-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
43 lines (34 loc) · 881 Bytes
/
utils.js
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
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
var utils = require('lazy-cache')(require);
var fn = require;
require = utils;
/**
* Lazily required module dependencies
*/
require('async-each-series', 'eachSeries');
require('data-store', 'DataStore');
require('extend-shallow', 'extend');
require('fs-exists-sync', 'exists');
require('get-value', 'get');
require('is-valid-app', 'isValid');
require('isobject', 'isObject');
require = fn;
/**
* Cast `val` to an array
*/
utils.arrayify = function(val) {
return val ? (Array.isArray(val) ? val : [val]) : [];
};
/**
* Remove names that are already listed in `package.json`
*/
utils.unique = function(pkg, type, keys) {
var names = utils.arrayify(Object.keys(utils.get(pkg, type) || {}));
return utils.arrayify(keys).filter(function(name) {
return names.indexOf(name) === -1;
});
};
/**
* Expose `utils` modules
*/
module.exports = utils;