Sha256: 96f30c3b1fd7b3cbfddd17a9053271d1329ce20b489351770a8e8440e8da5b3b

Contents?: true

Size: 1.36 KB

Versions: 7

Compression:

Stored size: 1.36 KB

Contents

var pathPlatform = require('path-platform');

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 path = isWindows ? pathPlatform.win32 : pathPlatform;
    var normalize = !isWindows ? path.normalize :
        path.normalize('c:') === 'c:.' ? fixNormalize(path.normalize) :
        path.normalize;
    var sep = isWindows ? /[\\\/]/ : '/';
    var init = isWindows ? '' : '/';
    
    var join = function (x, y) {
        var ps = [ x, y ].filter(function (p) {
            return p && typeof p === 'string'
        });

        return normalize(ps.join(isWindows ? '\\' : '/'));
    };
    
    var res = normalize(cwd)
        .split(sep)
        .reduce(function (acc,dir,ix) {
            return acc.concat(join(acc[ix], dir))
        }, [init])
        .slice(1)
        .reverse()
    ;
    if (res[0] === res[1]) return [ res[0] ];
    if (isWindows && /^\\/.test(cwd)) {
        return res.slice(0,-1).map(function (d) {
            var ch = d.charAt(0)
            return ch === '\\' ? d :
              ch === '.' ? '\\' + d.slice(1) :
              '\\' + d
        });
    }
    return res;

    function fixNormalize(fn) {
      return function(p) {
        return fn(p).replace(/:\.$/, ':')
      }
    }
}

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
minimum_viable_product-0.0.11 test/dummy/node_modules/parents/index.js
brwy_rails-0.0.6 test/dummy/node_modules/parents/index.js
brwy_rails-0.0.5 test/dummy/node_modules/parents/index.js
brwy_rails-0.0.4 test/dummy/node_modules/parents/index.js
brwy_rails-0.0.3 test/dummy/node_modules/parents/index.js
brwy_rails-0.0.2 test/dummy/node_modules/parents/index.js
brwy_rails-0.0.1 test/dummy/node_modules/parents/index.js