CmpStr - v3.3.0
    Preparing search index...

    Utility for validating CmpStr options.

    This class provides static methods to validate various aspects of the options object passed to CmpStr.

    Index

    Constructors

    Properties

    ALLOWED_FLAGS: Set<string> = ...

    Allowed normalization flags

    ALLOWED_MODES: Set<string> = ...

    Allowed comparison modes

    ALLOWED_OUTPUT: Set<string> = ...

    Allowed output modes

    ALLOWED_SORT: Set<string> = ...

    Allowed sort modes

    CMPSTR_OPT_MAP: {
        flags: (v: unknown) => void;
        metric: (v: unknown) => void;
        objectsOnly: (v: unknown) => void;
        opt: (v: any) => void;
        output: (v: unknown) => void;
        processors: (v: any) => void;
        raw: (v: unknown) => void;
        removeZero: (v: unknown) => void;
        safeEmpty: (v: unknown) => void;
        sort: (v: unknown) => void;
    } = ...

    CmpStr options validation dispatch table

    METRIC_OPT_MAP: {
        delimiter: (v: unknown) => void;
        gap: (v: unknown) => void;
        match: (v: unknown) => void;
        mismatch: (v: unknown) => void;
        mode: (v: unknown) => void;
        pad: (v: unknown) => void;
        q: (v: unknown) => void;
    } = ...

    Metric options validation dispatch table

    PHONETIC_OPT_MAP: {
        dedupe: (v: unknown) => void;
        delimiter: (v: unknown) => void;
        fallback: (v: unknown) => void;
        length: (v: unknown) => void;
        map: (v: unknown) => void;
        pad: (v: unknown) => void;
    } = ...

    Phonetic algorithm options validation dispatch table

    PROCESSORS: {
        phonetic: (
            opt: { algo: string; opt?: PhoneticOptions } | undefined,
        ) => void;
    } = ...

    Processor dispatch table

    Methods

    • Internal helper to convert a Set to a string for error messages.

      Parameters

      • set: Set<string>

        The set to convert

      Returns string

      • A string representation of the set
    • Validate boolean-like values.

      Parameters

      • value: unknown

        The value to validate

      • name: string

        The name of the option (for error messages)

      Returns void

      • If the value is not a boolean
    • Internal helper to validate enum-like values.

      Parameters

      • value: unknown

        The value to validate.

      • name: string

        The name of the option (for error messages).

      • set: Set<string>

        The set of allowed values.

      Returns void

      If the value is not a string or is not in the allowed set.

    • Validate normalization flags.

      Parameters

      • value: unknown

        The flags to validate

      Returns void

      • If the flags are not a string or contain invalid characters
    • Internal helper to validate objects against a dispatch table of validation functions.

      Type Parameters

      Parameters

      • opt: unknown

        The object to validate.

      • map: T

        A dispatch table mapping keys to validation functions.

      Returns void

      If any property in the object fails validation.

    • Validate metric name against the MetricRegistry.

      Parameters

      • value: unknown

        The metric name to validate

      Returns void

      • If the metric is not a string or not registered
    • Validate CmpStr comparison mode.

      Parameters

      • value: unknown

        The comparison mode to validate

      Returns void

      • If the comparison mode is not a string or not allowed
    • Validate number-like values.

      Parameters

      • value: unknown

        The value to validate

      • name: string

        The name of the option (for error messages)

      Returns void

      • If the value is not a number or is NaN
    • Validate the provided CmpStr options object.

      This method performs a comprehensive validation of the options object passed to CmpStr. It checks for the presence and validity of all supported options, including primitive types, enum-like values, registry-based names, and nested processor options.

      If any validation check fails, a CmpStrValidationError is thrown with a descriptive message and relevant details about the invalid option.

      Parameters

      Returns void

      • If any validation check fails
    • Validate CmpStr output mode.

      Parameters

      • value: unknown

        The output mode to validate

      Returns void

      • If the output mode is not a string or not allowed
    • Validate phonetic algorithm name against the PhoneticRegistry.

      Parameters

      • value: unknown

        The phonetic algorithm name to validate

      Returns void

      • If the phonetic algorithm is not a string or not registered
    • Validate processor options.

      This method iterates over the keys in the provided processor options and dispatches validation to the corresponding function in the PROCESSORS table.

      If an invalid processor type is found, a CmpStrValidationError is thrown indicating the invalid type and the expected processor types.

      Parameters

      Returns void

      • If any processor type is invalid
    • Internal helper to validate registry-based options (metrics and phonetic algorithms).

      Parameters

      • value: unknown

        The value to validate.

      • name: string

        The name of the option (for error messages).

      • label: string

        The label to use in error messages (e.g. "Metric" or "Phonetic algorithm").

      • has: (v: string) => boolean

        A function that checks if the registry contains a given name.

      • list: () => string[]

        A function that returns a list of registered names for error messages.

      Returns void

      If the value is not a non-empty string or is not registered.

    • Validate CmpStr structured data sort mode.

      Parameters

      • value: unknown

        The sort mode to validate

      • name: string

        The name of the option (for error messages)

      Returns void

      • If the sort mode is neither 'asc', 'desc', nor a boolean
    • Validate string-like values.

      Parameters

      • value: unknown

        The value to validate

      • name: string

        The name of the option (for error messages)

      Returns void

      • If the value is not a string
    • Internal helper to validate primitive types.

      Parameters

      • value: unknown

        The value to validate.

      • name: string

        The name of the option (for error messages).

      • type: "string" | "number" | "boolean"

        The expected type of the value.

      Returns void

      If the value is not of the expected type or is NaN (for numbers).