diff --git a/README.md b/README.md index e628b29..6a4d75a 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,6 @@ Simpler version of search using a custom function in the chain. #### Sort -Currently supports booleans and strings. (See [#1](https://github.com/sharpshark28/json-query-chain/issues/2) for Integer Support) - ##### By Boolean ```javascript @@ -62,6 +60,12 @@ Currently supports booleans and strings. (See [#1](https://github.com/sharpshark .sort('name') ``` +##### By Number + +```javascript +.sort('netWorth') +``` + #### Pagination Page 1 with 5 results per page. diff --git a/index.test.js b/index.test.js index 4351cd0..6b78a85 100644 --- a/index.test.js +++ b/index.test.js @@ -58,6 +58,16 @@ test('should sort by boolean isActive', () => { expect(query[0].name).toBe('Katelyn Steele'); }); +test('should sort by number netWorth', () => { + let query = new Query(TestData) + .sort('netWorth') + .results; + + expect(query[0].name).toBe('Howard Buckley'); // Negative + expect(query[1].name).toBe('Natalia Petty'); // 0 + expect(query[query.length - 1].name).toBe('Newman Mays'); // Richest +}); + test('should sort by string name', () => { let query = new Query(TestData) .sort('name') diff --git a/testdata.json b/testdata.json index 584c507..0bdba63 100644 --- a/testdata.json +++ b/testdata.json @@ -3,6 +3,7 @@ "_id": "5928038b69b33613f3577487", "isActive": true, "age": 20, + "netWorth": 54200.49, "name": "Haynes Meadows", "tags": [ "et", @@ -18,6 +19,7 @@ "_id": "5928038ba2400e7e09550991", "isActive": false, "age": 22, + "netWorth": 11900, "name": "Katelyn Steele", "tags": [ "cupidatat", @@ -33,6 +35,7 @@ "_id": "5928038bff4df5c29016be22", "isActive": false, "age": 29, + "netWorth": 0, "name": "Natalia Petty", "tags": [ "nulla", @@ -48,6 +51,7 @@ "_id": "5928038b496f64e646cb8d69", "isActive": false, "age": 34, + "netWorth": -5000.2, "name": "Howard Buckley", "tags": [ "qui", @@ -63,6 +67,7 @@ "_id": "5928038b4d214186ba1e7fa2", "isActive": false, "age": 22, + "netWorth": 401512.99, "name": "Jenkins Mosley", "tags": [ "adipisicing",