Socket
Socket
Sign inDemoInstall

json-server

Package Overview
Dependencies
Maintainers
1
Versions
154
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-server - npm Package Compare versions

Comparing version 0.10.0 to 0.10.1

4

CHANGELOG.md
# 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 @@

12

lib/server/router/plural.js

@@ -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 @@

{
"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",

@@ -157,6 +157,12 @@ # JSON Server [![](https://travis-ci.org/typicode/json-server.svg?branch=master)](https://travis-ci.org/typicode/json-server) [![](https://badge.fury.io/js/json-server.svg)](http://badge.fury.io/js/json-server) [![](https://badges.gitter.im/Join%20Chat.svg)](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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc