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

    Function assertIsSynthetikaProductPrice

    • This can be used to verify the .price.gross and .price.net fields of a SynthetikaProduct

      Parameters

      • data: unknown

        The data to verify (raw response from Synthetika)

      Returns asserts data is SynthetikaProductPrice

      True if the data is a SynthetikaProductPrice, false otherwise

      const product = { price: { gross: { final: "100" }, net: { final: "90" } } };
      assertIsSynthetikaProductPrice(product.price.gross);
      assertIsSynthetikaProductPrice(product.price.net);
      console.log(product.price.gross.final);
      export function assertIsSynthetikaProductPrice(
      data: unknown,
      ): asserts data is SynthetikaProductPrice {
      if (!data || typeof data !== 'object') {
      console.log('isSynthetikaProductPrice: data is falsey or not an object');
      throw new Error('isSynthetikaProductPrice: data is falsey or not an object');
      }

      if (!isSynthetikaProductPrice(data)) {
      console.log('isSynthetikaProductPrice: data is missing base or final');
      throw new Error('isSynthetikaProductPrice: data is missing base or final');
      }
      }