ChemPal Documentation - v1.6.0
    Preparing search index...
    • Type guard to validate if a value is a valid availability status. Checks if the value is a string that matches one of the predefined AVAILABILITY enum values. Matching is case-insensitive — input is lowercased before comparison.

      Parameters

      • availability: unknown

        The value to check

      Returns availability is Availability

      Type predicate indicating if the value is a valid AVAILABILITY enum value

      // Valid availability values
      if (isAvailability('IN_STOCK')) {
      console.log('Product is in stock');
      }
      if (isAvailability('OUT_OF_STOCK')) {
      console.log('Product is out of stock');
      }

      // Invalid availability values
      if (!isAvailability('available')) {
      console.log('Invalid availability status');
      }
      if (!isAvailability(123)) {
      console.log('Availability must be a string');
      }
      export function isAvailability(availability: unknown): availability is Availability {
      return v.safeParse(availabilitySchema, availability).success;
      }