Comparing version 2.0.1 to 2.1.0
168
index.js
const os = require('bare-os') | ||
const posix = require('./lib/posix') | ||
const win32 = require('./lib/win32') | ||
const posix = makePath(false) | ||
const win32 = makePath(true) | ||
posix.win32 = win32.win32 = win32 | ||
posix.posix = win32.posix = posix | ||
module.exports = os.platform() === 'win32' ? win32 : posix | ||
function makePath (windows) { | ||
const path = {} | ||
const sep = path.sep = windows ? '\\' : '/' | ||
path.isAbsolute = windows | ||
? function isAbsolute (p) { | ||
if (p.length === 0) return false | ||
return (p[0] === '\\' || p[0] === '/') || | ||
(p.length === 2 && p[1] === ':') || | ||
(p.length > 2 && p[1] === ':' && (p[2] === '\\' || p[2] === '/')) | ||
} | ||
: function isAbsolute (p) { | ||
return p.length > 0 && p[0] === '/' | ||
} | ||
path.root = windows | ||
? function root (p) { | ||
if (p.length === 0) return '' | ||
return (p[0] === '\\' || p[0] === '/') | ||
? p[0] | ||
: (p.length === 2 && p[1] === ':') | ||
? p | ||
: (p.length > 2 && p[1] === ':' && (p[2] === '\\' || p[2] === '/')) | ||
? p.slice(0, 3) | ||
: '' | ||
} | ||
: function root (p) { | ||
return path.isAbsolute(p) ? '/' : '' | ||
} | ||
path.toNamespacedPath = windows | ||
? function toNamespacedPath (p) { | ||
if (p.length === 0) return '' | ||
const r = path.resolve(p) | ||
if (r.length <= 2) return p | ||
if (r[0] === '\\') { | ||
if (r[1] === '\\') { | ||
if (r[2] !== '?' && r[2] !== '.') { | ||
return '\\\\?\\UNC\\' + r.slice(2) | ||
} | ||
} | ||
} else if (r[1] === ':' && (r[2] === '\\' || r[2] === '/')) { | ||
return '\\\\?\\' + r | ||
} | ||
return p | ||
} | ||
: function toNamespacedPath (p) { | ||
return p | ||
} | ||
path.basename = function basename (p) { | ||
let end = p.length - 1 | ||
while (end > 0 && p[end] === sep) end-- | ||
if (end <= 0) return '' | ||
return p.slice(p.lastIndexOf(sep, end) + 1, end + 1) | ||
} | ||
path.dirname = function dirname (p) { | ||
let end = p.length - 1 | ||
while (end > 0 && p[end] === sep) end-- | ||
if (end === 0) end = 1 | ||
if (end < 0) return '.' | ||
let start = p.lastIndexOf(sep, end) | ||
if (start === 0) start = 1 | ||
if (start === -1) return '.' | ||
return p.slice(0, start) | ||
} | ||
path.extname = windows | ||
? function extname (p) { | ||
const i = p.lastIndexOf('.') | ||
if (i === -1) return '' | ||
const e = p.slice(i) | ||
if (e.includes('/') || e.includes('\\')) return '' | ||
return e | ||
} | ||
: function extname (p) { | ||
const i = p.lastIndexOf('.') | ||
if (i === -1) return '' | ||
const e = p.slice(i) | ||
if (e.includes('/')) return '' | ||
return e | ||
} | ||
path.resolve = function resolve (...args) { | ||
let resolved = '' | ||
for (let i = args.length - 1; i >= -1; i--) { | ||
const part = i === -1 ? os.cwd() : args[i] | ||
if (part.length === 0) continue | ||
resolved = path.join(part, resolved) | ||
if (path.isAbsolute(resolved)) break | ||
} | ||
return resolved | ||
} | ||
path.join = function join (p, ...parts) { | ||
for (const part of parts) { | ||
if (part.length === 0) continue | ||
p += sep + part | ||
} | ||
return path.normalize(p) | ||
} | ||
path.normalize = function normalize (p) { | ||
if (windows === true) { | ||
let i = -1 | ||
while ((i = p.indexOf('/', i + 1)) !== -1) p = p.slice(0, i) + sep + p.slice(i + 1) | ||
} | ||
const root = path.root(p) | ||
const isAbsolute = root !== '' | ||
const hasTrailingSep = p[p.length - 1] === sep | ||
let i = root.length | ||
let out = '' | ||
while (i < p.length) { | ||
let j = p.indexOf(sep, i) | ||
if (j === -1) j = p.length | ||
const part = p.slice(i, j) | ||
i = j + 1 | ||
if (part === '') { | ||
continue | ||
} | ||
if (part === '.') { | ||
continue | ||
} | ||
if (part === '..') { | ||
const l = out.lastIndexOf(sep) | ||
if (l === -1 || out.slice(l + 1) === '..') { | ||
if (isAbsolute) out = '' | ||
else out += out ? sep + '..' : '..' | ||
} else { | ||
out = out.slice(0, l) | ||
} | ||
continue | ||
} | ||
out += out ? sep + part : part | ||
} | ||
if (root) out = root + out | ||
if (hasTrailingSep) out += sep | ||
return out || '.' | ||
} | ||
return path | ||
} |
{ | ||
"name": "bare-path", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Path manipulation library for JavaScript", | ||
"main": "index.js", | ||
"files": [ | ||
"index.js" | ||
"index.js", | ||
"lib", | ||
"NOTICE" | ||
], | ||
@@ -23,3 +25,3 @@ "scripts": { | ||
"dependencies": { | ||
"bare-os": "^2.0.0" | ||
"bare-os": "^2.1.0" | ||
}, | ||
@@ -26,0 +28,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35132
9
736
1
80
1
Updatedbare-os@^2.1.0