CmpStr - v3.2.1
    Preparing search index...

    Class CmpStrAsync<R>

    The CmpStrAsync class provides a fully asynchronous API for string comparison, phonetic indexing, filtering and normalization.

    Type Parameters

    • R = MetricRaw

      The type of the metric result, defaults to MetricRaw

    Hierarchy (View Summary)

    Index

    Constructors

    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

    • Asynchronously performs a batch metric comparison and returns results sorted by score.

      Type Parameters

      Parameters

      • a: MetricInput

        The source string or array of strings

      • b: MetricInput

        The target string or array of strings

      • Optionaldir: "desc" | "asc" = 'desc'

        Sort direction (desc, asc)

      • Optionalopt: CmpStrOptions

        Optional options

      Returns Promise<T>

      • The sorted batch results
    • 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)
    • Asynchronously performs a single metric comparison returning the numeric score.

      Parameters

      • a: string

        The source string

      • b: string

        The target string

      • Optionalopt: CmpStrOptions

        Optional options

      Returns Promise<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
    • Computes a similarity matrix for the given input array.

      Parameters

      • input: string[]

        The input array

      • Optionalopt: CmpStrOptions

        Optional options

      Returns number[][]

      • The similarity matrix
    • Asynchronously computes a similarity matrix for the given input array.

      Parameters

      • input: string[]

        The input array

      • Optionalopt: CmpStrOptions

        Optional options

      Returns Promise<number[][]>

      • The similarity matrix
    • Asynchronously 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 Promise<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
    • Asynchronously 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 Promise<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
    • Asynchronously 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 Promise<string>

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

      Returns this

    • Removes an option at the given path.

      Parameters

      • path: string

        The path to the option

      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
    • Asynchronously 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 Promise<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
    • Asynchronously 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 Promise<StructuredResultLike<T, R>>

      • Async closest matches
    • 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
    • Asynchronously 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 Promise<StructuredResultLike<T, R>>

      • Async furthest matches
    • 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
    • Asynchronously 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 Promise<StructuredResultLike<T, R>>

      • Async 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
    • Asynchronously 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 Promise<StructuredResultLike<T, R>>

      • Async filtered batch results
    • 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
    • Asynchronously 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 Promise<StructuredResultLike<T, R>>

      • Async 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
    • Asynchronously performs a single metric comparison.

      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 Promise<T>

      • The metric result
    • 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