@stryke/path
Version:
A package containing various utilities that expand the functionality of NodeJs's built-in `path` module
30 lines (29 loc) • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.resolveParentPath = exports.getParentPath = void 0;
var _isFile = require("./is-file.cjs");
var _joinPaths = require("./join-paths.cjs");
const resolveParentPath = (r, i = 1) => {
let t = r.replaceAll(/\/+$/g, "");
for (let n = 0; n < i; n++) t = (0, _joinPaths.joinPaths)(t, "..");
return t;
},
getParentPath = (r, i, t) => {
const n = t?.ignoreCase ?? !0,
f = t?.skipCwd ?? !1,
o = t?.targetType ?? "both";
let e = i;
f && (e = resolveParentPath(i));
let l = Array.isArray(r) ? r : [r];
for (n && (l = l.map(a => a.toLowerCase()));;) {
const a = l.find(p => (0, _isFile.isFile)((0, _joinPaths.joinPaths)(e, p)) && (o === "file" || o === "both") || (0, _isFile.isDirectory)((0, _joinPaths.joinPaths)(e, p)) && (o === "directory" || o === "both"));
if (a) return (0, _joinPaths.joinPaths)(e, a);
const g = resolveParentPath(e);
if (g === e) return;
e = g;
}
};
exports.getParentPath = getParentPath;
exports.resolveParentPath = resolveParentPath;