Parse text query language to object filter
npm install @wholebuzz/queryRegex extended filtrex object query language.
``
import { parseFilterQuery } from '@wholebuzz/query/lib/query'
interface Record {
title: string
count: number
}
const records: Record[] = [
{ title: 'Blues guitar volume 1', count: 35 },
{ title: 'Rock guitar volume 3', count: 46 },
{ title: 'Blues harmonica volume 1', count: 10 },
]
const parseRecordQuery = (q: string) =>
parseFilterQuery
// [
// { title: 'Blues guitar volume 1', count: 35 },
// { title: 'Blues harmonica volume 1', count: 10 }
// ]
console.log(records.filter(parseRecordQuery('blues')))
//[ { title: 'Blues guitar volume 1', count: 35 } ]
console.log(records.filter(parseRecordQuery('blues count>10')))
// [
// { title: 'Blues guitar volume 1', count: 35 },
// { title: 'Rock guitar volume 3', count: 46 }
// ]
console.log(records.filter(parseRecordQuery('count>=35')))
// [ { title: 'Rock guitar volume 3', count: 46 } ]
console.log(records.filter(parseRecordQuery('rock')))
`
- split
• Const split: any
Defined in: query.ts:3
▸ parseFilterQuery: string, objectFields: SetdefaultFields?: string[], extraFunctions?: { [T: string]: Function; }, customProps?: { [T: string]: (x: X) => any; }, options?: ParseFilterQueryOptions): function
Creates regex-expanded Filtrex object-filter described by query.
optional defaultFields The default fields to text search for non-property-query-terms.
optional extraFunctions Map of extra functions to make available to query, e.g. startsWith(docs/).
optional customProps Custom properties to make available to query, e.g. .authors.
optional options Extra query options.
#### Type parameters
| Name |
| :------ |
| X |
#### Parameters
| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| query | string | - | The query describing the filter. |objectFields
| | SetdefaultFields
| | string[] | [] | - |extraFunctions
| | object | {} | - |customProps
| | object | {} | - |options?
| | ParseFilterQueryOptions | - | - |
Returns: (docs/x`: X) => boolean
Defined in: query.ts:21