pax_global_header00006660000000000000000000000064123004470320014505gustar00rootroot0000000000000052 comment=da6471bf050fa206ffbb7a81dadf2985a64aee49 path2-0.1.0/000077500000000000000000000000001230044703200125215ustar00rootroot00000000000000path2-0.1.0/.gitignore000066400000000000000000000000631230044703200145100ustar00rootroot00000000000000.DS_Store /node_modules /npm-debug.log /.lintcache path2-0.1.0/.lint000066400000000000000000000002401230044703200134640ustar00rootroot00000000000000@root module tabs indent 2 maxlen 80 ass continue nomen plusplus regexp ./is-windows.js ./posix/_cwd.js ./windows predef+ process ./test predef+ __dirname path2-0.1.0/.travis.yml000066400000000000000000000001611230044703200146300ustar00rootroot00000000000000language: node_js node_js: - 0.8 - 0.10 - 0.11 notifications: email: - medikoo+path-ext@medikoo.com path2-0.1.0/CHANGES000066400000000000000000000000371230044703200135140ustar00rootroot00000000000000v0.1.0 -- 2014.02.17 Initial path2-0.1.0/LICENCE000066400000000000000000000021111230044703200135010ustar00rootroot00000000000000Copyright Joyent, Inc. and other Node contributors. All rights reserved. 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. path2-0.1.0/README.md000066400000000000000000000026221230044703200140020ustar00rootroot00000000000000# path2 ## Modular and extended version of [Node's path](http://nodejs.org/api/path.html) package Works exactly same as Node's `path`, with following improvements: - Both _windows_ and _posix_ versions can be accessed in any environment program is run. For windows version require `path2/windows` for posix `path2/posix`. - Doesn't depend on existence of `process` object and can safely be used in any enviroment (e.g. browser) which does not provide it. If `process.cwd` is not accessible, _/_ or _C:\_ (for windows) are used as current working directory - Each function is provided as an individual module, so only modules that are needed, can be required e.g. `path2/resolve` or specifically posix version: `path2/posix/resolve` One additional function, not present in native `path`, is provided: ### path.common(path1[, ...pathn]) Resolves common path for given path arguments: ```javascript path.common('/lorem/ipsum/foo/bar', '/lorem/ipsum/raz/dwa', '/lorem/elo/foo/bar'); // => '/lorem' ``` `path.common` is proposed to be [included in native `path`](https://github.com/joyent/node/pull/6328) ### Installation #### NPM In your project path: $ npm install path2 ##### Browser You can easily bundle _path2_ for browser with [modules-webmake](https://github.com/medikoo/modules-webmake) ## Tests [![Build Status](https://travis-ci.org/medikoo/path2.png)](https://travis-ci.org/medikoo/path2) $ npm test path2-0.1.0/_get-dirname-fn.js000066400000000000000000000005431230044703200160150ustar00rootroot00000000000000'use strict'; module.exports = function (splitPath) { return function (path) { var result = splitPath(path), root = result[0], dir = result[1]; if (!root && !dir) { // No dirname whatsoever return '.'; } if (dir) { // It has a dirname, strip trailing slash dir = dir.substr(0, dir.length - 1); } return root + dir; }; }; path2-0.1.0/_get-extname-fn.js000066400000000000000000000001621230044703200160340ustar00rootroot00000000000000'use strict'; module.exports = function (splitPath) { return function (path) { return splitPath(path)[3]; }; }; path2-0.1.0/_normalize-array.js000066400000000000000000000014471230044703200163400ustar00rootroot00000000000000// resolves . and .. elements in a path array with directory names there // must be no slashes, empty elements, or device names (c:\) in the array // (so also no leading and trailing slashes - it does not distinguish // relative and absolute paths) 'use strict'; module.exports = function normalizeArray(parts, allowAboveRoot) { // if the path tries to go above the root, `up` ends up > 0 var up = 0, i, last; for (i = parts.length - 1; i >= 0; i--) { last = parts[i]; if (last === '.') { parts.splice(i, 1); } else if (last === '..') { parts.splice(i, 1); up++; } else if (up) { parts.splice(i, 1); up--; } } // if the path is allowed to go above the root, restore leading ..s if (allowAboveRoot) { for (up; up--; up) { parts.unshift('..'); } } return parts; }; path2-0.1.0/basename.js000066400000000000000000000001701230044703200146300ustar00rootroot00000000000000'use strict'; module.exports = require('./is-windows') ? require('./windows/basename') : require('./posix/basename'); path2-0.1.0/common.js000066400000000000000000000001641230044703200143500ustar00rootroot00000000000000'use strict'; module.exports = require('./is-windows') ? require('./windows/common') : require('./posix/common'); path2-0.1.0/delimiter.js000066400000000000000000000001721230044703200150350ustar00rootroot00000000000000'use strict'; module.exports = require('./is-windows') ? require('./windows/delimiter') : require('./posix/delimiter'); path2-0.1.0/dirname.js000066400000000000000000000001661230044703200145010ustar00rootroot00000000000000'use strict'; module.exports = require('./is-windows') ? require('./windows/dirname') : require('./posix/dirname'); path2-0.1.0/extname.js000066400000000000000000000001661230044703200145230ustar00rootroot00000000000000'use strict'; module.exports = require('./is-windows') ? require('./windows/extname') : require('./posix/extname'); path2-0.1.0/index.js000066400000000000000000000001461230044703200141670ustar00rootroot00000000000000'use strict'; module.exports = require('./is-windows') ? require('./windows') : require('./posix'); path2-0.1.0/is-absolute.js000066400000000000000000000001761230044703200153120ustar00rootroot00000000000000'use strict'; module.exports = require('./is-windows') ? require('./windows/is-absolute') : require('./posix/is-absolute'); path2-0.1.0/is-windows.js000066400000000000000000000002551230044703200151640ustar00rootroot00000000000000'use strict'; module.exports = (function () { if (typeof process === 'undefined') return false; if (!process) return false; return (process.platform === 'win32'); }()); path2-0.1.0/join.js000066400000000000000000000001601230044703200140130ustar00rootroot00000000000000'use strict'; module.exports = require('./is-windows') ? require('./windows/join') : require('./posix/join'); path2-0.1.0/normalize.js000066400000000000000000000001721230044703200150570ustar00rootroot00000000000000'use strict'; module.exports = require('./is-windows') ? require('./windows/normalize') : require('./posix/normalize'); path2-0.1.0/package.json000066400000000000000000000006161230044703200150120ustar00rootroot00000000000000{ "name": "path2", "version": "0.1.0", "description": "Modular and extended version of `path` package", "keywords": [ "path", "node", "commonpath" ], "repository": { "type": "git", "url": "git://github.com/medikoo/path2.git" }, "scripts": { "test": "node ./node_modules/tad/bin/tad" }, "devDependencies": { "tad": "~0.1.20" }, "license": "MIT" } path2-0.1.0/posix/000077500000000000000000000000001230044703200136635ustar00rootroot00000000000000path2-0.1.0/posix/_cwd.js000066400000000000000000000004231230044703200151340ustar00rootroot00000000000000'use strict'; var isWindows = require('../is-windows'); module.exports = (function () { if (isWindows) return '/'; if (typeof process === 'undefined') return '/'; if (!process) return '/'; if (typeof process.cwd !== 'function') return '/'; return process.cwd(); }()); path2-0.1.0/posix/_split-path.js000066400000000000000000000002471230044703200164500ustar00rootroot00000000000000'use strict'; var re = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/; module.exports = function (filename) { return re.exec(filename).slice(1); }; path2-0.1.0/posix/basename.js000066400000000000000000000003531230044703200157750ustar00rootroot00000000000000'use strict'; var splitPath = require('./_split-path'); module.exports = function (path, ext) { var f = splitPath(path)[2]; if (ext && f.substr(-1 * ext.length) === ext) { f = f.substr(0, f.length - ext.length); } return f; }; path2-0.1.0/posix/common.js000066400000000000000000000020701230044703200155100ustar00rootroot00000000000000'use strict'; var dirname = require('./dirname') , resolve = require('./resolve') , normalize; normalize = function (path) { if (typeof path !== 'string') { throw new TypeError('Arguments to path.common must be strings'); } var isDir = (path[path.length - 1] === '/'); path = resolve(path); if (isDir) return path; return dirname(path); }; module.exports = function (path/*, ...pathn*/) { var i, l, pathLength, other, end, j, otherLength; path = normalize(path); if (path === '/') return '/'; l = arguments.length; pathLength = path.length; for (i = 1; i < l; ++i) { other = normalize(arguments[i]); end = 0; j = 0; otherLength = other.length; while (path[j] === other[j]) { if (path[j] === '/') end = j; ++j; if (pathLength === j) { if (otherLength === j) end = j; else if (other[j] === '/') end = j; break; } if (otherLength === j) { if (path[j] === '/') end = j; break; } } if (end <= 1) return '/'; if (end !== pathLength) { path = path.slice(0, end); pathLength = end; } } return path; }; path2-0.1.0/posix/delimiter.js000066400000000000000000000000451230044703200161760ustar00rootroot00000000000000'use strict'; module.exports = ':'; path2-0.1.0/posix/dirname.js000066400000000000000000000001311230044703200156330ustar00rootroot00000000000000'use strict'; module.exports = require('../_get-dirname-fn')(require('./_split-path')); path2-0.1.0/posix/extname.js000066400000000000000000000001311230044703200156550ustar00rootroot00000000000000'use strict'; module.exports = require('../_get-extname-fn')(require('./_split-path')); path2-0.1.0/posix/index.js000066400000000000000000000006501230044703200153310ustar00rootroot00000000000000'use strict'; module.exports = { basename: require('./basename'), delimiter: require('./delimiter'), dirname: require('./dirname'), extname: require('./extname'), isAbsolute: require('./is-absolute'), join: require('./join'), normalize: require('./normalize'), relative: require('./relative'), resolve: require('./resolve'), sep: require('./sep'), common: require('./common') }; path2-0.1.0/posix/is-absolute.js000066400000000000000000000001251230044703200164460ustar00rootroot00000000000000'use strict'; module.exports = function (path) { return path.charAt(0) === '/'; }; path2-0.1.0/posix/join.js000066400000000000000000000006471230044703200151670ustar00rootroot00000000000000'use strict'; var normalize = require('./normalize'); module.exports = function () { var path = '', i, segment; for (i = 0; i < arguments.length; i++) { segment = arguments[i]; if (typeof segment !== 'string') { throw new TypeError('Arguments to path.join must be strings'); } if (segment) { if (!path) { path += segment; } else { path += '/' + segment; } } } return normalize(path); }; path2-0.1.0/posix/normalize.js000066400000000000000000000011341230044703200162200ustar00rootroot00000000000000'use strict'; var isAbsolute = require('./is-absolute') , normalizeArray = require('../_normalize-array'); module.exports = function (path) { var isAbs = isAbsolute(path), trailingSlash = path[path.length - 1] === '/', segments = path.split('/'), nonEmptySegments = [], i; // Normalize the path for (i = 0; i < segments.length; i++) { if (segments[i]) { nonEmptySegments.push(segments[i]); } } path = normalizeArray(nonEmptySegments, !isAbs).join('/'); if (!path && !isAbs) { path = '.'; } if (path && trailingSlash) { path += '/'; } return (isAbs ? '/' : '') + path; }; path2-0.1.0/posix/relative.js000066400000000000000000000017341230044703200160410ustar00rootroot00000000000000'use strict'; var resolve = require('./resolve'); module.exports = function (from, to) { var trim, fromParts, toParts, length, samePartsLength, i, outputParts; from = resolve(from).substr(1); to = resolve(to).substr(1); trim = function (arr) { var start, end; for (start = 0; start < arr.length; start++) { if (arr[start] !== '') break; } for (end = arr.length - 1; end >= 0; end--) { if (arr[end] !== '') break; } if (start > end) return []; return arr.slice(start, end - start + 1); }; fromParts = trim(from.split('/')); toParts = trim(to.split('/')); length = Math.min(fromParts.length, toParts.length); samePartsLength = length; for (i = 0; i < length; i++) { if (fromParts[i] !== toParts[i]) { samePartsLength = i; break; } } outputParts = []; for (i = samePartsLength; i < fromParts.length; i++) { outputParts.push('..'); } outputParts = outputParts.concat(toParts.slice(samePartsLength)); return outputParts.join('/'); }; path2-0.1.0/posix/resolve.js000066400000000000000000000016521230044703200157040ustar00rootroot00000000000000'use strict'; var normalizeArray = require('../_normalize-array') , cwd = require('./_cwd'); module.exports = function () { var resolvedPath = '', resolvedAbsolute = false, i, path; for (i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { path = (i >= 0) ? arguments[i] : cwd; // Skip empty and invalid entries if (typeof path !== 'string') { throw new TypeError('Arguments to path.resolve must be strings'); } if (!path) continue; resolvedPath = path + '/' + resolvedPath; resolvedAbsolute = path.charAt(0) === '/'; } // At this point the path should be resolved to a full absolute path, but // handle relative paths to be safe (might happen when process.cwd() fails) // Normalize the path resolvedPath = normalizeArray(resolvedPath.split('/').filter(function (p) { return !!p; }), !resolvedAbsolute).join('/'); return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; }; path2-0.1.0/posix/sep.js000066400000000000000000000000451230044703200150070ustar00rootroot00000000000000'use strict'; module.exports = '/'; path2-0.1.0/relative.js000066400000000000000000000001701230044703200146700ustar00rootroot00000000000000'use strict'; module.exports = require('./is-windows') ? require('./windows/relative') : require('./posix/relative'); path2-0.1.0/resolve.js000066400000000000000000000001661230044703200145410ustar00rootroot00000000000000'use strict'; module.exports = require('./is-windows') ? require('./windows/resolve') : require('./posix/resolve'); path2-0.1.0/sep.js000066400000000000000000000001561230044703200136500ustar00rootroot00000000000000'use strict'; module.exports = require('./is-windows') ? require('./windows/sep') : require('./posix/sep'); path2-0.1.0/test/000077500000000000000000000000001230044703200135005ustar00rootroot00000000000000path2-0.1.0/test/_get-dirname-fn.js000066400000000000000000000001641230044703200167730ustar00rootroot00000000000000'use strict'; module.exports = function (t, a) { t = t(require('../posix/_split-path')); a(t('/a/b/'), '/a'); }; path2-0.1.0/test/_get-extname-fn.js000066400000000000000000000001711230044703200170130ustar00rootroot00000000000000'use strict'; module.exports = function (t, a) { t = t(require('../posix/_split-path')); a(t('/a/b/c.js'), '.js'); }; path2-0.1.0/test/_normalize-array.js000066400000000000000000000001401230044703200173040ustar00rootroot00000000000000'use strict'; module.exports = function (t, a) { a.deep(t(['raz', 'dwa', '..']), ['raz']); }; path2-0.1.0/test/basename.js000066400000000000000000000002051230044703200156060ustar00rootroot00000000000000'use strict'; module.exports = require('../is-windows') ? require('./windows/basename').tests : require('./posix/basename').tests; path2-0.1.0/test/common.js000066400000000000000000000002011230044703200153170ustar00rootroot00000000000000'use strict'; module.exports = require('../is-windows') ? require('./windows/common').tests : require('./posix/common').tests; path2-0.1.0/test/delimiter.js000066400000000000000000000002071230044703200160130ustar00rootroot00000000000000'use strict'; module.exports = require('../is-windows') ? require('./windows/delimiter').tests : require('./posix/delimiter').tests; path2-0.1.0/test/dirname.js000066400000000000000000000002031230044703200154500ustar00rootroot00000000000000'use strict'; module.exports = require('../is-windows') ? require('./windows/dirname').tests : require('./posix/dirname').tests; path2-0.1.0/test/extname.js000066400000000000000000000002031230044703200154720ustar00rootroot00000000000000'use strict'; module.exports = require('../is-windows') ? require('./windows/extname').tests : require('./posix/extname').tests; path2-0.1.0/test/index.js000066400000000000000000000003371230044703200151500ustar00rootroot00000000000000'use strict'; var indexTest = require('tad/lib/utils/index-test'); module.exports = indexTest(indexTest.readDir(__dirname + '/../')(function (o) { delete o.isWindows; delete o.posix; delete o.windows; return o; })); path2-0.1.0/test/is-absolute.js000066400000000000000000000002141230044703200162620ustar00rootroot00000000000000'use strict'; module.exports = require('../is-windows') ? require('./windows/is-absolute').tests : require('./posix/is-absolute').tests; path2-0.1.0/test/is-windows.js000066400000000000000000000001161230044703200161370ustar00rootroot00000000000000'use strict'; module.exports = function (t, a) { a(typeof t, 'boolean'); }; path2-0.1.0/test/join.js000066400000000000000000000001751230044703200150000ustar00rootroot00000000000000'use strict'; module.exports = require('../is-windows') ? require('./windows/join').tests : require('./posix/join').tests; path2-0.1.0/test/normalize.js000066400000000000000000000002071230044703200160350ustar00rootroot00000000000000'use strict'; module.exports = require('../is-windows') ? require('./windows/normalize').tests : require('./posix/normalize').tests; path2-0.1.0/test/posix/000077500000000000000000000000001230044703200146425ustar00rootroot00000000000000path2-0.1.0/test/posix/_cwd.js000066400000000000000000000001151230044703200161110ustar00rootroot00000000000000'use strict'; module.exports = function (t, a) { a(typeof t, 'string'); }; path2-0.1.0/test/posix/_split-path.js000066400000000000000000000001721230044703200174240ustar00rootroot00000000000000'use strict'; module.exports = function (t, a) { a.deep(t('/raz/dwa/trzy.js'), ['/', 'raz/dwa/', 'trzy.js', '.js']); }; path2-0.1.0/test/posix/basename.js000066400000000000000000000013771230044703200167630ustar00rootroot00000000000000'use strict'; var f = 'test-path.js' , controlCharFilename = 'Icon' + String.fromCharCode(13); module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { a(t(f), 'test-path.js'); a(t(f, '.js'), 'test-path'); a(t(''), ''); a(t('/dir/basename.ext'), 'basename.ext'); a(t('/basename.ext'), 'basename.ext'); a(t('basename.ext'), 'basename.ext'); a(t('basename.ext/'), 'basename.ext'); a(t('basename.ext//'), 'basename.ext'); a(t('\\dir\\basename.ext'), '\\dir\\basename.ext'); a(t('\\basename.ext'), '\\basename.ext'); a(t('basename.ext'), 'basename.ext'); a(t('basename.ext\\'), 'basename.ext\\'); a(t('basename.ext\\\\'), 'basename.ext\\\\'); a(t('/a/b/' + controlCharFilename), controlCharFilename); }; path2-0.1.0/test/posix/common.js000066400000000000000000000012221230044703200164650ustar00rootroot00000000000000'use strict'; var data = [[['/'], '/'], [['/raz/dwa/'], '/raz/dwa'], [['/raz/dwa'], '/raz'], [['/raz/dwa', '/trzy/cztery'], '/'], [['/raz/dwa', '/raz/trzy'], '/raz'], [['/raz/dwa', '/raz/dwa/trzy', '/raz/cztery'], '/raz'], [['/raz/dwa/piec', '/raz/dwa/trzy', '/raz/dwa/cztery'], '/raz/dwa'], [['/raz/dwa/piec', '/raz/dwa/trzy', '/raz/dwa/'], '/raz/dwa'], [['/raz/dwa/piec', '/raz/dwa/trzy', '/raz/dwa'], '/raz'], [['/raz/dwa/trzy', '/raz/dwatrzy'], '/raz']]; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { data.forEach(function (test, i) { a(t.apply(null, test[0]), test[1], i); }); }; path2-0.1.0/test/posix/delimiter.js000066400000000000000000000002061230044703200171540ustar00rootroot00000000000000'use strict'; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { a(t, ':'); }; path2-0.1.0/test/posix/dirname.js000066400000000000000000000004711230044703200166210ustar00rootroot00000000000000'use strict'; var f = '/foo/test/posix/test-path.js'; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { a(t(f).substr(-10), 'test/posix'); a(t('/a/b/'), '/a'); a(t('/a/b'), '/a'); a(t('/a'), '/'); a(t(''), '.'); a(t('/'), '/'); a(t('////'), '/'); }; path2-0.1.0/test/posix/extname.js000066400000000000000000000025601230044703200166440ustar00rootroot00000000000000'use strict'; var f = 'test-path.js'; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { a(t(f), '.js'); a(t(''), ''); a(t('/path/to/file'), ''); a(t('/path/to/file.ext'), '.ext'); a(t('/path.to/file.ext'), '.ext'); a(t('/path.to/file'), ''); a(t('/path.to/.file'), ''); a(t('/path.to/.file.ext'), '.ext'); a(t('/path/to/f.ext'), '.ext'); a(t('/path/to/..ext'), '.ext'); a(t('file'), ''); a(t('file.ext'), '.ext'); a(t('.file'), ''); a(t('.file.ext'), '.ext'); a(t('/file'), ''); a(t('/file.ext'), '.ext'); a(t('/.file'), ''); a(t('/.file.ext'), '.ext'); a(t('.path/file.ext'), '.ext'); a(t('file.ext.ext'), '.ext'); a(t('file.'), '.'); a(t('.'), ''); a(t('./'), ''); a(t('.file.ext'), '.ext'); a(t('.file'), ''); a(t('.file.'), '.'); a(t('.file..'), '.'); a(t('..'), ''); a(t('../'), ''); a(t('..file.ext'), '.ext'); a(t('..file'), '.file'); a(t('..file.'), '.'); a(t('..file..'), '.'); a(t('...'), '.'); a(t('...ext'), '.ext'); a(t('....'), '.'); a(t('file.ext/'), '.ext'); a(t('file.ext//'), '.ext'); a(t('file/'), ''); a(t('file//'), ''); a(t('file./'), '.'); a(t('file.//'), '.'); a(t('.\\'), ''); a(t('..\\'), '.\\'); a(t('file.ext\\'), '.ext\\'); a(t('file.ext\\\\'), '.ext\\\\'); a(t('file\\'), ''); a(t('file\\\\'), ''); a(t('file.\\'), '.\\'); a(t('file.\\\\'), '.\\\\'); }; path2-0.1.0/test/posix/is-absolute.js000066400000000000000000000003361230044703200174310ustar00rootroot00000000000000'use strict'; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { a(t('/home/foo'), true); a(t('/home/foo/..'), true); a(t('bar/'), false); a(t('./baz'), false); }; path2-0.1.0/test/posix/join.js000066400000000000000000000030211230044703200161330ustar00rootroot00000000000000'use strict'; module.exports = exports = function (t, a) { exports.tests(t, a); }; var data = exports.data = [[['.', 'x/b', '..', '/b/c.js'], 'x/b/c.js'], [['/.', 'x/b', '..', '/b/c.js'], '/x/b/c.js'], [['/foo', '../../../bar'], '/bar'], [['foo', '../../../bar'], '../../bar'], [['foo/', '../../../bar'], '../../bar'], [['foo/x', '../../../bar'], '../bar'], [['foo/x', './bar'], 'foo/x/bar'], [['foo/x/', './bar'], 'foo/x/bar'], [['foo/x/', '.', 'bar'], 'foo/x/bar'], [['./'], './'], [['.', './'], './'], [['.', '.', '.'], '.'], [['.', './', '.'], '.'], [['.', '/./', '.'], '.'], [['.', '/////./', '.'], '.'], [['.'], '.'], [['', '.'], '.'], [['', 'foo'], 'foo'], [['foo', '/bar'], 'foo/bar'], [['', '/foo'], '/foo'], [['', '', '/foo'], '/foo'], [['', '', 'foo'], 'foo'], [['foo', ''], 'foo'], [['foo/', ''], 'foo/'], [['foo', '', '/bar'], 'foo/bar'], [['./', '..', '/foo'], '../foo'], [['./', '..', '..', '/foo'], '../../foo'], [['.', '..', '..', '/foo'], '../../foo'], [['', '..', '..', '/foo'], '../../foo'], [['/'], '/'], [['/', '.'], '/'], [['/', '..'], '/'], [['/', '..', '..'], '/'], [[''], '.'], [['', ''], '.'], [[' /foo'], ' /foo'], [[' ', 'foo'], ' /foo'], [[' ', '.'], ' '], [[' ', '/'], ' /'], [[' ', ''], ' '], [['/', 'foo'], '/foo'], [['/', '/foo'], '/foo'], [['/', '//foo'], '/foo'], [['/', '', '/foo'], '/foo'], [['', '/', 'foo'], '/foo'], [['', '/', '/foo'], '/foo']]; exports.tests = function (t, a) { data.forEach(function (test, i) { a(t.apply(null, test[0]), test[1], i); }); }; path2-0.1.0/test/posix/normalize.js000066400000000000000000000004501230044703200171770ustar00rootroot00000000000000'use strict'; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { a(t('./fixtures///b/../b/c.js'), 'fixtures/b/c.js'); a(t('/foo/../../../bar'), '/bar'); a(t('a//b//../b'), 'a/b'); a(t('a//b//./c'), 'a/b/c'); a(t('a//b//.'), 'a/b'); }; path2-0.1.0/test/posix/relative.js000066400000000000000000000006361230044703200170200ustar00rootroot00000000000000'use strict'; var data = [['/var/lib', '/var', '..'], ['/var/lib', '/bin', '../../bin'], ['/var/lib', '/var/lib', ''], ['/var/lib', '/var/apache', '../apache'], ['/var/', '/var/lib', 'lib'], ['/', '/var/lib', 'var/lib']]; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { data.forEach(function (test, i) { a(t(test[0], test[1]), test[2], i); }); }; path2-0.1.0/test/posix/resolve.js000066400000000000000000000006701230044703200166620ustar00rootroot00000000000000'use strict'; var cwd = require('../../posix/_cwd') , data = [[['/var/lib', '../', 'file/'], '/var/file'], [['/var/lib', '/../', 'file/'], '/file'], [['a/b/c/', '../../..'], cwd], [['.'], cwd], [['/some/dir', '.', '/absolute/'], '/absolute']]; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { data.forEach(function (test, i) { a(t.apply(null, test[0]), test[1], i); }); }; path2-0.1.0/test/posix/sep.js000066400000000000000000000002061230044703200157650ustar00rootroot00000000000000'use strict'; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { a(t, '/'); }; path2-0.1.0/test/relative.js000066400000000000000000000002051230044703200156460ustar00rootroot00000000000000'use strict'; module.exports = require('../is-windows') ? require('./windows/relative').tests : require('./posix/relative').tests; path2-0.1.0/test/resolve.js000066400000000000000000000002031230044703200155100ustar00rootroot00000000000000'use strict'; module.exports = require('../is-windows') ? require('./windows/resolve').tests : require('./posix/resolve').tests; path2-0.1.0/test/sep.js000066400000000000000000000001731230044703200146260ustar00rootroot00000000000000'use strict'; module.exports = require('../is-windows') ? require('./windows/sep').tests : require('./posix/sep').tests; path2-0.1.0/test/windows/000077500000000000000000000000001230044703200151725ustar00rootroot00000000000000path2-0.1.0/test/windows/_cwd.js000066400000000000000000000001151230044703200164410ustar00rootroot00000000000000'use strict'; module.exports = function (t, a) { a(typeof t, 'string'); }; path2-0.1.0/test/windows/_make-long.js000066400000000000000000000010101230044703200175310ustar00rootroot00000000000000'use strict'; var file = 'C:\\raz\\dwa\\a.js'; module.exports = function (t, a) { a('\\\\?\\' + file, t(file)); a('\\\\?\\' + file, t('\\\\?\\' + file)); a('\\\\?\\UNC\\someserver\\someshare\\somefile', t('\\\\someserver\\someshare\\somefile')); a('\\\\?\\UNC\\someserver\\someshare\\somefile', t('\\\\?\\UNC\\someserver\\someshare\\somefile')); a('\\\\.\\pipe\\somepipe', t('\\\\.\\pipe\\somepipe')); a(t(null), null); a(t(100), 100); a(t(exports), exports); a(t(false), false); a(t(true), true); }; path2-0.1.0/test/windows/_normalize-unc-root.js000066400000000000000000000001431230044703200214310ustar00rootroot00000000000000'use strict'; module.exports = function (t, a) { a(t('/raz/dwa/trzy'), '\\\\raz\\dwa\\trzy'); }; path2-0.1.0/test/windows/_split-device-re.js000066400000000000000000000002461230044703200206650ustar00rootroot00000000000000'use strict'; module.exports = function (t, a) { a.deep('C:\\raz\\dwa\\trzy.js'.match(t).slice(), ['C:\\raz\\dwa\\trzy.js', 'C:', '\\', 'raz\\dwa\\trzy.js']); }; path2-0.1.0/test/windows/_split-path.js000066400000000000000000000002041230044703200177500ustar00rootroot00000000000000'use strict'; module.exports = function (t, a) { a.deep(t('C:\\raz\\dwa\\trzy.js'), ['C:\\', 'raz\\dwa\\', 'trzy.js', '.js']); }; path2-0.1.0/test/windows/basename.js000066400000000000000000000011711230044703200173030ustar00rootroot00000000000000'use strict'; var f = 'test-path.js'; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { a(t(f), 'test-path.js'); a(t(f, '.js'), 'test-path'); a(t(''), ''); a(t('/dir/basename.ext'), 'basename.ext'); a(t('/basename.ext'), 'basename.ext'); a(t('basename.ext'), 'basename.ext'); a(t('basename.ext/'), 'basename.ext'); a(t('basename.ext//'), 'basename.ext'); a(t('\\dir\\basename.ext'), 'basename.ext'); a(t('\\basename.ext'), 'basename.ext'); a(t('basename.ext'), 'basename.ext'); a(t('basename.ext\\'), 'basename.ext'); a(t('basename.ext\\\\'), 'basename.ext'); }; path2-0.1.0/test/windows/common.js000066400000000000000000000015701230044703200170230ustar00rootroot00000000000000'use strict'; var data = [[['C:\\'], 'C:\\'], [['d:\\'], 'd:\\'], [['c:\\', 'd:\\'], null], [['c:\\raz\\dwa\\'], 'c:\\raz\\dwa'], [['C:\\raZ\\dwa'], 'C:\\raZ'], [['c:\\raz\\dwa', 'c:\\trzy\\cztery'], 'c:\\'], [['c:\\raz\\dwa', 'c:\\raz\\trzy'], 'c:\\raz'], [['c:\\raZ\\dwa', 'c:\\rAz\\trzy'], 'c:\\raZ'], [['c:\\raz\\dwa', 'c:\\raz\\dwa\\trzy', 'c:\\raz\\cztery'], 'c:\\raz'], [['C:\\raz\\dwa\\piec', 'c:\\raz\\dwa\\trzy', 'c:\\raz\\dwa\\cztery'], 'C:\\raz\\dwa'], [['C:\\raz\\dwa\\piec', 'c:\\raz\\dwa\\trzy', 'c:\\raz\\dwa\\'], 'C:\\raz\\dwa'], [['c:\\raz\\dwa\\piec', 'c:\\raz\\dwa\\trzy', 'c:\\raz\\dwa'], 'c:\\raz'], [['c:\\raz\\dwa\\trzy', 'c:\\raz\\dwatrzy'], 'c:\\raz']]; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { data.forEach(function (test, i) { a(t.apply(null, test[0]), test[1], i); }); }; path2-0.1.0/test/windows/delimiter.js000066400000000000000000000002061230044703200175040ustar00rootroot00000000000000'use strict'; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { a(t, ';'); }; path2-0.1.0/test/windows/dirname.js000066400000000000000000000022371230044703200171530ustar00rootroot00000000000000'use strict'; var f = 'C:\\foo\\test\\posix\\test-path.js'; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { a(t(f).substr(-10), 'test\\posix'); a(t('/a/b/'), '/a'); a(t('/a/b'), '/a'); a(t('/a'), '/'); a(t(''), '.'); a(t('/'), '/'); a(t('////'), '/'); a(t('c:\\'), 'c:\\'); a(t('c:\\foo'), 'c:\\'); a(t('c:\\foo\\'), 'c:\\'); a(t('c:\\foo\\bar'), 'c:\\foo'); a(t('c:\\foo\\bar\\'), 'c:\\foo'); a(t('c:\\foo\\bar\\baz'), 'c:\\foo\\bar'); a(t('\\'), '\\'); a(t('\\foo'), '\\'); a(t('\\foo\\'), '\\'); a(t('\\foo\\bar'), '\\foo'); a(t('\\foo\\bar\\'), '\\foo'); a(t('\\foo\\bar\\baz'), '\\foo\\bar'); a(t('c:'), 'c:'); a(t('c:foo'), 'c:'); a(t('c:foo\\'), 'c:'); a(t('c:foo\\bar'), 'c:foo'); a(t('c:foo\\bar\\'), 'c:foo'); a(t('c:foo\\bar\\baz'), 'c:foo\\bar'); a(t('\\\\unc\\share'), '\\\\unc\\share'); a(t('\\\\unc\\share\\foo'), '\\\\unc\\share\\'); a(t('\\\\unc\\share\\foo\\'), '\\\\unc\\share\\'); a(t('\\\\unc\\share\\foo\\bar'), '\\\\unc\\share\\foo'); a(t('\\\\unc\\share\\foo\\bar\\'), '\\\\unc\\share\\foo'); a(t('\\\\unc\\share\\foo\\bar\\baz'), '\\\\unc\\share\\foo\\bar'); }; path2-0.1.0/test/windows/extname.js000066400000000000000000000025421230044703200171740ustar00rootroot00000000000000'use strict'; var f = 'test-path.js'; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { a(t(f), '.js'); a(t(''), ''); a(t('/path/to/file'), ''); a(t('/path/to/file.ext'), '.ext'); a(t('/path.to/file.ext'), '.ext'); a(t('/path.to/file'), ''); a(t('/path.to/.file'), ''); a(t('/path.to/.file.ext'), '.ext'); a(t('/path/to/f.ext'), '.ext'); a(t('/path/to/..ext'), '.ext'); a(t('file'), ''); a(t('file.ext'), '.ext'); a(t('.file'), ''); a(t('.file.ext'), '.ext'); a(t('/file'), ''); a(t('/file.ext'), '.ext'); a(t('/.file'), ''); a(t('/.file.ext'), '.ext'); a(t('.path/file.ext'), '.ext'); a(t('file.ext.ext'), '.ext'); a(t('file.'), '.'); a(t('.'), ''); a(t('./'), ''); a(t('.file.ext'), '.ext'); a(t('.file'), ''); a(t('.file.'), '.'); a(t('.file..'), '.'); a(t('..'), ''); a(t('../'), ''); a(t('..file.ext'), '.ext'); a(t('..file'), '.file'); a(t('..file.'), '.'); a(t('..file..'), '.'); a(t('...'), '.'); a(t('...ext'), '.ext'); a(t('....'), '.'); a(t('file.ext/'), '.ext'); a(t('file.ext//'), '.ext'); a(t('file/'), ''); a(t('file//'), ''); a(t('file./'), '.'); a(t('file.//'), '.'); a(t('.\\'), ''); a(t('..\\'), ''); a(t('file.ext\\'), '.ext'); a(t('file.ext\\\\'), '.ext'); a(t('file\\'), ''); a(t('file\\\\'), ''); a(t('file.\\'), '.'); a(t('file.\\\\'), '.'); }; path2-0.1.0/test/windows/index.js000066400000000000000000000002171230044703200166370ustar00rootroot00000000000000'use strict'; var indexTest = require('tad/lib/utils/index-test'); module.exports = indexTest(__dirname + '/../../windows', ['_makeLong']); path2-0.1.0/test/windows/is-absolute.js000066400000000000000000000005711230044703200177620ustar00rootroot00000000000000'use strict'; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { a(t('//server/file'), true); a(t('\\\\server\\file'), true); a(t('C:/Users/'), true); a(t('C:\\Users\\'), true); a(t('C:cwd/another'), false); a(t('C:cwd\\another'), false); a(t('directory/directory'), false); a(t('directory\\directory'), false); }; path2-0.1.0/test/windows/join.js000066400000000000000000000035701230044703200164740ustar00rootroot00000000000000'use strict'; module.exports = exports = function (t, a) { exports.tests(t, a); }; var data = exports.data = require('../posix/join').data.concat([ // UNC path expected [['//foo/bar'], '//foo/bar/'], [['\\/foo/bar'], '//foo/bar/'], [['\\\\foo/bar'], '//foo/bar/'], // UNC path expected - server and share separate [['//foo', 'bar'], '//foo/bar/'], [['//foo/', 'bar'], '//foo/bar/'], [['//foo', '/bar'], '//foo/bar/'], // UNC path expected - questionable [['//foo', '', 'bar'], '//foo/bar/'], [['//foo/', '', 'bar'], '//foo/bar/'], [['//foo/', '', '/bar'], '//foo/bar/'], // UNC path expected - even more questionable [['', '//foo', 'bar'], '//foo/bar/'], [['', '//foo/', 'bar'], '//foo/bar/'], [['', '//foo/', '/bar'], '//foo/bar/'], // No UNC path expected (no double slash in first component) [['\\', 'foo/bar'], '/foo/bar'], [['\\', '/foo/bar'], '/foo/bar'], [['', '/', '/foo/bar'], '/foo/bar'], // No UNC path expected (no non-slashes in first component - questionable) [['//', 'foo/bar'], '/foo/bar'], [['//', '/foo/bar'], '/foo/bar'], [['\\\\', '/', '/foo/bar'], '/foo/bar'], [['//'], '/'], // No UNC path expected (share name missing - questionable). [['//foo'], '/foo'], [['//foo/'], '/foo/'], [['//foo', '/'], '/foo/'], [['//foo', '', '/'], '/foo/'], // No UNC path expected (too many leading slashes - questionable) [['///foo/bar'], '/foo/bar'], [['////foo', 'bar'], '/foo/bar'], [['\\\\\\/foo/bar'], '/foo/bar'], // Drive-relative vs drive-absolute paths. This merely describes the // status quo, rather than being obviously right [['c:'], 'c:.'], [['c:.'], 'c:.'], [['c:', ''], 'c:.'], [['', 'c:'], 'c:.'], [['c:.', '/'], 'c:./'], [['c:.', 'file'], 'c:file'], [['c:', '/'], 'c:/'], [['c:', 'file'], 'c:/file'] ]); exports.tests = function (t, a) { data.forEach(function (test, i) { a(t.apply(null, test[0]), test[1].replace(/\//g, '\\'), i); }); }; path2-0.1.0/test/windows/normalize.js000066400000000000000000000005731230044703200175350ustar00rootroot00000000000000'use strict'; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { a(t('./fixtures///b/../b/c.js'), 'fixtures\\b\\c.js'); a(t('/foo/../../../bar'), '\\bar'); a(t('a//b//../b'), 'a\\b'); a(t('a//b//./c'), 'a\\b\\c'); a(t('a//b//.'), 'a\\b'); a(t('//server/share/dir/file.ext'), '\\\\server\\share\\dir\\file.ext'); }; path2-0.1.0/test/windows/relative.js000066400000000000000000000010361230044703200173430ustar00rootroot00000000000000'use strict'; var data = [['c:/blah\\blah', 'd:/games', 'd:\\games'], ['c:/aaaa/bbbb', 'c:/aaaa', '..'], ['c:/aaaa/bbbb', 'c:/cccc', '..\\..\\cccc'], ['c:/aaaa/bbbb', 'c:/aaaa/bbbb', ''], ['c:/aaaa/bbbb', 'c:/aaaa/cccc', '..\\cccc'], ['c:/aaaa/', 'c:/aaaa/cccc', 'cccc'], ['c:/', 'c:\\aaaa\\bbbb', 'aaaa\\bbbb'], ['c:/aaaa/bbbb', 'd:\\', 'd:\\']]; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { data.forEach(function (test, i) { a(t(test[0], test[1]), test[2], i); }); }; path2-0.1.0/test/windows/resolve.js000066400000000000000000000014331230044703200172100ustar00rootroot00000000000000'use strict'; var cwd = require('../../windows/_cwd') , data = [[['c:/blah\\blah', 'd:/games', 'c:../a'], 'c:\\blah\\a'], [['c:/ignore', 'd:\\a/b\\c/d', '\\e.exe'], 'd:\\e.exe'], [['c:/ignore', 'c:/some/file'], 'c:\\some\\file'], [['d:/ignore', 'd:some/dir//'], 'd:\\ignore\\some\\dir'], [['.'], cwd], [['//server/share', '..', 'relative\\'], '\\\\server\\share\\relative'], [['c:/', '//'], 'c:\\'], [['c:/', '//dir'], 'c:\\dir'], [['c:/', '//server/share'], '\\\\server\\share\\'], [['c:/', '//server//share'], '\\\\server\\share\\'], [['c:/', '///some//dir'], 'c:\\some\\dir'] ]; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { data.forEach(function (test, i) { a(t.apply(null, test[0]), test[1], i); }); }; path2-0.1.0/test/windows/sep.js000066400000000000000000000002071230044703200163160ustar00rootroot00000000000000'use strict'; module.exports = exports = function (t, a) { exports.tests(t, a); }; exports.tests = function (t, a) { a(t, '\\'); }; path2-0.1.0/windows/000077500000000000000000000000001230044703200142135ustar00rootroot00000000000000path2-0.1.0/windows/_cwd.js000066400000000000000000000004401230044703200154630ustar00rootroot00000000000000'use strict'; var isWindows = require('../is-windows'); module.exports = (function () { if (typeof process === 'undefined') return 'C:\\'; if (!process) return 'C:\\'; if (typeof process.cwd !== 'function') return 'C:\\'; if (!isWindows) return 'C:\\'; return process.cwd(); }()); path2-0.1.0/windows/_make-long.js000066400000000000000000000011431230044703200165610ustar00rootroot00000000000000'use strict'; var resolve = require('./resolve'); module.exports = function (path) { // Note: this will *probably* throw somewhere. if (typeof path !== 'string') return path; if (!path) { return ''; } var resolvedPath = resolve(path); if (/^[a-zA-Z]\:\\/.test(resolvedPath)) { // path is local filesystem path, which needs to be converted // to long UNC path. return '\\\\?\\' + resolvedPath; } if (/^\\\\[^?.]/.test(resolvedPath)) { // path is network UNC path, which needs to be converted // to long UNC path. return '\\\\?\\UNC\\' + resolvedPath.substring(2); } return path; }; path2-0.1.0/windows/_normalize-unc-root.js000066400000000000000000000002021230044703200204460ustar00rootroot00000000000000'use strict'; module.exports = function (device) { return '\\\\' + device.replace(/^[\\\/]+/, '').replace(/[\\\/]+/g, '\\'); }; path2-0.1.0/windows/_split-device-re.js000066400000000000000000000001471230044703200177060ustar00rootroot00000000000000'use strict'; module.exports = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/; path2-0.1.0/windows/_split-path.js000066400000000000000000000010361230044703200167750ustar00rootroot00000000000000'use strict'; var splitDeviceRe = require('./_split-device-re') , splitTailRe = /^([\s\S]*?)((?:\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))(?:[\\\/]*)$/; module.exports = function (filename) { // Separate device+slash from tail var result = splitDeviceRe.exec(filename) , device = (result[1] || '') + (result[2] || ''), tail = result[3] || '' // Split the tail into dir, basename and extension , result2 = splitTailRe.exec(tail), dir = result2[1], basename = result2[2] , ext = result2[3]; return [device, dir, basename, ext]; }; path2-0.1.0/windows/basename.js000066400000000000000000000004071230044703200163250ustar00rootroot00000000000000'use strict'; var splitPath = require('./_split-path'); module.exports = function (path, ext) { var f = splitPath(path)[2]; if (ext && f.substr(-1 * ext.length).toLowerCase() === ext.toLowerCase()) { f = f.substr(0, f.length - ext.length); } return f; }; path2-0.1.0/windows/common.js000066400000000000000000000022011230044703200160340ustar00rootroot00000000000000'use strict'; var dirname = require('./dirname') , resolve = require('./resolve') , normalize; normalize = function (path) { if (typeof path !== 'string') { throw new TypeError('Arguments to path.common must be strings'); } var isDir = (path[path.length - 1] === '\\'); path = resolve(path); if (isDir) return path; return dirname(path); }; module.exports = function (path/*, ...pathn*/) { var i, l, pathLength, other, end, j, otherLength; path = normalize(path); l = arguments.length; pathLength = path.length; for (i = 1; i < l; ++i) { other = normalize(arguments[i]).toLowerCase(); end = 0; j = 0; otherLength = other.length; while (path[j].toLowerCase() === other[j]) { if (path[j] === '\\') end = j; ++j; if (pathLength === j) { if (otherLength === j) end = j; else if (other[j] === '\\') end = j; break; } if (otherLength === j) { if (path[j] === '\\') end = j; break; } } if (!end) return null; if (end !== pathLength) { path = path.slice(0, end); if (path[path.length - 1] === ':') { path += '\\'; ++end; } pathLength = end; } } return path; }; path2-0.1.0/windows/delimiter.js000066400000000000000000000000451230044703200165260ustar00rootroot00000000000000'use strict'; module.exports = ';'; path2-0.1.0/windows/dirname.js000066400000000000000000000001311230044703200161630ustar00rootroot00000000000000'use strict'; module.exports = require('../_get-dirname-fn')(require('./_split-path')); path2-0.1.0/windows/extname.js000066400000000000000000000001311230044703200162050ustar00rootroot00000000000000'use strict'; module.exports = require('../_get-extname-fn')(require('./_split-path')); path2-0.1.0/windows/index.js000066400000000000000000000007161230044703200156640ustar00rootroot00000000000000'use strict'; module.exports = { basename: require('./basename'), delimiter: require('./delimiter'), dirname: require('./dirname'), extname: require('./extname'), isAbsolute: require('./is-absolute'), join: require('./join'), normalize: require('./normalize'), relative: require('./relative'), resolve: require('./resolve'), sep: require('./sep'), _makeLong: require('./_make-long'), common: require('./common') }; path2-0.1.0/windows/is-absolute.js000066400000000000000000000004451230044703200170030ustar00rootroot00000000000000'use strict'; var splitDeviceRe = require('./_split-device-re'); module.exports = function (path) { var result = splitDeviceRe.exec(path), device = result[1] || '' , isUnc = device && device.charAt(1) !== ':'; // UNC paths are always absolute return !!result[2] || isUnc || false; }; path2-0.1.0/windows/join.js000066400000000000000000000022221230044703200155060ustar00rootroot00000000000000'use strict'; var normalize = require('./normalize'); module.exports = function () { var paths, joined, f; f = function (p) { if (typeof p !== 'string') { throw new TypeError('Arguments to path.join must be strings'); } return p; }; paths = Array.prototype.filter.call(arguments, f); joined = paths.join('\\'); // Make sure that the joined path doesn't start with two slashes, because // normalize() will mistake it for an UNC path then. // // This step is skipped when it is very clear that the user actually // intended to point at an UNC path. This is assumed when the first // non-empty string arguments starts with exactly two slashes followed by // at least one more non-slash character. // // Note that for normalize() to treat a path as an UNC path it needs to // have at least 2 components, so we don't filter for that here. // This means that the user can use join to construct UNC paths from // a server name and a share name; for example: // path.join('//server', 'share') -> '\\\\server\\share\') if (!/^[\\\/]{2}[^\\\/]/.test(paths[0])) { joined = joined.replace(/^[\\\/]{2,}/, '\\'); } return normalize(joined); }; path2-0.1.0/windows/normalize.js000066400000000000000000000021151230044703200165500ustar00rootroot00000000000000'use strict'; var isAbsolute = require('./is-absolute') , normalizeUNCRoot = require('./_normalize-unc-root') , splitDeviceRe = require('./_split-device-re') , normalizeArray = require('../_normalize-array'); module.exports = function (path) { var result = splitDeviceRe.exec(path), device = result[1] || '' , isUnc = device && device.charAt(1) !== ':', isAbs = isAbsolute(path) , tail = result[3], trailingSlash = /[\\\/]$/.test(tail); // If device is a drive letter, we'll normalize to lower case. if (device && device.charAt(1) === ':') { device = device[0].toLowerCase() + device.substr(1); } // Normalize the tail path tail = normalizeArray(tail.split(/[\\\/]+/).filter(function (p) { return !!p; }), !isAbs).join('\\'); if (!tail && !isAbs) { tail = '.'; } if (tail && trailingSlash) { tail += '\\'; } // Convert slashes to backslashes when `device` points to an UNC root. // Also squash multiple slashes into a single one where appropriate. if (isUnc) { device = normalizeUNCRoot(device); } return device + (isAbs ? '\\' : '') + tail; }; path2-0.1.0/windows/relative.js000066400000000000000000000023251230044703200163660ustar00rootroot00000000000000'use strict'; var resolve = require('./resolve'); module.exports = function (from, to) { var lowerFrom, lowerTo, trim, toParts, lowerFromParts, lowerToParts, length , samePartsLength, i, outputParts; from = resolve(from); to = resolve(to); // windows is not case sensitive lowerFrom = from.toLowerCase(); lowerTo = to.toLowerCase(); trim = function (arr) { var start, end; for (start = 0; start < arr.length; start++) { if (arr[start] !== '') break; } for (end = arr.length - 1; end >= 0; end--) { if (arr[end] !== '') break; } if (start > end) return []; return arr.slice(start, end - start + 1); }; toParts = trim(to.split('\\')); lowerFromParts = trim(lowerFrom.split('\\')); lowerToParts = trim(lowerTo.split('\\')); length = Math.min(lowerFromParts.length, lowerToParts.length); samePartsLength = length; for (i = 0; i < length; i++) { if (lowerFromParts[i] !== lowerToParts[i]) { samePartsLength = i; break; } } if (samePartsLength === 0) { return to; } outputParts = []; for (i = samePartsLength; i < lowerFromParts.length; i++) { outputParts.push('..'); } outputParts = outputParts.concat(toParts.slice(samePartsLength)); return outputParts.join('\\'); }; path2-0.1.0/windows/resolve.js000066400000000000000000000046161230044703200162370ustar00rootroot00000000000000'use strict'; var isAbsolute = require('./is-absolute') , normalizeUNCRoot = require('./_normalize-unc-root') , splitDeviceRe = require('./_split-device-re') , cwd = require('./_cwd') , normalizeArray = require('../_normalize-array'); module.exports = function () { var resolvedDevice = '', resolvedTail = '', resolvedAbsolute = false, i, path , result, device, isUnc, isAbs, tail; for (i = arguments.length - 1; i >= -1; i--) { if (i >= 0) { path = arguments[i]; } else if (!resolvedDevice) { path = cwd; } else { // Windows has the concept of drive-specific current working // directories. If we've resolved a drive letter but not yet an // absolute path, get cwd for that drive. We're sure the device is not // an unc path at this points, because unc paths are always absolute. path = process.env['=' + resolvedDevice]; // Verify that a drive-local cwd was found and that it actually points // to our drive. If not, default to the drive's root. if (!path || (path.substr(0, 3).toLowerCase() !== resolvedDevice.toLowerCase() + '\\')) { path = resolvedDevice + '\\'; } } // Skip empty and invalid entries path = String(path); if (!path) continue; result = splitDeviceRe.exec(path); device = result[1] || ''; isUnc = device && device.charAt(1) !== ':'; isAbs = isAbsolute(path); tail = result[3]; if (device && resolvedDevice && (device.toLowerCase() !== resolvedDevice.toLowerCase())) { // This path points to another device so it is not applicable continue; } if (!resolvedDevice) { resolvedDevice = device; } if (!resolvedAbsolute) { resolvedTail = tail + '\\' + resolvedTail; resolvedAbsolute = isAbs; } if (resolvedDevice && resolvedAbsolute) { break; } } // Convert slashes to backslashes when `resolvedDevice` points to an UNC // root. Also squash multiple slashes into a single one where appropriate. if (isUnc) { resolvedDevice = normalizeUNCRoot(resolvedDevice); } // At this point the path should be resolved to a full absolute path, // but handle relative paths to be safe (might happen when process.cwd() // fails) // Normalize the tail path function f(p) { return !!p; } resolvedTail = normalizeArray(resolvedTail.split(/[\\\/]+/).filter(f), !resolvedAbsolute).join('\\'); return (resolvedDevice + (resolvedAbsolute ? '\\' : '') + resolvedTail) || '.'; }; path2-0.1.0/windows/sep.js000066400000000000000000000000461230044703200153400ustar00rootroot00000000000000'use strict'; module.exports = '\\';