9.0.0 • Published 6 years ago

@lanetix/odata-parser v9.0.0

Weekly downloads
210
License
MIT
Repository
github
Last release
6 years ago

OData query string parser for node.js based on pegjs.

Build Status

Installation

npm install odata-parser

Usage: parse()

var parser = require("odata-parser");

var ast = parser.parse("$top=10&$skip=5&$select=foo")

util.inspect(ast)

will result in:

{
  '$top': 10,
  '$skip': 5,
  '$select': [ 'foo' ]
}

Filters like:

parser.parse("$filter=Name eq 'John' and LastName lt 'Doe'")

results in:

{
    $filter: {
        type: 'and',
        left: {
            type: 'eq',
            left: {
                type: 'property',
                name: 'Name'
            },
            right: {
                type: 'literal',
                value: 'John'
            }
        },
        right: {
            type: 'lt',
            left: {
                type: 'property',
                name: 'LastName'
            },
            right: {
                type: 'literal',
                value: 'Doe'
            }
        }
    }
}

Using functions in filters

parser.parse("$filter=substringof('nginx', Servers)")

results in:

{
    $filter: {
        type: 'functioncall',
        func: 'substringof',
        args: [{
            type: 'literal',
            value: 'nginx'
        }, {
            type: 'property',
            name: 'Servers'
        }]
    }
}

Usage: stringify()

var mod = require("odata-parser");

var uri = `$filter=( nullable_string ne null and telephone_number eq 999999999 )&$select=name`

var originalAst = mod.parse(uri)
var remadeOdata = mod.stringify(originalAst)
var reParsedAst = mod.parse(remadeOdata)

console.log(remadeOdata)

will result in:

`$select=name&$filter=((nullable_string) ne (null)) and ((telephone_number) eq (999999999))`

assert passes as well:

assert.deepEqual(originalAst, reParsedAst)

Issue Reporting

If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.

Author

Auth0

License

This project is licensed under the MIT license. See the LICENSE file for more info.

9.0.0

6 years ago

8.0.0

6 years ago

7.0.4

6 years ago

7.0.3

6 years ago

7.0.2

6 years ago

7.0.1

6 years ago

7.0.0

6 years ago

6.2.2

7 years ago

6.2.1

7 years ago

6.2.0

7 years ago

6.1.4

7 years ago

6.1.3

7 years ago

6.1.2

7 years ago

6.1.1

7 years ago

6.1.0

7 years ago

6.0.0

7 years ago

5.0.1

7 years ago

5.0.0

7 years ago

4.5.1

7 years ago

4.5.0

7 years ago

4.4.0

7 years ago

4.3.0

7 years ago

4.2.0

7 years ago

4.1.0

7 years ago

4.0.2

7 years ago

4.0.1

7 years ago

4.0.0

7 years ago

3.0.0

7 years ago

2.4.1

7 years ago

2.4.0

7 years ago

2.3.0

7 years ago

2.2.0

8 years ago

2.1.0

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.3.0

9 years ago

1.2.2

9 years ago