Fix code style

This commit is contained in:
Typicode
2015-05-13 18:34:22 +02:00
parent ce73c479b4
commit b1ca61ba9e
8 changed files with 105 additions and 100 deletions

View File

@ -59,10 +59,11 @@ function start(object, filename) {
} }
}) })
var router
if (filename) { if (filename) {
var router = jsonServer.router(filename) router = jsonServer.router(filename)
} else { } else {
var router = jsonServer.router(object) router = jsonServer.router(object)
} }
var server = jsonServer.create() var server = jsonServer.create()

View File

@ -27,10 +27,11 @@
"devDependencies": { "devDependencies": {
"husky": "^0.6.1", "husky": "^0.6.1",
"mocha": "^2.2.4", "mocha": "^2.2.4",
"standard": "^3.8.0",
"supertest": "~0.8.1" "supertest": "~0.8.1"
}, },
"scripts": { "scripts": {
"test": "mocha -R spec test", "test": "standard && mocha -R spec test",
"start": "node bin", "start": "node bin",
"prepush": "npm t" "prepush": "npm t"
}, },

View File

@ -13,9 +13,9 @@ arr.push(logger('dev', {
// Serve static files // Serve static files
if (fs.existsSync(process.cwd() + '/public')) { if (fs.existsSync(process.cwd() + '/public')) {
arr.push(express.static(process.cwd() + '/public')); arr.push(express.static(process.cwd() + '/public'))
} else { } else {
arr.push(express.static(__dirname + '/public')); arr.push(express.static(__dirname + '/public'))
} }
// CORS // CORS

View File

@ -23,11 +23,12 @@ module.exports = function(source) {
router.use(methodOverride()) router.use(methodOverride())
// Create database // Create database
var db
if (_.isObject(source)) { if (_.isObject(source)) {
var db = low() db = low()
db.object = source db.object = source
} else { } else {
var db = low(source) db = low(source)
} }
// Expose database // Expose database
@ -113,11 +114,11 @@ module.exports = function(source) {
_order = _order || 'ASC' _order = _order || 'ASC'
array = _.sortBy(array, function (element) { array = _.sortBy(array, function (element) {
return element[_sort]; return element[_sort]
}) })
if (_order === 'DESC') { if (_order === 'DESC') {
array.reverse(); array.reverse()
} }
} }
@ -127,13 +128,14 @@ module.exports = function(source) {
res.setHeader('Access-Control-Expose-Headers', 'X-Total-Count') res.setHeader('Access-Control-Expose-Headers', 'X-Total-Count')
} }
_start = parseInt(_start) || 0 _start = parseInt(_start, 10) || 0
if (_end) { if (_end) {
array = array.slice(_start, parseInt(_end)) _end = parseInt(_end, 10)
array = array.slice(_start, _end)
} else if (_limit) { } else if (_limit) {
// Convert strings to int and sum to get end value _limit = parseInt(_limit, 10)
array = array.slice(_start, parseInt(_start) + parseInt(_limit)) array = array.slice(_start, _start + _limit)
} }
res.jsonp(array) res.jsonp(array)

View File

@ -39,7 +39,6 @@ function createId(coll) {
} }
} }
// Returns document ids that have unsatisfied relations // Returns document ids that have unsatisfied relations
// Example: a comment that references a post that doesn't exist // Example: a comment that references a post that doesn't exist
function getRemovable (db) { function getRemovable (db) {

View File

@ -1,7 +1,9 @@
var request = require('supertest') var request = require('supertest')
var assert = require('assert') var assert = require('assert')
var jsonServer = require('../src/') var jsonServer = require('../src/')
var utils = require('../src/utils')
/* global beforeEach, describe, it */
describe('Server', function () { describe('Server', function () {
var server var server
@ -166,8 +168,7 @@ describe('Server', function() {
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect([ .expect([
db.comments[0], db.comments[0],
db.comments[1], db.comments[1]
]) ])
.expect(200, done) .expect(200, done)
}) })
@ -199,7 +200,6 @@ describe('Server', function() {
}) })
}) })
describe('POST /:resource', function () { describe('POST /:resource', function () {
it('should respond with json, create a resource and increment id', it('should respond with json, create a resource and increment id',
function (done) { function (done) {

View File

@ -1,6 +1,8 @@
var assert = require('assert') var assert = require('assert')
var utils = require('../src/utils') var utils = require('../src/utils')
/* global describe, it */
describe('utils', function () { describe('utils', function () {
describe('getRemovable', function () { describe('getRemovable', function () {
@ -15,7 +17,7 @@ describe('utils', function() {
{id: 1, postId: 1}, {id: 1, postId: 1},
// Comments below references a post that doesn't exist // Comments below references a post that doesn't exist
{id: 2, postId: 2}, {id: 2, postId: 2},
{id: 3, postId: 2}, {id: 3, postId: 2}
] ]
} }