[Pkg-javascript-commits] [node-parents] 01/29: module to list parents recursively

Bastien Roucariès rouca at moszumanska.debian.org
Sun Aug 20 13:47:03 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-parents.

commit e590ea036d1ce6ca21d023093ed16462e95c7d37
Author: James Halliday <mail at substack.net>
Date:   Thu Jul 12 01:21:40 2012 -0700

    module to list parents recursively
---
 index.js | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/index.js b/index.js
new file mode 100644
index 0000000..072eb41
--- /dev/null
+++ b/index.js
@@ -0,0 +1,27 @@
+var path = require('path');
+
+module.exports = function (cwd, opts) {
+    if (cwd === undefined) cwd = process.cwd();
+    if (!opts) opts = {};
+    var platform = opts.platform || process.platform;
+    
+    var isWindows = /^win/.test(platform);
+    var sep = isWindows ? /[\\\/]/ : '/';
+    var init = isWindows ? '' : '/';
+    
+    var join = function (x, y) {
+        var ps = [].slice.call(arguments).filter(function (p) {
+            return p && typeof p === 'string'
+        });
+        return path.normalize(ps.join(isWindows ? '\\' : '/'));
+    };
+    
+    return path.normalize(cwd)
+        .split(sep)
+        .reduce(function (acc,dir,ix) {
+            return acc.concat(join(acc[ix], dir))
+        }, [init])
+        .slice(1)
+        .reverse()
+    ;
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-parents.git



More information about the Pkg-javascript-commits mailing list