1
1
Fork 0
portfolio/repos/json-query-chain.md
2021-02-25 23:22:34 -06:00

1.4 KiB

tags templateEngineOverride title description date
repos md json-query-chain Chain queries onto POJOs to return precise results. 2018-02-23

Fork on Gitlab

npm version

100% test covered and developed with Test-Driven Development.

Usage

import Query from 'json-query-chain';

let myQ = new Query(someJsonData)
.search('isActiveUser', true)
.results;

Chainable Methods

Currently supports booleans and strings. (See #1 for Integer Support)

By Boolean
.search('isActiveUser', true)
By String
.search('name', 'steele')

Filter

Simpler version of search using a custom function in the chain.

.filter(a => a.age >= 21)
By Key
.filterBy('age', x => x >= 21)

Sort

By Boolean
.sort('isActiveUser', true)
By String
.sort('name')
By Number
.sort('netWorth')

Pagination

Page 1 with 5 results per page.

.paginate(1, 5)

Page 2 wtih default of 10 results per page.

.paginate(2)

Tests

npm test runs tests through Jest