json-server
Advanced tools
+4
-0
| # Change Log | ||
| ## [0.10.1][2017-05-16] `GET /posts?_sort=user,views&_order=desc,asc` | ||
| * Multiple fields sorting | ||
| ## [0.10.0][2017-04-26] | ||
@@ -4,0 +8,0 @@ |
@@ -137,11 +137,7 @@ 'use strict'; | ||
| if (_sort) { | ||
| _order = _order || 'ASC'; | ||
| chain = chain.sortBy(function (element) { | ||
| return _.get(element, _sort); | ||
| var _sortSet = _sort.split(','); | ||
| var _orderSet = (_order || '').split(',').map(function (s) { | ||
| return s.toLowerCase(); | ||
| }); | ||
| if (_order === 'DESC') { | ||
| chain = chain.reverse(); | ||
| } | ||
| chain = chain.orderBy(_sortSet, _orderSet); | ||
| } | ||
@@ -148,0 +144,0 @@ |
+1
-1
| { | ||
| "name": "json-server", | ||
| "version": "0.10.0", | ||
| "version": "0.10.1", | ||
| "description": "Serves JSON files through REST routes.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/server/index.js", |
+8
-2
@@ -157,6 +157,12 @@ # JSON Server [](https://travis-ci.org/typicode/json-server) [](http://badge.fury.io/js/json-server) [](https://gitter.im/typicode/json-server?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
| ``` | ||
| GET /posts?_sort=views&_order=DESC | ||
| GET /posts/1/comments?_sort=votes&_order=ASC | ||
| GET /posts?_sort=views&_order=asc | ||
| GET /posts/1/comments?_sort=votes&_order=asc | ||
| ``` | ||
| For multiple fields, use the following format: | ||
| ``` | ||
| GET /posts?_sort=user,views&_order=desc,asc | ||
| ``` | ||
| ### Slice | ||
@@ -163,0 +169,0 @@ |
@@ -45,2 +45,14 @@ const assert = require('assert') | ||
| db.buyers = [ | ||
| { id: 1, name: 'Aileen', country: 'Colombia', total: 100 }, | ||
| { id: 2, name: 'Barney', country: 'Colombia', total: 200 }, | ||
| { id: 3, name: 'Carley', country: 'Colombia', total: 300 }, | ||
| { id: 4, name: 'Daniel', country: 'Belize', total: 30 }, | ||
| { id: 5, name: 'Ellen', country: 'Belize', total: 20 }, | ||
| { id: 6, name: 'Frank', country: 'Belize', total: 10 }, | ||
| { id: 7, name: 'Grace', country: 'Argentina', total: 1 }, | ||
| { id: 8, name: 'Henry', country: 'Argentina', total: 2 }, | ||
| { id: 9, name: 'Isabelle', country: 'Argentina', total: 3 } | ||
| ] | ||
| db.refs = [ | ||
@@ -273,2 +285,14 @@ { id: 'abcd-1234', url: 'http://example.com', postId: 1, userId: 1 } | ||
| )) | ||
| it('should sort on multiple fields', () => ( | ||
| request(server) | ||
| .get('/buyers?_sort=country,total&_order=asc,desc') | ||
| .expect('Content-Type', /json/) | ||
| .expect([ | ||
| db.buyers[8], db.buyers[7], db.buyers[6], | ||
| db.buyers[3], db.buyers[4], db.buyers[5], | ||
| db.buyers[2], db.buyers[1], db.buyers[0] | ||
| ]) | ||
| .expect(200) | ||
| )) | ||
| }) | ||
@@ -275,0 +299,0 @@ |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
95292
1.26%2190
0.92%551
1.1%