@lanetix/odata-parser

    9.0.0 • Public • Published

    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.

    Keywords

    Install

    npm i @lanetix/odata-parser

    DownloadsWeekly Downloads

    1,042

    Version

    9.0.0

    License

    MIT

    Last publish

    Collaborators

    • gauthamvr-qb
    • lanetix-system
    • manu-kodiyan-winmore
    • dnm-winmore
    • mkdyanugk
    • rahulkookal
    • albin_alias
    • vigneshk7
    • abdulshukkoor-qb
    • soumyaarun
    • aswanth
    • sajith.qb
    • jobinqb
    • dhiluraj-qburst
    • anandqb
    • arun-dtk
    • vikasqb
    • acpradosh1234
    • jasifqb