ChemPal Documentation - v1.6.0
    Preparing search index...
    • Type guard to validate if a value is a valid product image entry. Checks for a string href and a type of either "image" or "thumbnail". The href is only shape-checked here; the builder resolves it to an absolute URL (and drops the entry when it can't).

      Parameters

      • value: unknown

        The value to check

      Returns value is ProductImage

      Type predicate indicating if the value is a valid ProductImage

      // Valid image entry
      if (isProductImage({ href: "https://example.com/a.jpg", type: "image" })) {
      console.log('Valid product image');
      }

      // Invalid — unknown type
      if (!isProductImage({ href: "https://example.com/a.jpg", type: "banner" })) {
      console.log('Not a valid product image');
      }

      // Invalid — missing href
      if (!isProductImage({ type: "thumbnail" })) {
      console.log('Not a valid product image');
      }
      export function isProductImage(value: unknown): value is ProductImage {
      return v.safeParse(productImageSchema, value).success;
      }