OData Filter Builder
npm install odata-filter-builderODataFilterBuilder is util to build


ODataFilterBuilder - logical operatorsODataFilterBuilder.filters - canonical functionsThe fastest way to get started is to serve JavaScript from the unpkg:
``html`
`js`
// now you can find the library on window.ODataFilterBuilder
var f = ODataFilterBuilder;
If you'd like to use bower:
`sh`
$ bower install --save https://unpkg.com/odata-filter-builder@1.0.0-0/dist/odata-filter-builder.js
And it's just as easy with npm:
`sh`
$ npm install --save odata-filter-builder`js`
// using ES6 modules
import f from 'odata-filter-builder';`js`
// using CommonJS modules
var f = require('odata-filter-builder').ODataFilterBuilder;
Also you can try it in your browser
Constructor for ODataFilterBuilder class. Create new instance of filter builder.
Can be used without new operator.
| parameter | type | description |
| ------------------- | ------ | ------------------------------------------ |
| [condition='and'] | string | _optional:_ base condition ('and'/'or'). |
Examples
`js`
// can be used without "new" operator
// default base condition is 'and'
f()
.eq('TypeId', '1')
.contains(x => x.toLower('Name'), 'a')
.toString();
// (TypeId eq '1') and (contains(tolower(Name), 'a'))`js`
// there are different constructors for 'and' as base condition
// f(), f('and') and f.and()
f('and')
.eq('Type/Id', 3)
.eq(x => x.concat(y => y.concat('City',', '), 'Country', false), 'Berlin, Germany')
.toString();
// (Type/Id eq 3) and (concat(concat(City, ', '), Country) eq 'Berlin, Germany')
ODataFilterBuilder
constructor alias.
Same as f('or').'or'
Creates a new OData filter builder with as base condition.
Examples
`js`
// 'or' condition as base condition
f('or')
.eq(x => x.toLower('Name'), 'foo')
.eq(x => x.toLower('Name'), 'bar')
.toString();
// (tolower(Name) eq 'foo') or (tolower(Name) eq 'bar')`js`
// combination of 'or' and 'and'
f('or')
.contains(x => x.toLower('Name'), 'google')
.contains(x => x.toLower('Name'), 'yandex')
.and(x => x.eq('Type/Name', 'Search Engine'))
.toString();
// ((contains(tolower(Name), 'google')) or (contains(tolower(Name), 'yandex'))) and (Type/Name eq 'Search Engine')
To use with AngularJS see http://stackoverflow.com/a/36128276/223750.
Clone repository and use npm scripts
`sh`
$ npm test
$ npm run test:watch
$ npm run test:cov
$ npm run lint
`sh`
$ npm run build
`sh``
$ npm run jsdoc