ChemPal Documentation - v1.6.0
    Preparing search index...

    Function isMacklinProductDetailsResponse

    • Validates if data matches the Macklin product details response format. Product details response contains a list of product details.

      Parameters

      • data: unknown

        The data to validate

      Returns data is MacklinProductDetailsResponse

      True if the data matches the product details response format

      const response = await fetch("/api/product/list?code=B803083");
      const data = await response.json();
      if (isMacklinProductDetailsResponse(data.data)) {
      console.log("Products:", data.data.list.length);
      }
      export function isMacklinProductDetailsResponse(
      data: unknown,
      ): data is MacklinProductDetailsResponse {
      if (typeof data !== 'object' || data === null) return false;
      if (!('list' in data) || !Array.isArray(data.list)) return false;
      return data.list.every(isMacklinProductDetails);
      }