mirror of
https://github.com/typicode/json-server.git
synced 2025-07-29 05:03:04 +08:00
Use lodash
This commit is contained in:
@ -14,13 +14,12 @@
|
|||||||
"errorhandler": "^1.2.0",
|
"errorhandler": "^1.2.0",
|
||||||
"express": "^4.9.5",
|
"express": "^4.9.5",
|
||||||
"got": "^1.2.2",
|
"got": "^1.2.2",
|
||||||
"lodash": "^3.9.1",
|
"lodash": "^3.9.2",
|
||||||
"lowdb": "^0.7.1",
|
"lowdb": "^0.7.1",
|
||||||
"method-override": "^2.1.2",
|
"method-override": "^2.1.2",
|
||||||
"morgan": "^1.3.1",
|
"morgan": "^1.3.1",
|
||||||
"node-uuid": "^1.4.2",
|
"node-uuid": "^1.4.2",
|
||||||
"pluralize": "^1.1.2",
|
"pluralize": "^1.1.2",
|
||||||
"underscore": "^1.8.3",
|
|
||||||
"underscore-db": "^0.8.0",
|
"underscore-db": "^0.8.0",
|
||||||
"update-notifier": "^0.2.2",
|
"update-notifier": "^0.2.2",
|
||||||
"yargs": "^1.3.1"
|
"yargs": "^1.3.1"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
var express = require('express')
|
var express = require('express')
|
||||||
var methodOverride = require('method-override')
|
var methodOverride = require('method-override')
|
||||||
var bodyParser = require('body-parser')
|
var bodyParser = require('body-parser')
|
||||||
var _ = require('underscore')
|
var _ = require('lodash')
|
||||||
var low = require('lowdb')
|
var low = require('lowdb')
|
||||||
var pluralize = require('pluralize')
|
var pluralize = require('pluralize')
|
||||||
var utils = require('./utils')
|
var utils = require('./utils')
|
||||||
@ -202,7 +202,7 @@ module.exports = function (source) {
|
|||||||
// Remove dependents documents
|
// Remove dependents documents
|
||||||
var removable = utils.getRemovable(db.object)
|
var removable = utils.getRemovable(db.object)
|
||||||
|
|
||||||
_(removable).each(function (item) {
|
_.each(removable, function (item) {
|
||||||
db(item.name).remove(item.id)
|
db(item.name).remove(item.id)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
var _ = require('underscore')
|
var _ = require('lodash')
|
||||||
var uuid = require('node-uuid')
|
var uuid = require('node-uuid')
|
||||||
var pluralize = require('pluralize')
|
var pluralize = require('pluralize')
|
||||||
|
|
||||||
@ -44,9 +44,9 @@ function createId (coll) {
|
|||||||
// 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) {
|
||||||
var removable = []
|
var removable = []
|
||||||
_(db).each(function (coll, collName) {
|
_.each(db, function (coll, collName) {
|
||||||
_(coll).each(function (doc) {
|
_.each(coll, function (doc) {
|
||||||
_(doc).each(function (value, key) {
|
_.each(doc, function (value, key) {
|
||||||
if (/Id$/.test(key)) {
|
if (/Id$/.test(key)) {
|
||||||
var refName = pluralize.plural(key.slice(0, -2))
|
var refName = pluralize.plural(key.slice(0, -2))
|
||||||
// Test if table exists
|
// Test if table exists
|
||||||
|
Reference in New Issue
Block a user