ChemPal Documentation - v0.0.13-beta.5
    Preparing search index...

    Function isAmbeedProductListResponse

    • Type guard to validate if a response matches the Ambeed product list API response structure. Checks for the presence and correct types of source, code, lang, value, and time fields.

      Parameters

      • data: unknown

        The response data to validate

      Returns data is AmbeedProductListResponse

      Type predicate indicating if the data is a valid AmbeedProductListResponse

      const response = await fetch("https://www.ambeed.com/api/search");
      const data = await response.json();
      if (isAmbeedProductListResponse(data)) {
      console.log("Valid response, language:", data.lang);
      console.log("Response code:", data.code);
      }
      export function isAmbeedProductListResponse(data: unknown): data is AmbeedProductListResponse {
      return ambeedProductListResponseSchema.safeParse(data).success;
      }