Chain queries onto POJOs to return precise results.
Find a file
2018-03-18 17:46:11 -05:00
.eslintrc.js Eslint 2018-02-22 19:14:15 -06:00
.gitignore Coverage badge 2018-02-22 18:45:22 -06:00
.travis.yml Code climate fixes, travis config, badge 2017-08-20 20:21:44 -05:00
coverage.svg Coverage badge 2018-02-22 18:45:22 -06:00
index.js Flat array support 2018-03-18 17:46:11 -05:00
index.test.js Flat array support 2018-03-18 17:46:11 -05:00
package.json 1.1.3 2018-03-18 17:34:54 -05:00
README.md Flat array support 2018-03-18 17:46:11 -05:00
testdata.json Test to prove sorting by integer works 2017-08-17 18:17:06 -05:00

json-query-chain

Build Status npm version Code Coverage Maintainability

Chain queries onto arrays and arrays of objects to return precise results. See example usages in the tests running on this test data.

Usage

import Query from 'json-query-chain';

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

console.log('Results: ', query);

Chainable Methods

By Boolean

Acts as a smart filter returning only elements who's key matches the expected result.

.search(true, 'isActiveUser')
By String

Sorts and filters out any elements in the array not matching the requested value while attempting to raise the best results to the top (most frequent number of occurrences).

.search('steele', 'name')

Filter

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

.filter(a => a.age >= 21)
By Key

Like .filter(), but narrowed down by key.

.filterBy('age', x => x >= 21)

Sort

A chainable version of javascript's built in array sort.

.sort((a, b) => a > b)
By Boolean

Abstracted sort by matching a key to a boolean.

.sortBy('isActiveUser')
By String

Sorts alphabetically based on key.

.sortBy('name')
By Number

Sorts by ascending numerical order based on key.

.sortBy('netWorth')

Pagination

Page 1 with 5 results per page.

.paginate(1, 5)

Page 2 with default of 10 results per page.

.paginate(2)

Tests

npm test runs tests through Jest