pax_global_header00006660000000000000000000000064124555345410014522gustar00rootroot0000000000000052 comment=1a90e0b70695f08e3eab32be2f1a867b4bbe6880 node-parents-1.0.1/000077500000000000000000000000001245553454100141205ustar00rootroot00000000000000node-parents-1.0.1/.travis.yml000066400000000000000000000000531245553454100162270ustar00rootroot00000000000000language: node_js node_js: - 0.6 - 0.8 node-parents-1.0.1/LICENSE000066400000000000000000000020611245553454100151240ustar00rootroot00000000000000This software is released under the MIT license: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. node-parents-1.0.1/example/000077500000000000000000000000001245553454100155535ustar00rootroot00000000000000node-parents-1.0.1/example/dirname.js000066400000000000000000000001201245553454100175210ustar00rootroot00000000000000var parents = require('../'); var dirs = parents(__dirname); console.dir(dirs); node-parents-1.0.1/example/win32.js000066400000000000000000000002401245553454100170470ustar00rootroot00000000000000var parents = require('../'); var dir = 'C:\\Program Files\\Maxis\\Sim City 2000\\cities'; var dirs = parents(dir, { platform : 'win32' }); console.dir(dirs); node-parents-1.0.1/index.js000066400000000000000000000025621245553454100155720ustar00rootroot00000000000000var 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(/:\.$/, ':') } } } node-parents-1.0.1/package.json000066400000000000000000000016021245553454100164050ustar00rootroot00000000000000{ "name" : "parents", "version" : "1.0.1", "description" : "return all the parent directories for a directory", "main" : "index.js", "bin" : {}, "directories" : { "example" : "example", "test" : "test" }, "dependencies" : { "path-platform": "~0.11.15" }, "devDependencies" : { "tap" : "~0.2.5" }, "scripts" : { "test" : "tap test/*.js" }, "repository" : { "type" : "git", "url" : "git://github.com/substack/node-parents.git" }, "homepage" : "https://github.com/substack/node-parents", "keywords" : [ "directory", "parent", "path", "tree" ], "author" : { "name" : "James Halliday", "email" : "mail@substack.net", "url" : "http://substack.net" }, "license" : "MIT", "engine" : { "node" : ">=0.6" } } node-parents-1.0.1/readme.markdown000066400000000000000000000030451245553454100171230ustar00rootroot00000000000000# parents Return all the parent directories of a directory, inclusive of that directory. [![build status](https://secure.travis-ci.org/substack/node-parents.png)](http://travis-ci.org/substack/node-parents) # example ## dirname ``` js var parents = require('parents'); var dirs = parents(__dirname); console.dir(dirs); ``` *** ``` [ '/home/substack/projects/node-parents/example', '/home/substack/projects/node-parents', '/home/substack/projects', '/home/substack', '/home', '/' ] ``` ## win32 ``` js var parents = require('parents'); var dir = 'C:\\Program Files\\Maxis\\Sim City 2000\\cities'; var dirs = parents(dir, { platform : 'win32' }); console.dir(dirs); ``` *** ``` [ 'C:\\Program Files\\Maxis\\Sim City 2000\\cities', 'C:\\Program Files\\Maxis\\Sim City 2000', 'C:\\Program Files\\Maxis', 'C:\\Program Files', 'C:' ] ``` # methods ``` js var parents = require('parents') ``` ## parents(dir, opts) Return an array of the parent directories of `dir`, including and starting with `dir`. If a `dir` isn't specified, `process.cwd()` will be used. Optionally specify an `opts.platform` to control whether the separator and paths works the unixy way with `'/'` or the windowsy way where sometimes things use `'/'` and sometimes they use `'\\'` and also there are leading drive letters and other exotic features. If `opts.platform` isn't specified, `process.platform` will be used. Anything that matches `/^win/` will use the windowsy behavior. # install With [npm](http://npmjs.org) do: ``` npm install parents ``` # licence MIT node-parents-1.0.1/test/000077500000000000000000000000001245553454100150775ustar00rootroot00000000000000node-parents-1.0.1/test/dirname.js000066400000000000000000000006031245553454100170530ustar00rootroot00000000000000var test = require('tap').test; var parents = require('../'); test('dirname', function (t) { var dirs = parents('/foo/bar/baz/quux'); t.same(dirs, [ '/foo/bar/baz/quux', '/foo/bar/baz', '/foo/bar', '/foo', '/', ]); t.end(); }); test('root', function (t) { var dirs = parents('/'); t.same(dirs, [ '/' ]); t.end(); }); node-parents-1.0.1/test/win32.js000066400000000000000000000016211245553454100163770ustar00rootroot00000000000000var test = require('tap').test; var parents = require('../'); test('win32', function (t) { var dir = 'c:\\Program Files\\Maxis\\Sim City 2000\\cities'; var dirs = parents(dir, { platform : 'win32' }); t.same(dirs, [ 'c:\\Program Files\\Maxis\\Sim City 2000\\cities', 'c:\\Program Files\\Maxis\\Sim City 2000', 'c:\\Program Files\\Maxis', 'c:\\Program Files', 'c:', ]); t.end(); }); test('win32 c:', function (t) { var dirs = parents('c:\\', { platform : 'win32' }); t.same(dirs, [ 'c:' ]); t.end(); }); test('win32 network drive', function (t) { var dirs = parents( '\\storageserver01\\Active Projects\\ProjectA', { platform : 'win32' } ); t.same(dirs, [ '\\storageserver01\\Active Projects\\ProjectA', '\\storageserver01\\Active Projects', '\\storageserver01' ]); t.end(); });