ChemPal Documentation - v1.6.0
    Preparing search index...
    • Type guard to validate if a value is a valid currency code. Checks if the value is a string and if it is a known currency code in the CURRENCY_CODE_MAP.

      Parameters

      • code: unknown

        The value to validate

      Returns code is valueof<{ [key: string]: string }>

      Type predicate indicating if the value is a valid currency code

      const validCode = "USD";
      if (isCurrencyCode(validCode)) {
      console.log("Valid currency code:", validCode);
      } else {
      console.log("Invalid currency code:", validCode);
      }
      export function isCurrencyCode(code: unknown): code is CurrencyCode {
      // CURRENCY_SYMBOL_MAP maps code -> symbol, so its keys are the valid codes (e.g. "USD").
      return typeof code === 'string' && code in CURRENCY_SYMBOL_MAP;
      }