mirror of
https://github.com/typicode/json-server.git
synced 2025-07-28 12:43:18 +08:00
Fix code style
This commit is contained in:
@ -59,10 +59,11 @@ function start(object, filename) {
|
||||
}
|
||||
})
|
||||
|
||||
var router
|
||||
if (filename) {
|
||||
var router = jsonServer.router(filename)
|
||||
router = jsonServer.router(filename)
|
||||
} else {
|
||||
var router = jsonServer.router(object)
|
||||
router = jsonServer.router(object)
|
||||
}
|
||||
|
||||
var server = jsonServer.create()
|
||||
|
@ -27,10 +27,11 @@
|
||||
"devDependencies": {
|
||||
"husky": "^0.6.1",
|
||||
"mocha": "^2.2.4",
|
||||
"standard": "^3.8.0",
|
||||
"supertest": "~0.8.1"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha -R spec test",
|
||||
"test": "standard && mocha -R spec test",
|
||||
"start": "node bin",
|
||||
"prepush": "npm t"
|
||||
},
|
||||
|
@ -13,9 +13,9 @@ arr.push(logger('dev', {
|
||||
|
||||
// Serve static files
|
||||
if (fs.existsSync(process.cwd() + '/public')) {
|
||||
arr.push(express.static(process.cwd() + '/public'));
|
||||
arr.push(express.static(process.cwd() + '/public'))
|
||||
} else {
|
||||
arr.push(express.static(__dirname + '/public'));
|
||||
arr.push(express.static(__dirname + '/public'))
|
||||
}
|
||||
|
||||
// CORS
|
||||
|
@ -23,11 +23,12 @@ module.exports = function(source) {
|
||||
router.use(methodOverride())
|
||||
|
||||
// Create database
|
||||
var db
|
||||
if (_.isObject(source)) {
|
||||
var db = low()
|
||||
db = low()
|
||||
db.object = source
|
||||
} else {
|
||||
var db = low(source)
|
||||
db = low(source)
|
||||
}
|
||||
|
||||
// Expose database
|
||||
@ -113,11 +114,11 @@ module.exports = function(source) {
|
||||
_order = _order || 'ASC'
|
||||
|
||||
array = _.sortBy(array, function (element) {
|
||||
return element[_sort];
|
||||
return element[_sort]
|
||||
})
|
||||
|
||||
if (_order === 'DESC') {
|
||||
array.reverse();
|
||||
array.reverse()
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,13 +128,14 @@ module.exports = function(source) {
|
||||
res.setHeader('Access-Control-Expose-Headers', 'X-Total-Count')
|
||||
}
|
||||
|
||||
_start = parseInt(_start) || 0
|
||||
_start = parseInt(_start, 10) || 0
|
||||
|
||||
if (_end) {
|
||||
array = array.slice(_start, parseInt(_end))
|
||||
_end = parseInt(_end, 10)
|
||||
array = array.slice(_start, _end)
|
||||
} else if (_limit) {
|
||||
// Convert strings to int and sum to get end value
|
||||
array = array.slice(_start, parseInt(_start) + parseInt(_limit))
|
||||
_limit = parseInt(_limit, 10)
|
||||
array = array.slice(_start, _start + _limit)
|
||||
}
|
||||
|
||||
res.jsonp(array)
|
||||
|
@ -39,7 +39,6 @@ function createId(coll) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Returns document ids that have unsatisfied relations
|
||||
// Example: a comment that references a post that doesn't exist
|
||||
function getRemovable (db) {
|
||||
|
@ -1,7 +1,9 @@
|
||||
var request = require('supertest')
|
||||
var assert = require('assert')
|
||||
var jsonServer = require('../src/')
|
||||
var utils = require('../src/utils')
|
||||
|
||||
/* global beforeEach, describe, it */
|
||||
|
||||
describe('Server', function () {
|
||||
|
||||
var server
|
||||
@ -166,8 +168,7 @@ describe('Server', function() {
|
||||
.expect('Content-Type', /json/)
|
||||
.expect([
|
||||
db.comments[0],
|
||||
db.comments[1],
|
||||
|
||||
db.comments[1]
|
||||
])
|
||||
.expect(200, done)
|
||||
})
|
||||
@ -199,7 +200,6 @@ describe('Server', function() {
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
describe('POST /:resource', function () {
|
||||
it('should respond with json, create a resource and increment id',
|
||||
function (done) {
|
||||
|
@ -1,6 +1,8 @@
|
||||
var assert = require('assert')
|
||||
var utils = require('../src/utils')
|
||||
|
||||
/* global describe, it */
|
||||
|
||||
describe('utils', function () {
|
||||
|
||||
describe('getRemovable', function () {
|
||||
@ -15,7 +17,7 @@ describe('utils', function() {
|
||||
{id: 1, postId: 1},
|
||||
// Comments below references a post that doesn't exist
|
||||
{id: 2, postId: 2},
|
||||
{id: 3, postId: 2},
|
||||
{id: 3, postId: 2}
|
||||
]
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user