npm.io
1.1.0 • Published 2d ago

@odata-filter/core

Licence
MIT
Version
1.1.0
Deps
0
Size
91 kB
Vulns
0
Weekly
394

OData Filter Core

Installation

See INSTALL.md for full instructions.

Usage

Package Installation
npm i @odata-filter/core --save
Basic Example
import { tokenize, parse } from '@odata-filter/core';

const tokens = tokenize("country/name eq 'US' and age gte 21");

parse(tokens);

/*{
  type: 'logical_operator',
  value: 'and',
  left: {
    type: 'comparison_operator',
    value: 'eq',
    left: { type: 'field', value: 'country/name' },
    right: { type: 'string_value', value: 'US' }
  },
  right: {
    type: 'comparison_operator',
    value: 'gte',
    left: { type: 'field', value: 'age' },
    right: { type: 'number_value', value: 21 }
  }
}*/
Traverse Results
import { tokenize, parse, iterate } from '@odata-filter/core';

const tokens = tokenize("country eq 'US' and age gte 21");
const ast = parse(tokens);

iterate(ast);

/*[
  {
    type: 'logical_operator',
    value: 'and',
    left: {
      type: 'comparison_operator',
      value: 'eq',
      left: [Object],
      right: [Object]
    },
    right: {
      type: 'comparison_operator',
      value: 'gte',
      left: [Object],
      right: [Object]
    }
  },
  {
    type: 'comparison_operator',
    value: 'eq',
    left: { type: 'field', value: 'country' },
    right: { type: 'string_value', value: 'US' }
  },
  { type: 'field', value: 'country' },
  { type: 'string_value', value: 'US' },
  {
    type: 'comparison_operator',
    value: 'gte',
    left: { type: 'field', value: 'age' },
    right: { type: 'number_value', value: 21 }
  },
  { type: 'field', value: 'age' },
  { type: 'number_value', value: 21 }
]*/

Contributing

See CONTRIBUTING.md for full instructions.

License

See LICENSE for licensing information.

Documentation

Keywords