Comparing version 1.0.1 to 1.0.2
34
index.js
@@ -5,16 +5,9 @@ 'use strict' | ||
const isSubdirOnNormalized = isWindows() | ||
? isSubdirOnNormalizedWin | ||
: isSubdirOnNormalizedNonWin | ||
module.exports = isWindows() | ||
? isSubdirOnWin | ||
: isSubdirOnNonWin | ||
module.exports = function isSubdir(parent, dir) { | ||
return isSubdirOnNormalized( | ||
path.resolve(parent), | ||
path.resolve(dir) | ||
) | ||
} | ||
function isSubdirOnNormalizedWin (parent, dir) { | ||
const parentParts = parent.split(':') | ||
const dirParts = dir.split(':') | ||
function isSubdirOnWin (parent, dir) { | ||
const parentParts = winResolve(parent).split(':') | ||
const dirParts = winResolve(dir).split(':') | ||
return parentParts[0].toLowerCase() === dirParts[0].toLowerCase() && | ||
@@ -24,4 +17,15 @@ dirParts[1].startsWith(parentParts[1]) | ||
function isSubdirOnNormalizedNonWin (parent, dir) { | ||
return dir.startsWith(parent) | ||
// On Windows path.resolve('C:') returns C:\Users\ | ||
// This function resolves C: to C: | ||
function winResolve (p) { | ||
if (p.endsWith(':')) { | ||
return p | ||
} | ||
return path.resolve(p) | ||
} | ||
function isSubdirOnNonWin (parent, dir) { | ||
const rParent = path.resolve(parent) | ||
const rDir = path.resolve(dir) | ||
return rDir.startsWith(rParent) | ||
} |
{ | ||
"name": "is-subdir", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Return whether a directory is a subdirectory of another directory", | ||
@@ -13,2 +13,5 @@ "main": "index.js", | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"repository": { | ||
@@ -15,0 +18,0 @@ "type": "git", |
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
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
3841
25