CmpStr - v3.2.1
    Preparing search index...

    Class Filter

    The Filter class provides a way to manage and apply filters to strings based on hooks.

    Index

    Constructors

    Properties

    filters: Map<FilterHooks, Map<string, FilterEntry>> = ...

    A static map to hold all filters. The key is the hook name, and the value is an Map of FilterEntry objects.

    pipeline: Map<FilterHooks, FilterFn> = ...

    A map that holds the pipeline of filters to be applied. The key is the hook name, and the value is the compiled function.

    Methods

    • Adds a filter to the specified hook.

      Parameters

      • hook: FilterHooks

        The name of the hook

      • id: string

        The id of the filter

      • fn: FilterFn

        The filter function

      • Optionalopt: FilterOptions = {}

        Additional options for the filter

      Returns boolean

      • Returns true if the filter was added, false if it was not added due to override restrictions
    • Applies all active filters for a given hook to the input string(s).

      Parameters

      • hook: FilterHooks

        The name of the hook

      • input: string | string[]

        The input string(s) to be filtered

      Returns string | string[]

      • The filtered string(s)
    • Applies all active filters for a given hook to the input string(s) asynchronously. Each filter function may return a Promise or a plain string; all are awaited in order.

      Parameters

      • hook: FilterHooks

        The name of the hook

      • input: string | string[]

        The input string(s) to be filtered

      Returns Promise<string | string[]>

      • The filtered string(s)
    • Clears all filters or filters for a specific hook. If no hook is provided, clear all filters

      Parameters

      • Optionalhook: FilterHooks

        Optional name of the hook to clear filters for

      Returns void

    • Clears the entire filter pipeline cache. This forces recompilation of all pipelines on next application.

      Returns void

    • Retrieves the compiled filter function for a given hook. If the function is not cached, it compiles it from the active filters.

      Parameters

      Returns FilterFn

      • The compiled filter function for the hook
    • Checks if a filter exists for a given hook and id.

      Parameters

      • hook: FilterHooks

        The name of the hook

      • id: string

        The id of the filter

      Returns boolean

      • Returns true if the filter exists, false otherwise
    • Lists all filters for a given hook.

      Parameters

      • hook: FilterHooks

        The name of the hook

      • active: boolean = false

        If true, only list active filters

      Returns string[]

      • An array of filter ids
    • Pauses a filter by its hook and id.

      Parameters

      • hook: FilterHooks

        The name of the hook

      • id: string

        The id of the filter

      Returns boolean

      • Returns true if the filter was paused, false if it was not found
    • Removes a filter by its hook and id.

      Parameters

      • hook: FilterHooks

        The name of the hook

      • id: string

        The id of the filter

      Returns boolean

      • Returns true if the filter was removed, false if it was not found
    • Resumes a filter by its hook and id.

      Parameters

      • hook: FilterHooks

        The name of the hook

      • id: string

        The id of the filter

      Returns boolean

      • Returns true if the filter was resumed, false if it was not found