A highly versatile and fast OData Version 4.01 Parser which support almost all the available system query options like $filter, $orderby, $skip, $top, $count. The Open Data Protocol (OData) enables the creation of REST-based data services which allow resources, identified using Uniform Resource Locators (URLs) and defined in a data model. The Parser on high level works on lexer scanner strategy.
To run the parser in local, please clone the repository and follow the below steps:
npm install
npm run parser
To test and for test coverage:
npm test
npm run test:report
import { parseFilter, parseOrderby, parseSkip, parseTop } from '@slackbyte/odata-query-parser';
const filter = "Price gt 20 or Rating ge 10 not (Name eq 'uday singh' and City in ('Redmond', 'London'))"
console.log(parseFilter(filter));
Output:
{
token: [
{ tokenType: 'conditionMemberExp', subType: '', value: 'Price' },
{ tokenType: 'comOperatorExp', subType: 'greaterThanExp', value: '>'},
{ tokenType: 'conditionMemberExp', subType: '', value: '20' },
{ tokenType: 'logOperatorExp', subType: 'orExp', value: 'OR' },
{ tokenType: 'conditionMemberExp', subType: '', value: 'Rating' },
{ tokenType: 'comOperatorExp', subType: 'greaterThanEqualToExp', value: '>='},
{ tokenType: 'conditionMemberExp', subType: '', value: '10' },
{ tokenType: 'logOperatorExp', subType: 'notExp', value: 'NOT' },
{ tokenType: 'groupOperatorExp', subType: 'openBracExp', value: '('},
{ tokenType: 'conditionMemberExp', subType: '', value: 'Name' },
{ tokenType: 'comOperatorExp', subType: 'equalToExp', value: '=' },
{ tokenType: 'conditionMemberExp', subType: '', value: "'uday singh'"},
{ tokenType: 'logOperatorExp', subType: 'andExp', value: 'AND' },
{ tokenType: 'conditionMemberExp', subType: '', value: 'City' },
{ tokenType: 'comOperatorExp', subType: 'inExp', value: 'in' },
{ tokenType: 'conditionMemberExp', subType: '', value: "('Redmond', 'London')"},
{ tokenType: 'groupOperatorExp', subType: 'closeBracExp', value: ')'}
]
}
- $count
- $filter
- Comparison Operators
- eq
- ne
- lt
- le
- gt
- ge
- has
- in
- Logical Operators
- and
- or
- not
- Arithmetic Operators
- add
- sub
- mul
- div
- divby
- mod
- String Functions
- indexof
- contains
- endswith
- startswith
- length
- substring
- tolower
- toupper
- trim
- concat
- Date Functions
- year
- month
- day
- hour
- minute
- second
- fractionalseconds
- date
- time
- totaloffsetminutes
- now
- mindatetime
- maxdatetime
- Math Functions
- round
- floor
- ceiling
- Type and conditional Functions
- cast
- isof
- case
- Comparison Operators
- $select
- $top
- $skip
- $orderby
I love your inputs! and I want to make your contribution to this project easy and transparent, whether it's:
- Reporting a bug
- Discussing the current state of the code
- Submitting a fix
- Proposing new features
Please raise a pull request. 😊
Made with love in INDIA. ❤️