Git Product home page Git Product logo

udaysingh236 / odata-query-parser Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 140 KB

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.

Home Page: https://www.npmjs.com/package/@slackbyte/odata-query-parser

License: MIT License

TypeScript 99.65% JavaScript 0.35%
odata odata-query-parser odata-server odatav4

odata-query-parser's Introduction

odata-query-parser

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.

How to build

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

How to use

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: ')'}
  ]
}

Support Features

  • $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
  • $select
  • $top
  • $skip
  • $orderby

CONTRIBUTING

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. โค๏ธ

odata-query-parser's People

Contributors

udaysingh236 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.