UNPKG

smart-array-filter

Version:
53 lines 1.89 kB
import type { CustomMatcher } from './utils/customOperators.ts'; import type { Json } from './utils/types.ts'; interface OptionsTypeBase { /** * List of keywords used to filter the array. */ keywords?: string[] | string | null; /** * Maximum number of results. */ limit?: number; /** * Search mode for string comparisons. Case insensitive by default. */ caseSensitive?: boolean; /** * How results from different keywords are combined into the final result. */ predicate?: Predicate; /** * A list of jpath to ignore. `ignorePaths` has precedence over `includePaths`. */ ignorePaths?: Array<RegExp | string>; /** * A list of jpath to limit the search to. By default the entire data object is searched recursively. */ includePaths?: Array<RegExp | string>; /** * List of aliases to certain object paths. * The key is the alias and the value is the object path, which can be a regular expression. */ pathAlias?: Record<string, string | RegExp>; /** * List of custom matchers which converts search expressions into matchers. */ customMatchers?: CustomMatcher[]; } export type OptionsTypeWithIndex = OptionsTypeBase & { /** * Returns the indices in the array that match, instead of the elements themselves. */ index: true; }; export type OptionsTypeWithoutIndex = OptionsTypeBase & { index?: false; }; export type OptionsType = OptionsTypeWithIndex | OptionsTypeWithoutIndex; export type Predicate = 'AND' | 'OR'; export declare function filter(array: Json[], options?: OptionsTypeWithIndex): number[]; export declare function filter<T>(array: T[], options?: OptionsTypeWithoutIndex): T[]; export declare function filter<T>(array: T[], options?: OptionsType): T[] | number[]; export {}; //# sourceMappingURL=index.d.ts.map