-
Notifications
You must be signed in to change notification settings - Fork 8
/
util.js
67 lines (57 loc) · 1.22 KB
/
util.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* Parse words.
* @param str {String}
* @return {Array} Words.
*/
exports.words = function(str) {
str = String(str).trim();
if (!str) return [];
return str.match(/\w+/).map(function(word){
return word.toLowerCase();
});
};
/**
* Word keys from `words`.
* @param words {Array}
* @return {Array} Word keys.
*/
exports.wordKeys = function(words) {
return words.map(function(str){
return 'word:' + str;
});
};
/**
* Component keys from `names`.
* @param names {Array}
* @return {Array} Component keys.
*/
exports.componentKeys = function(names) {
return names.map(function(str){
return 'component:' + str;
});
};
/**
* List packages that depend on the supplied package, `pkg`.
*
* @param pkg
* @param pkgs {Array} All packages to analyse.
* @return {Array} Repos of packages that depend on `pkg`.
*/
exports.dependents = function(pkg, pkgs) {
var repo = pkg.repo
return pkgs.filter(blank).filter(function(pkg) {
pkg.dependencies = pkg.dependencies || []
return Object.keys(pkg.dependencies).indexOf(repo) !== -1
}).map(function(pkg) {
return pkg.repo
})
}
/**
* Check, if `pkg` is blank.
*
* @param pkg
* @return {Boolean}
*/
function blank(pkg) {
return !!pkg
}