-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.js
More file actions
32 lines (30 loc) · 870 Bytes
/
util.js
File metadata and controls
32 lines (30 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const _ = require('lodash')
, {join} = require('path')
, async = require('async')
module.exports = {
obj(key, val) {
const result = {}
result[key] = val
return result
},
require(...path) {
return require(this.rel.apply(this, path))
},
getType(obj) {
const ptype = Object.prototype.toString.call(obj).slice(8, -1)
return ptype === 'Object' ? obj.constructor.name.toString() : ptype
},
getModelSummary(model) {
return _.pick(model.definition, ['properties', 'settings', 'relations', 'indexes'])
},
objMapAsync(obj, iter, done) {
const wrappedIter = (results, key, next) => {
const interpret = (err, result) => {
results[key] = result
return next(err, results)
}
return iter(obj[key], interpret, key)
}
return async.reduce(Object.keys(obj), {}, wrappedIter, done)
},
}