CmpStr - v3.2.1
    Preparing search index...

    Class CmpStr<R>

    The main CmpStr class that provides a unified interface for string comparison, phonetic indexing, filtering, and text analysis.

    Type Parameters

    • R = MetricRaw

      The type of the metric result, defaults to MetricRaw

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a new CmpStr instance with the given options. The constructor is protected to enforce the use of the static create method.

      Type Parameters

      • R = MetricRaw

        The type of the metric result, defaults to MetricRaw

      Parameters

      • Optionalopt: string | CmpStrOptions

        Optional serialized or options object

      Returns CmpStr<R>

    Properties

    options: CmpStrOptions = ...
    clearCache: {
        filter: () => void;
        metric: () => void;
        normalizer: () => void;
        phonetic: () => void;
    } = ...

    Clears the caches for normalizer, filter pipelines, metric, and phonetic modules.

    Type Declaration

    • filter: () => void
    • metric: () => void
    • normalizer: () => void
    • phonetic: () => void
    filter: {
        add: (
            hook: FilterHooks,
            id: string,
            fn: FilterFn,
            opt?: FilterOptions,
        ) => boolean;
        clear: (hook?: FilterHooks) => void;
        has: (hook: FilterHooks, id: string) => boolean;
        list: (hook: FilterHooks, active?: boolean) => string[];
        pause: (hook: FilterHooks, id: string) => boolean;
        remove: (hook: FilterHooks, id: string) => boolean;
        resume: (hook: FilterHooks, id: string) => boolean;
    } = ...

    Adds, removes, pauses, resumes, lists, or clears global filters.

    Type Declaration

    Filter

    metric: {
        add: (
            name: string,
            cls: RegistryConstructor<Metric<MetricRaw>>,
            update?: boolean,
        ) => void;
        has: (name: string) => boolean;
        list: () => string[];
        remove: (name: string) => void;
    } = ...

    Adds, removes, checks, or lists available metrics.

    MetricRegistry

    phonetic: {
        add: (
            name: string,
            cls: RegistryConstructor<Phonetic>,
            update?: boolean,
        ) => void;
        has: (name: string) => boolean;
        list: () => string[];
        map: {
            add: (
                algo: string,
                id: string,
                map: PhoneticMap,
                update?: boolean,
            ) => void;
            has: (algo: string, id: string) => boolean;
            list: (algo: string) => string[];
            remove: (algo: string, id: string) => void;
        };
        remove: (name: string) => void;
    } = ...

    Adds, removes, checks, or lists available phonetic algorithms and mappings.

    PhoneticRegistry

    profiler: ProfilerService<any> = profiler.services

    Provides access to the global profiler services.

    Profiler

    Methods

    • Assert a condition and throws if the condition is not met.

      Parameters

      • cond: string

        The condition to met

      • Optionaltest: any

        Value to test for

      Returns void

      If the condition is not met

    • Assert multiple conditions.

      Parameters

      • ...cond: [string, any?][]

        Array of [ condition, value ] pairs

      Returns void

    • Performs a single metric comparison and returns only the numeric score.

      Parameters

      • a: string

        The source string

      • b: string

        The target string

      • Optionalopt: CmpStrOptions

        Optional options

      Returns number

      • The similarity score (0..1)
    • Returns a specific option value by path.

      Parameters

      • path: string

        The path to the option

      Returns any

      • The option value
    • Returns the options as a JSON string.

      Returns string

      • The serialized options
    • Computes a similarity matrix for the given input array.

      Parameters

      • input: string[]

        The input array

      • Optionalopt: CmpStrOptions

        Optional options

      Returns number[][]

      • The similarity matrix
    • Normalizes the input string or array using the configured or provided flags.

      Parameters

      • input: MetricInput

        The input string or array

      • Optionalflags: string

        Normalization flags

      Returns MetricInput

      • The normalized input
    • Performs a pairwise metric comparison between source and target strings or array of strings.

      Input arrays needs of the same length to perform pairwise comparison, otherwise the method will throw an error.

      Type Parameters

      Parameters

      Returns T

      • The pairwise metric results
    • Computes the phonetic index for a string using the configured or given algorithm.

      Parameters

      • Optionalinput: string

        The input string

      • Optionalalgo: string

        The phonetic algorithm to use

      • Optionalopt: PhoneticOptions

        Optional phonetic options

      Returns string

      • The phonetic index as a string
    • Resets the instance, clearing all data and options.

      Returns this

    • Removes the normalization flags entirely.

      Returns this

    • Removes an option at the given path.

      Parameters

      • path: string

        The path to the option

      Returns this

    • Removes the processors entirely.

      Returns this

    • Performs a normalized and filtered substring search.

      Parameters

      • needle: string

        The search string

      • haystack: string[]

        The array to search in

      • Optionalflags: string

        Normalization flags

      • Optionalprocessors: CmpStrProcessors

        Pre-processors to apply

      Returns string[]

      • Array of matching entries
    • Sets the normalization flags (e.g., 'itw', 'nfc').

      Parameters

      • flags: string

        The normalization flags

      Returns this

    • Sets the similatity metric to use (e.g., 'levenshtein', 'dice').

      Parameters

      • name: string

        The metric name

      Returns this

    • Sets a specific option at the given path.

      Parameters

      • path: string

        The path to the option

      • value: any

        The value to set

      Returns this

    • Enable or disable raw output.

      Parameters

      • enable: boolean

        Whether to enable or disable raw output

      Returns this

    • Sets the serialized options from a JSON string.

      Parameters

      • opt: string

        The serialized options

      Returns this

    • Creates a instance for processing structured data.

      Type Parameters

      • T = any

        The type of objects in the data array

      Parameters

      • data: T[]

        The array of structured objects

      • key: keyof T

        The property key to compare

      Returns StructuredData<T, R>

      • The lookup instance
    • Returns the n closest matches from a batch comparison of structured data.

      Type Parameters

      • T = any

        The type of objects in the data array

      Parameters

      • query: string

        The query string to compare against

      • data: T[]

        The array of structured objects

      • key: keyof T

        The property key to extract for comparison

      • Optionaln: number = 1

        Number of closest matches

      • Optionalopt: StructuredDataOptions

        Optional lookup options

      Returns StructuredResultLike<T, R>

      • Closest matches with objects
    • Returns the n furthest matches from a batch comparison of structured data.

      Type Parameters

      • T = any

        The type of objects in the data array

      Parameters

      • query: string

        The query string to compare against

      • data: T[]

        The array of structured objects

      • key: keyof T

        The property key to extract for comparison

      • Optionaln: number = 1

        Number of furthest matches

      • Optionalopt: StructuredDataOptions

        Optional lookup options

      Returns StructuredResultLike<T, R>

      • Furthest matches with objects
    • Performs a batch comparison against structured data by extracting a specific property and returning results with original objects attached.

      Type Parameters

      • T = any

        The type of objects in the data array

      Parameters

      • query: string

        The query string to compare against

      • data: T[]

        The array of structured objects

      • key: keyof T

        The property key to extract for comparison

      • Optionalopt: StructuredDataOptions

        Optional lookup options

      Returns StructuredResultLike<T, R>

      • Batch results with original objects
    • Performs a batch comparison and returns only results above the threshold for structured data.

      Type Parameters

      • T = any

        The type of objects in the data array

      Parameters

      • query: string

        The query string to compare against

      • data: T[]

        The array of structured objects

      • key: keyof T

        The property key to extract for comparison

      • threshold: number

        The similarity threshold (0..1)

      • Optionalopt: StructuredDataOptions

        Optional lookup options

      Returns StructuredResultLike<T, R>

      • Filtered batch results with objects
    • Performs a pairwise comparison between two arrays of structured objects by extracting specific properties and returning results with original objects attached.

      Type Parameters

      • T = any

        The type of objects in the arrays

      • O = any

        The type of objects in the other array

      Parameters

      • data: T[]

        The array of structured objects

      • key: keyof T

        The property key to extract for comparison

      • other: O[]

        The other array of structured objects

      • otherKey: keyof O

        The property key to extract from other array

      • Optionalopt: StructuredDataOptions

        Optional lookup options

      Returns StructuredResultLike<T, R>

      • Pairwise results with original objects
    • Performs a single metric comparison between the source and target.

      Type Parameters

      • T extends ResultLike<R> = any

        The type of the metric result

      Parameters

      • a: string

        The source string

      • b: string

        The target string

      • Optionalopt: CmpStrOptions

        Optional options

      Returns T

      • The metric result
    • Returns a TextAnalyzer instance for the given input string.

      Parameters

      • Optionalinput: string

        The input string

      Returns TextAnalyzer

      • The text analyzer
    • Returns a DiffChecker instance for computing the unified diff between two texts.

      Parameters

      • a: string

        The first (original) text

      • b: string

        The second (modified) text

      • Optionalopt: DiffOptions

        Optional diff configuration

      Returns DiffChecker

      • The diff checker instance