├── .gitignore ├── LICENSE ├── README.md ├── index.js ├── package.json └── test └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | 10 | pids 11 | logs 12 | results 13 | 14 | npm-debug.log 15 | node_modules 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 filearts 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | node-absolute-path 2 | ================== 3 | 4 | Node.js 0.11.x path.isAbsolute as an installable module 5 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var currentPlatform = process !== void 0 ? process.platform : ''; 2 | 3 | function isAbsolute (path) { 4 | if (currentPlatform === 'win32') { 5 | // Regex to split a windows path into three parts: [*, device, slash, 6 | // tail] windows-only 7 | var splitDeviceRe = 8 | /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/; 9 | 10 | var result = splitDeviceRe.exec(path), 11 | device = result[1] || '', 12 | isUnc = device && device.charAt(1) !== ':'; 13 | // UNC paths are always absolute 14 | return !!result[2] || isUnc; 15 | } else { 16 | return path.charAt(0) === '/'; 17 | } 18 | } 19 | 20 | module.exports = isAbsolute; 21 | 22 | isAbsolute.setPlatform = function (platform) { 23 | currentPlatform = platform; 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "absolute-path", 3 | "version": "0.0.0", 4 | "description": "Node.js 0.11.x path.isAbsolute as a separate module", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "node test/index.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/filearts/node-absolute-path" 12 | }, 13 | "keywords": [ 14 | "path", 15 | "absolute", 16 | "isabsolute", 17 | "windows" 18 | ], 19 | "author": "Geoff Goodman", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/filearts/node-absolute-path/issues" 23 | }, 24 | "homepage": "https://github.com/filearts/node-absolute-path" 25 | } 26 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var isAbsolute = require('../'); 3 | 4 | isAbsolute.setPlatform('win32'); 5 | 6 | assert.equal(isAbsolute('//server/file'), true); 7 | assert.equal(isAbsolute('\\\\server\\file'), true); 8 | assert.equal(isAbsolute('C:/Users/'), true); 9 | assert.equal(isAbsolute('C:\\Users\\'), true); 10 | assert.equal(isAbsolute('C:cwd/another'), false); 11 | assert.equal(isAbsolute('C:cwd\\another'), false); 12 | assert.equal(isAbsolute('directory/directory'), false); 13 | assert.equal(isAbsolute('directory\\directory'), false); 14 | 15 | isAbsolute.setPlatform(''); 16 | 17 | assert.equal(isAbsolute('/home/foo'), true); 18 | assert.equal(isAbsolute('/home/foo/..'), true); 19 | assert.equal(isAbsolute('bar/'), false); 20 | assert.equal(isAbsolute('./baz'), false); --------------------------------------------------------------------------------