List dependents of a package. #11

Merged
merged 1 commit into from Nov 11, 2012
Jump to file
+22 −0
Split
View
@@ -30,6 +30,7 @@ function fetch() {
if (!pkg.description) console.log('"description" missing for %s', pkg.name);
words = words.concat(parse(pkg.description));
words = words.concat(pkg.keywords || []);
+ pkg.dependents = dependents(pkg, pkgs)
pkg.stars = 0;
++pending;
@@ -69,6 +70,27 @@ function fetch() {
});
}
+/**
+ * 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`.
+ */
+function dependents(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
+ })
+}
+
+function blank(pkg) {
+ return !!pkg
tj
tj Nov 11, 2012 Contributor

hehe :D I still need to find the source of these damn blanks

+}
+
function parse(str) {
str = String(str).trim();
if (!str) return [];