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

    Module utils/typeGuards/common

    Functions - Typeguards

    isHttpResponse

    Type guard to validate if a value is a valid HTTP Response object. Checks for the presence of essential Response properties and methods.

    isUOM

    Type guard to validate if a value is a valid UOM. Checks if the value is a string and if it is in the UOM array.

    isJsonResponse

    Type guard to validate if a Response object contains JSON content. Checks both the Content-Type header and ensures it's a valid Response object.

    assertJsonResponse

    Type guard to validate if a Response object contains JSON content. Checks both the Content-Type header and ensures it's a valid Response object.

    isHtmlResponse

    Type guard to validate if a Response object contains HTML content. Checks both the Content-Type header and ensures it's a valid Response object.

    assertHtmlResponse

    Asserts that a Response object contains HTML content. Throws a TypeError if the response is not a valid HTML response.

    isValidResult

    Type guard to validate if a value has the minimal required properties of a search result. Checks for the presence and correct types of all required fields for a search result.

    checkMissingMinimalProductFields

    Checks a product object for missing or incorrectly typed minimal required fields. Returns an array of field names that are missing or have the wrong type.

    isMinimalProduct

    Type guard to validate if a value has the minimal required properties of a Product. This is a less strict validation than isProduct as it only checks for the minimum required fields. Useful for validating partial product data during construction.

    checkCompleteProductFields

    Checks a product object for missing or incorrectly typed complete required fields. Returns an array of field names that are missing or have the wrong type.

    assertCompleteProductFields

    Asserts that a product object contains all required fields with correct types. Throws a TypeError listing any missing or invalid fields.

    isProduct

    Type guard to validate if a value is a complete Product object. Checks for the presence and correct types of all required product fields. This is a stricter validation than isMinimalProduct as it ensures all required fields are present.

    isCurrencySymbol

    Type guard to validate if a value is a valid currency symbol. Checks if the value is a string and if it is in the CURRENCY_SYMBOL_MAP.

    isCurrencyCode

    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.

    isCountryCode

    Type guard to validate if a value is a known ISO 3166-1 alpha-2 country code. Checks the value against country-list-js so any real country code is accepted.

    isShippingRange

    Type guard to validate if a value is a valid shipping range.

    isPaymentMethod

    Type guard to validate if a value is a valid payment method.

    isPopulatedObject

    Checks if an object is empty.

    isPopulatedArray

    Checks if an array is populated.

    isParsedPrice

    Type guard to validate if a value is a valid ParsedPrice object. Checks for the presence and correct types of currencyCode, currencySymbol, and price.

    isQuantityObject

    Type guard to validate if a value is a valid QuantityObject. Checks for the presence and correct types of quantity (number) and uom (string).

    isCAS

    Type guard to validate a CAS (Chemical Abstracts Service) number. CAS numbers follow a specific format (XXXXXXX-XX-X) and include a checksum digit.

    isFullURL

    Type guard to validate if a value is a full URL. Attempts to construct a URL object from the value.

    isRequest

    Type guard to validate if a value is a Request instance.

    isSpinSpeed

    Type guard to check if a string is a valid SPIN_SPEED key.

    isButtonElement

    Type guard to check if an EventTarget is an HTMLButtonElement.

    isAnchorElement

    Type guard to check if an EventTarget is an HTMLAnchorElement.

    isInputElement

    Type guard to check if an EventTarget is an HTMLInputElement.

    isValidUserSettings

    Type guard to validate if a value is a valid UserSettings object. Checks for the presence and correct types of all UserSettings properties.

    isPlainContainer

    Check if a value is a plain object or array.

    isSmiles

    Type guard to validate if a value is a valid SMILES string. Checks if the value is a string and if it is a valid SMILES string.

    isIupacName

    Type guard to validate if a value is a usable IUPAC name (a non-empty string).

    isPubChemCID

    Type guard to validate if a value is a PubChem Compound ID (a positive integer). Numeric strings are accepted and coerced before validation.

    toPubChemCID

    Normalizes a value already validated by isPubChemCID into the branded PubChemCID number, coercing a numeric string to its number form. The assertion is unavoidable and lives here as the single sanctioned construction point: a nominal brand can't be minted from Number() without one.

    isInChIKey

    Type guard to validate if a value is an InChIKey. An InChIKey is three hyphen-separated uppercase-letter blocks of 14, 10, and 1 characters.

    isInChI

    Type guard to validate if a value is an InChI string. Accepts values with or without the leading InChI= prefix (the version layer 1S/... or 1/... must follow).