@chronicstone/array-query
- Version 1.0.5
- Published
- 40.8 kB
- No dependencies
- MIT license
Install
npm i @chronicstone/array-queryyarn add @chronicstone/array-querypnpm add @chronicstone/array-queryOverview
A simple and lightweight array query library
Index
Functions
Interfaces
Type Aliases
Functions
function query
query: < T extends GenericObject, P extends QueryParams< T, NestedPaths<T>, NestedPathsForType<T, string | number | boolean> >>( data: T[], params: P) => QueryResult<T, P>;Interfaces
interface ComparatorParams
interface ComparatorParams {}property dateMode
dateMode?: boolean;interface MatchModeProcessorMap
interface MatchModeProcessorMap {}property arrayLength
arrayLength: (f: { value: any; filter: any }) => boolean;property between
between: (f: { value: any; filter: any; params?: ComparatorParams }) => boolean;property contains
contains: (f: { value: any; filter: any }) => boolean;property equals
equals: (f: { value: any; filter: any }) => boolean;property exists
exists: (f: { value: any; filter: any }) => boolean;property greaterThan
greaterThan: (f: { value: any; filter: any; params?: ComparatorParams;}) => boolean;property greaterThanOrEqual
greaterThanOrEqual: (f: { value: any; filter: any; params?: ComparatorParams;}) => boolean;property lessThan
lessThan: (f: { value: any; filter: any; params?: ComparatorParams }) => boolean;property lessThanOrEqual
lessThanOrEqual: (f: { value: any; filter: any; params?: ComparatorParams;}) => boolean;property notEquals
notEquals: (f: { value: any; filter: any }) => boolean;property objectMatch
objectMatch: (f: { value: any; filter: any; params: ObjectMapFilterParams; index?: number;}) => boolean;property regex
regex: (f: { value: any; filter: any; params?: RegexParams }) => boolean;interface ObjectMapFilterParams
interface ObjectMapFilterParams {}property applyAtRoot
applyAtRoot?: boolean;property matchPropertyAtIndex
matchPropertyAtIndex?: boolean;property operator
operator: 'AND' | 'OR';property properties
properties: Array<{ key: string; matchMode: Exclude<FilterMatchMode, 'objectMap'>;}>;property transformFilterValue
transformFilterValue?: (value: any) => any;interface QueryFilterGroup
interface QueryFilterGroup<Paths extends string = string> {}interface QueryParams
interface QueryParams< T extends GenericObject = GenericObject, Paths extends NestedPaths<T> = NestedPaths<T>, PrimitivePath extends string = NestedPathsForType< T, string | number | null | boolean | undefined >> {}interface RegexParams
interface RegexParams {}property flags
flags?: string;interface SearchOptions
interface SearchOptions<Paths extends string = string> {}property caseSensitive
caseSensitive?: boolean;property keys
keys: | Paths[] | Array<{ key: Paths; caseSensitive?: boolean; }>;property value
value: string;interface SortOption
interface SortOption<Paths extends string = string> {}Type Aliases
type ComparatorMatchMode
type ComparatorMatchMode = Extract< FilterMatchMode, 'between' | 'greaterThan' | 'greaterThanOrEqual' | 'lessThan' | 'lessThanOrEqual'>;type FilterMatchMode
type FilterMatchMode = | 'contains' | 'between' | 'equals' | 'notEquals' | 'greaterThan' | 'greaterThanOrEqual' | 'lessThan' | 'lessThanOrEqual' | 'exists' | 'regex' | 'arrayLength' | 'objectMatch';type FilterOptions
type FilterOptions<Paths extends string = string> = | Array<QueryFilterGroup<Paths>> | Array<QueryFilter<Paths>> | { groups: Array<QueryFilterGroup<Paths>>; operator: Operator; };type GenericObject
type GenericObject = Record<Primitive, unknown>;type MatchModeCore
type MatchModeCore = | { matchMode: Exclude< FilterMatchMode, RegexMatchMode | 'objectMatch' | ComparatorMatchMode >; } | { matchMode: ComparatorMatchMode; params?: ComparatorParams; } | { matchMode: 'regex'; params?: RegexParams; } | { matchMode: 'objectMatch'; params: ObjectMapFilterParams | ((value: any) => ObjectMapFilterParams); };type NestedPaths
type NestedPaths<T> = T extends Array<infer U> ? `${NestedPaths<U>}` : T extends object ? { [K in keyof T & (string | number)]: K extends string ? `${K}` | `${K}.${NestedPaths<T[K]>}` : never; }[keyof T & (string | number)] : never;type NestedPathsForType
type NestedPathsForType<T, P> = T extends Array<infer U> ? NestedPathsForType<U, P> : T extends object ? { [K in keyof T & (string | number)]: K extends string ? T[K] extends P ? `${K}` | `${K}.${NestedPathsForType<T[K], P>}` : T[K] extends object ? `${K}.${NestedPathsForType<T[K], P>}` : string : string; }[keyof T & (string | number)] : string;type NonObjectMatchMode
type NonObjectMatchMode = Exclude<FilterMatchMode, 'objectMatch'>;type Operator
type Operator = 'AND' | 'OR' | (() => 'AND' | 'OR');type Primitive
type Primitive = string | number | symbol;type QueryFilter
type QueryFilter<Paths extends string = string> = { key: Paths; value: any; operator?: Operator; condition?: () => boolean;} & MatchModeCore;type QueryResult
type QueryResult<T extends GenericObject, P extends QueryParams<T>> = P extends { limit: number;} ? { totalRows: number; totalPages: number; rows: T[]; unpaginatedRows: T[]; } : T[];type RegexMatchMode
type RegexMatchMode = Extract<FilterMatchMode, 'regex'>;Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (22)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@chronicstone/array-query.
- Markdown[](https://www.jsdocs.io/package/@chronicstone/array-query)
- HTML<a href="https://www.jsdocs.io/package/@chronicstone/array-query"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3836 ms. - Missing or incorrect documentation? Open an issue for this package.
