ChemPare Documentation - v0.0.0
    Preparing search index...
    • Type guard to validate if an object matches the SearchResultItem structure. Checks for the presence and correct types of required properties in Onyxmet search results. Required properties:

      • label: Product name/title
      • image: Product image URL or identifier
      • description: Product description text
      • href: Product URL or path

      Parameters

      • product: unknown

        The object to validate

      Returns product is OnyxMetSearchResultItem

      Type predicate indicating if the object is a valid SearchResultItem

      // Valid search result item
      const validItem = {
      label: "Sodium Chloride",
      image: "nacl.jpg",
      description: "High purity NaCl",
      href: "/products/nacl"
      };
      if (isSearchResultItem(validItem)) {
      console.log("Valid item:", validItem.label);
      }

      // Invalid search result item (missing properties)
      const invalidItem = {
      label: "Sodium Chloride",
      image: "nacl.jpg"
      // Missing description and href
      };
      if (!isSearchResultItem(invalidItem)) {
      console.log("Invalid item - missing required properties");
      }

      // Invalid search result item (wrong type)
      const wrongType = "not an object";
      if (!isSearchResultItem(wrongType)) {
      console.log("Invalid item - not an object");
      }