@stryke/path 0.12.5 â 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -14
- package/dist/correct-path.cjs +8 -7
- package/dist/correct-path.mjs +1 -1
- package/dist/cwd.cjs +9 -0
- package/dist/cwd.d.ts +9 -0
- package/dist/cwd.mjs +1 -0
- package/dist/delimiter.cjs +6 -6
- package/dist/delimiter.d.ts +12 -2
- package/dist/delimiter.mjs +1 -1
- package/dist/file-path-fns.cjs +59 -36
- package/dist/file-path-fns.d.ts +13 -1
- package/dist/file-path-fns.mjs +1 -1
- package/dist/get-parent-path.cjs +14 -15
- package/dist/get-parent-path.d.ts +1 -1
- package/dist/get-parent-path.mjs +1 -1
- package/dist/index.cjs +8 -41
- package/dist/index.d.ts +1 -4
- package/dist/index.mjs +1 -1
- package/dist/is-root-dir.cjs +4 -3
- package/dist/is-root-dir.d.ts +1 -1
- package/dist/is-root-dir.mjs +1 -1
- package/dist/is-type.cjs +23 -0
- package/dist/is-type.d.ts +34 -0
- package/dist/is-type.mjs +1 -0
- package/dist/join-paths.cjs +44 -50
- package/dist/join-paths.d.ts +1 -2
- package/dist/join-paths.mjs +1 -1
- package/dist/regex.cjs +3 -2
- package/dist/regex.d.ts +1 -0
- package/dist/regex.mjs +1 -1
- package/dist/replace.cjs +2 -1
- package/dist/replace.mjs +1 -1
- package/package.json +23 -60
- package/dist/exists.cjs +0 -12
- package/dist/exists.d.ts +0 -14
- package/dist/exists.mjs +0 -1
- package/dist/get-workspace-root.cjs +0 -38
- package/dist/get-workspace-root.d.ts +0 -30
- package/dist/get-workspace-root.mjs +0 -1
- package/dist/is-file.cjs +0 -39
- package/dist/is-file.d.ts +0 -46
- package/dist/is-file.mjs +0 -1
- package/dist/resolve.cjs +0 -59
- package/dist/resolve.d.ts +0 -71
- package/dist/resolve.mjs +0 -1
package/README.md
CHANGED
|
@@ -42,26 +42,29 @@ This package is part of Storm Software's **đŠī¸ Stryke** monorepo. Stryke pac
|
|
|
42
42
|
# Stryke - Path Helpers
|
|
43
43
|
|
|
44
44
|
A package containing various utilities that expand the functionality of NodeJs's
|
|
45
|
-
built-in \`path\` module
|
|
45
|
+
built-in \`path\` module; however, it is platform neutral and can be used in both
|
|
46
|
+
NodeJs and browser environments.
|
|
46
47
|
|
|
47
48
|
<!-- START doctoc -->
|
|
48
49
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
49
50
|
|
|
50
51
|
## Table of Contents
|
|
51
52
|
|
|
52
|
-
- [
|
|
53
|
-
- [
|
|
54
|
-
- [
|
|
55
|
-
- [
|
|
56
|
-
- [
|
|
57
|
-
|
|
58
|
-
- [
|
|
59
|
-
- [
|
|
60
|
-
- [
|
|
61
|
-
- [
|
|
62
|
-
- [
|
|
63
|
-
- [
|
|
64
|
-
- [
|
|
53
|
+
- [Stryke - Path Helpers](#stryke---path-helpers)
|
|
54
|
+
- [Table of Contents](#table-of-contents)
|
|
55
|
+
- [Installing](#installing)
|
|
56
|
+
- [Reduced Package Size](#reduced-package-size)
|
|
57
|
+
- [Development](#development)
|
|
58
|
+
- [Building](#building)
|
|
59
|
+
- [Running unit tests](#running-unit-tests)
|
|
60
|
+
- [Linting](#linting)
|
|
61
|
+
- [Storm Workspaces](#storm-workspaces)
|
|
62
|
+
- [Roadmap](#roadmap)
|
|
63
|
+
- [Support](#support)
|
|
64
|
+
- [License](#license)
|
|
65
|
+
- [Changelog](#changelog)
|
|
66
|
+
- [Contributing](#contributing)
|
|
67
|
+
- [Contributors](#contributors)
|
|
65
68
|
|
|
66
69
|
<!-- END doctoc -->
|
|
67
70
|
|
package/dist/correct-path.cjs
CHANGED
|
@@ -8,7 +8,8 @@ exports.normalizeString = normalizeString;
|
|
|
8
8
|
exports.normalizeWindowsPath = normalizeWindowsPath;
|
|
9
9
|
exports.toAbsolutePath = toAbsolutePath;
|
|
10
10
|
exports.toRelativePath = toRelativePath;
|
|
11
|
-
var
|
|
11
|
+
var _cwd = require("./cwd.cjs");
|
|
12
|
+
var _isType = require("./is-type.cjs");
|
|
12
13
|
var _joinPaths = require("./join-paths.cjs");
|
|
13
14
|
var _regex = require("./regex.cjs");
|
|
14
15
|
var _slash = require("./slash.cjs");
|
|
@@ -19,7 +20,7 @@ function correctPath(e) {
|
|
|
19
20
|
if (!e || e.length === 0) return ".";
|
|
20
21
|
e = normalizeWindowsPath(e);
|
|
21
22
|
const n = e.match(_regex.UNC_REGEX),
|
|
22
|
-
r = (0,
|
|
23
|
+
r = (0, _isType.isAbsolutePath)(e),
|
|
23
24
|
i = e.endsWith("/");
|
|
24
25
|
return e = normalizeString(e, !r), e.length === 0 ? r ? "/" : i ? "./" : "." : (i && (e += "/"), _regex.DRIVE_LETTER_REGEX.test(e) && (e += "/"), n ? r ? `//${e}` : `//./${e}` : !e.startsWith("/") && r && !_regex.DRIVE_LETTER_REGEX.test(e) ? `/${e}` : e);
|
|
25
26
|
}
|
|
@@ -38,8 +39,8 @@ function normalizeString(e, n) {
|
|
|
38
39
|
if (!(l === t - 1 || s === 1)) if (s === 2) {
|
|
39
40
|
if (r.length < 2 || i !== 2 || r[r.length - 1] !== "." || r[r.length - 2] !== ".") {
|
|
40
41
|
if (r.length > 2) {
|
|
41
|
-
const
|
|
42
|
-
|
|
42
|
+
const g = r.lastIndexOf("/");
|
|
43
|
+
g === -1 ? (r = "", i = 0) : (r = r.slice(0, g), i = r.length - 1 - r.lastIndexOf("/")), l = t, s = 0;
|
|
43
44
|
continue;
|
|
44
45
|
} else if (r.length > 0) {
|
|
45
46
|
r = "", i = 0, l = t, s = 0;
|
|
@@ -54,8 +55,8 @@ function normalizeString(e, n) {
|
|
|
54
55
|
return r;
|
|
55
56
|
}
|
|
56
57
|
function toAbsolutePath(e, n) {
|
|
57
|
-
return (0,
|
|
58
|
+
return (0, _isType.isAbsolutePath)(e) ? e : (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(n || process.cwd(), e), !0));
|
|
58
59
|
}
|
|
59
|
-
function toRelativePath(e, n) {
|
|
60
|
-
return !e || e.length === 0 ? "." : ((0,
|
|
60
|
+
function toRelativePath(e, n = (0, _cwd.cwd)()) {
|
|
61
|
+
return !e || e.length === 0 ? "." : ((0, _isType.isAbsolutePath)(e) ? e = (0, _slash.slash)(normalizeString(e, !0)) : e = (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(n, e), !0)), e.startsWith("./") ? e.slice(2) : e);
|
|
61
62
|
}
|
package/dist/correct-path.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isAbsolutePath as
|
|
1
|
+
import{cwd as E}from"./cwd";import{isAbsolutePath as u}from"./is-type";import{joinPaths as c}from"./join-paths";import{DRIVE_LETTER_REGEX as m,DRIVE_LETTER_START_REGEX as d,UNC_REGEX as x}from"./regex";import{slash as f}from"./slash";export function normalizeWindowsPath(e=""){return e&&f(e).replace(d,n=>n.toUpperCase())}export function correctPath(e){if(!e||e.length===0)return".";e=normalizeWindowsPath(e);const n=e.match(x),r=u(e),i=e.endsWith("/");return e=normalizeString(e,!r),e.length===0?r?"/":i?"./":".":(i&&(e+="/"),m.test(e)&&(e+="/"),n?r?`//${e}`:`//./${e}`:!e.startsWith("/")&&r&&!m.test(e)?`/${e}`:e)}export function normalizeString(e,n){let r="",i=0,l=-1,s=0,o=null;for(let t=0;t<=e.length;++t){if(t<e.length)o=e[t];else{if(o==="/")break;o="/"}if(o==="/"){if(!(l===t-1||s===1))if(s===2){if(r.length<2||i!==2||r[r.length-1]!=="."||r[r.length-2]!=="."){if(r.length>2){const g=r.lastIndexOf("/");g===-1?(r="",i=0):(r=r.slice(0,g),i=r.length-1-r.lastIndexOf("/")),l=t,s=0;continue}else if(r.length>0){r="",i=0,l=t,s=0;continue}}n&&(r+=r.length>0?"/..":"..",i=2)}else r.length>0?r+=`/${e.slice(l+1,t)}`:r=e.slice(l+1,t),i=t-l-1;l=t,s=0}else o==="."&&s!==-1?++s:s=-1}return r}export function toAbsolutePath(e,n){return u(e)?e:f(normalizeString(c(n||process.cwd(),e),!0))}export function toRelativePath(e,n=E()){return!e||e.length===0?".":(u(e)?e=f(normalizeString(e,!0)):e=f(normalizeString(c(n,e),!0)),e.startsWith("./")?e.slice(2):e)}
|
package/dist/cwd.cjs
ADDED
package/dist/cwd.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the current working directory.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* This function attempts to retrieve the current working directory using `process.cwd()`.
|
|
6
|
+
*
|
|
7
|
+
* @returns The current working directory or '/' if it cannot be determined
|
|
8
|
+
*/
|
|
9
|
+
export declare function cwd(): string;
|
package/dist/cwd.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function cwd(){return typeof process<"u"&&typeof process.cwd=="function"?process.cwd().replace(/\\/g,"/"):"/"}
|
package/dist/delimiter.cjs
CHANGED
|
@@ -5,14 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.win32 = exports.posix = exports.delimiter = void 0;
|
|
7
7
|
const delimiter = exports.delimiter = process?.platform === "win32" ? ";" : ":";
|
|
8
|
-
const
|
|
8
|
+
const i = {
|
|
9
9
|
posix: void 0,
|
|
10
10
|
win32: void 0
|
|
11
11
|
},
|
|
12
|
-
|
|
13
|
-
get(
|
|
14
|
-
return
|
|
12
|
+
e = (t = delimiter) => new Proxy({}, {
|
|
13
|
+
get(o, n) {
|
|
14
|
+
return n === "delimiter" ? t : n === "posix" ? posix : n === "win32" ? win32 : i[n];
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
|
-
const posix = exports.posix =
|
|
18
|
-
win32 = exports.win32 =
|
|
17
|
+
const posix = exports.posix = e(":"),
|
|
18
|
+
win32 = exports.win32 = e(";");
|
package/dist/delimiter.d.ts
CHANGED
|
@@ -4,5 +4,15 @@
|
|
|
4
4
|
* Equals to `";"` in windows and `":"` in all other platforms.
|
|
5
5
|
*/
|
|
6
6
|
export declare const delimiter: ";" | ":";
|
|
7
|
-
export declare const posix:
|
|
8
|
-
|
|
7
|
+
export declare const posix: {
|
|
8
|
+
posix: any;
|
|
9
|
+
win32: any;
|
|
10
|
+
} & {
|
|
11
|
+
delimiter: ";" | ":";
|
|
12
|
+
};
|
|
13
|
+
export declare const win32: {
|
|
14
|
+
posix: any;
|
|
15
|
+
win32: any;
|
|
16
|
+
} & {
|
|
17
|
+
delimiter: ";" | ":";
|
|
18
|
+
};
|
package/dist/delimiter.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const delimiter=process?.platform==="win32"?";":":";const
|
|
1
|
+
export const delimiter=process?.platform==="win32"?";":":";const i={posix:void 0,win32:void 0},e=(t=delimiter)=>new Proxy({},{get(o,n){return n==="delimiter"?t:n==="posix"?posix:n==="win32"?win32:i[n]}});export const posix=e(":"),win32=e(";");
|
package/dist/file-path-fns.cjs
CHANGED
|
@@ -13,43 +13,45 @@ exports.hasFileName = hasFileName;
|
|
|
13
13
|
exports.hasFilePath = hasFilePath;
|
|
14
14
|
exports.hasFolderName = hasFolderName;
|
|
15
15
|
exports.parsePath = parsePath;
|
|
16
|
+
exports.relative = relative;
|
|
16
17
|
exports.relativePath = relativePath;
|
|
17
|
-
exports.
|
|
18
|
+
exports.relativeToCurrentDir = relativeToCurrentDir;
|
|
18
19
|
exports.renameFile = renameFile;
|
|
20
|
+
exports.resolve = resolve;
|
|
19
21
|
exports.resolvePath = resolvePath;
|
|
20
22
|
exports.resolvePaths = resolvePaths;
|
|
21
23
|
var _base = require("@stryke/types/base");
|
|
22
|
-
var _nodePath = require("node:path");
|
|
23
24
|
var _correctPath = require("./correct-path.cjs");
|
|
24
|
-
var
|
|
25
|
-
var
|
|
25
|
+
var _cwd = require("./cwd.cjs");
|
|
26
|
+
var _isType = require("./is-type.cjs");
|
|
26
27
|
var _joinPaths = require("./join-paths.cjs");
|
|
28
|
+
var _regex = require("./regex.cjs");
|
|
27
29
|
function findFileName(e, t = {}) {
|
|
28
30
|
const {
|
|
29
|
-
requireExtension:
|
|
30
|
-
withExtension:
|
|
31
|
+
requireExtension: r = !1,
|
|
32
|
+
withExtension: n = !0
|
|
31
33
|
} = t,
|
|
32
34
|
i = (0, _correctPath.normalizeWindowsPath)(e)?.split(e?.includes("\\") ? "\\" : "/")?.pop() ?? "";
|
|
33
|
-
return
|
|
35
|
+
return r === !0 && !i.includes(".") ? _base.EMPTY_STRING : n === !1 && i.includes(".") ? i.substring(0, i.lastIndexOf(".")) || _base.EMPTY_STRING : i;
|
|
34
36
|
}
|
|
35
37
|
function findFilePath(e) {
|
|
36
38
|
const t = (0, _correctPath.normalizeWindowsPath)(e),
|
|
37
|
-
|
|
39
|
+
r = t.replace(findFileName(t, {
|
|
38
40
|
requireExtension: !0
|
|
39
41
|
}), "");
|
|
40
|
-
return
|
|
42
|
+
return r === "/" ? r : r.replace(/\/$/, "");
|
|
41
43
|
}
|
|
42
44
|
function findFolderName(e) {
|
|
43
45
|
const t = findFilePath(e).split("/");
|
|
44
|
-
let
|
|
45
|
-
for (let
|
|
46
|
-
const i = t[
|
|
46
|
+
let r = "";
|
|
47
|
+
for (let n = t.length - 1; n >= 0; n--) {
|
|
48
|
+
const i = t[n];
|
|
47
49
|
if (i) {
|
|
48
|
-
|
|
50
|
+
r = i;
|
|
49
51
|
break;
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
|
-
return
|
|
54
|
+
return r ?? _base.EMPTY_STRING;
|
|
53
55
|
}
|
|
54
56
|
function findFileExtension(e) {
|
|
55
57
|
if (e.endsWith(".") || e.endsWith("/")) return;
|
|
@@ -71,42 +73,63 @@ function hasFolderName(e) {
|
|
|
71
73
|
function hasFileExtension(e) {
|
|
72
74
|
return !!findFileExtension(e);
|
|
73
75
|
}
|
|
74
|
-
function resolvePath(e, t = (0,
|
|
75
|
-
const
|
|
76
|
-
let
|
|
76
|
+
function resolvePath(e, t = (0, _cwd.cwd)()) {
|
|
77
|
+
const r = (0, _correctPath.normalizeWindowsPath)(e).split("/");
|
|
78
|
+
let n = "",
|
|
77
79
|
i = !1;
|
|
78
|
-
for (let
|
|
79
|
-
const
|
|
80
|
-
!
|
|
80
|
+
for (let o = r.length - 1; o >= -1 && !i; o--) {
|
|
81
|
+
const s = o >= 0 ? r[o] : t;
|
|
82
|
+
!s || s.length === 0 || (n = (0, _joinPaths.joinPaths)(s, n), i = (0, _isType.isAbsolutePath)(s));
|
|
81
83
|
}
|
|
82
|
-
return
|
|
84
|
+
return n = (0, _correctPath.normalizeString)(n, !i), i && !(0, _isType.isAbsolutePath)(n) ? `/${n}` : n.length > 0 ? n : ".";
|
|
85
|
+
}
|
|
86
|
+
function resolve(...e) {
|
|
87
|
+
e = e.map(n => (0, _correctPath.normalizeWindowsPath)(n));
|
|
88
|
+
let t = "",
|
|
89
|
+
r = !1;
|
|
90
|
+
for (let n = e.length - 1; n >= -1 && !r; n--) {
|
|
91
|
+
const i = n >= 0 ? e[n] : (0, _cwd.cwd)();
|
|
92
|
+
!i || i.length === 0 || (t = `${i}/${t}`, r = (0, _isType.isAbsolute)(i));
|
|
93
|
+
}
|
|
94
|
+
return t = (0, _correctPath.normalizeString)(t, !r), r && !(0, _isType.isAbsolute)(t) ? `/${t}` : t.length > 0 ? t : ".";
|
|
83
95
|
}
|
|
84
96
|
function resolvePaths(...e) {
|
|
85
97
|
return resolvePath((0, _joinPaths.joinPaths)(...e.map(t => (0, _correctPath.normalizeWindowsPath)(t))));
|
|
86
98
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
99
|
+
function relative(e, t) {
|
|
100
|
+
const r = resolve(e).replace(_regex.ROOT_FOLDER_REGEX, "$1").split("/"),
|
|
101
|
+
n = resolve(t).replace(_regex.ROOT_FOLDER_REGEX, "$1").split("/");
|
|
102
|
+
if (n[0][1] === ":" && r[0][1] === ":" && r[0] !== n[0]) return n.join("/");
|
|
103
|
+
const i = [...r];
|
|
104
|
+
for (const o of i) {
|
|
105
|
+
if (n[0] !== o) break;
|
|
106
|
+
r.shift(), n.shift();
|
|
107
|
+
}
|
|
108
|
+
return [...r.map(() => ".."), ...n].join("/");
|
|
109
|
+
}
|
|
110
|
+
function relativePath(e, t, r = !1) {
|
|
111
|
+
return relative(r !== !0 ? e.replace(/\/$/, "") : e, r !== !0 ? t.replace(/\/$/, "") : t);
|
|
89
112
|
}
|
|
90
|
-
function
|
|
91
|
-
return relativePath(e, (0,
|
|
113
|
+
function relativeToCurrentDir(e) {
|
|
114
|
+
return relativePath(e, (0, _cwd.cwd)());
|
|
92
115
|
}
|
|
93
116
|
function parsePath(e) {
|
|
94
117
|
const t = /^[/\\]|^[a-z]:[/\\]/i.exec(e)?.[0]?.replace(/\\/g, "/") || "",
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const i = findFolderName(
|
|
99
|
-
|
|
100
|
-
|
|
118
|
+
r = (0, _correctPath.normalizeWindowsPath)(e),
|
|
119
|
+
n = r.replace(/\/$/, "").split("/").slice(0, -1);
|
|
120
|
+
n.length === 1 && /^[A-Z]:$/i.test(n[0]) && (n[0] += "/");
|
|
121
|
+
const i = findFolderName(r),
|
|
122
|
+
o = n.join("/") || ((0, _isType.isAbsolutePath)(e) ? "/" : "."),
|
|
123
|
+
s = findFileExtensionSafe(e);
|
|
101
124
|
return {
|
|
102
125
|
root: t,
|
|
103
|
-
dir:
|
|
126
|
+
dir: o,
|
|
104
127
|
base: i,
|
|
105
|
-
ext:
|
|
106
|
-
name: i.slice(0, i.length -
|
|
128
|
+
ext: s,
|
|
129
|
+
name: i.slice(0, i.length - s.length)
|
|
107
130
|
};
|
|
108
131
|
}
|
|
109
132
|
function renameFile(e, t) {
|
|
110
|
-
const
|
|
111
|
-
return (0, _joinPaths.joinPaths)(
|
|
133
|
+
const r = parsePath(e);
|
|
134
|
+
return (0, _joinPaths.joinPaths)(r.dir, t.includes(".") ? t : t + r.ext);
|
|
112
135
|
}
|
package/dist/file-path-fns.d.ts
CHANGED
|
@@ -117,6 +117,7 @@ export declare function hasFileExtension(filePath: string): boolean;
|
|
|
117
117
|
* @returns The resolved path
|
|
118
118
|
*/
|
|
119
119
|
export declare function resolvePath(path: string, cwd?: string): string;
|
|
120
|
+
export declare function resolve(...paths: string[]): string;
|
|
120
121
|
/**
|
|
121
122
|
* Resolve the file path to an absolute path.
|
|
122
123
|
*
|
|
@@ -124,6 +125,17 @@ export declare function resolvePath(path: string, cwd?: string): string;
|
|
|
124
125
|
* @returns The resolved path
|
|
125
126
|
*/
|
|
126
127
|
export declare function resolvePaths(...paths: string[]): string;
|
|
128
|
+
/**
|
|
129
|
+
* Get the relative path from one file to another.
|
|
130
|
+
*
|
|
131
|
+
* @remarks
|
|
132
|
+
* This function is similar to the `path.relative` function in Node's path module.
|
|
133
|
+
*
|
|
134
|
+
* @param from - The base path to start from
|
|
135
|
+
* @param to - The target path to resolve relative to the base path
|
|
136
|
+
* @returns The relative path from the base path to the target path
|
|
137
|
+
*/
|
|
138
|
+
export declare function relative(from: string, to: string): string;
|
|
127
139
|
/**
|
|
128
140
|
* Get the relative path from one file to another.
|
|
129
141
|
*
|
|
@@ -142,7 +154,7 @@ export declare function relativePath(from: string, to: string, withEndSlash?: bo
|
|
|
142
154
|
* @param filePath - The file path to process
|
|
143
155
|
* @returns The resolved file path
|
|
144
156
|
*/
|
|
145
|
-
export declare function
|
|
157
|
+
export declare function relativeToCurrentDir(filePath: string): string;
|
|
146
158
|
/**
|
|
147
159
|
* Check if the path is a relative path.
|
|
148
160
|
*
|
package/dist/file-path-fns.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EMPTY_STRING as
|
|
1
|
+
import{EMPTY_STRING as u}from"@stryke/types/base";import{normalizeString as g,normalizeWindowsPath as l}from"./correct-path";import{cwd as a}from"./cwd";import{isAbsolute as p,isAbsolutePath as c}from"./is-type";import{joinPaths as f}from"./join-paths";import{ROOT_FOLDER_REGEX as d}from"./regex";export function findFileName(e,t={}){const{requireExtension:r=!1,withExtension:n=!0}=t,i=l(e)?.split(e?.includes("\\")?"\\":"/")?.pop()??"";return r===!0&&!i.includes(".")?u:n===!1&&i.includes(".")?i.substring(0,i.lastIndexOf("."))||u:i}export function findFilePath(e){const t=l(e),r=t.replace(findFileName(t,{requireExtension:!0}),"");return r==="/"?r:r.replace(/\/$/,"")}export function findFolderName(e){const t=findFilePath(e).split("/");let r="";for(let n=t.length-1;n>=0;n--){const i=t[n];if(i){r=i;break}}return r??u}export function findFileExtension(e){if(e.endsWith(".")||e.endsWith("/"))return;const t=/.(\.[^./]+|\.)$/.exec(l(e));return t&&t[1]||void 0}export function findFileExtensionSafe(e){return findFileExtension(e)??u}export function hasFileName(e){return!!findFileName(e)}export function hasFilePath(e){return!!findFilePath(e)}export function hasFolderName(e){return!!findFolderName(e)}export function hasFileExtension(e){return!!findFileExtension(e)}export function resolvePath(e,t=a()){const r=l(e).split("/");let n="",i=!1;for(let o=r.length-1;o>=-1&&!i;o--){const s=o>=0?r[o]:t;!s||s.length===0||(n=f(s,n),i=c(s))}return n=g(n,!i),i&&!c(n)?`/${n}`:n.length>0?n:"."}export function resolve(...e){e=e.map(n=>l(n));let t="",r=!1;for(let n=e.length-1;n>=-1&&!r;n--){const i=n>=0?e[n]:a();!i||i.length===0||(t=`${i}/${t}`,r=p(i))}return t=g(t,!r),r&&!p(t)?`/${t}`:t.length>0?t:"."}export function resolvePaths(...e){return resolvePath(f(...e.map(t=>l(t))))}export function relative(e,t){const r=resolve(e).replace(d,"$1").split("/"),n=resolve(t).replace(d,"$1").split("/");if(n[0][1]===":"&&r[0][1]===":"&&r[0]!==n[0])return n.join("/");const i=[...r];for(const o of i){if(n[0]!==o)break;r.shift(),n.shift()}return[...r.map(()=>".."),...n].join("/")}export function relativePath(e,t,r=!1){return relative(r!==!0?e.replace(/\/$/,""):e,r!==!0?t.replace(/\/$/,""):t)}export function relativeToCurrentDir(e){return relativePath(e,a())}export function parsePath(e){const t=/^[/\\]|^[a-z]:[/\\]/i.exec(e)?.[0]?.replace(/\\/g,"/")||"",r=l(e),n=r.replace(/\/$/,"").split("/").slice(0,-1);n.length===1&&/^[A-Z]:$/i.test(n[0])&&(n[0]+="/");const i=findFolderName(r),o=n.join("/")||(c(e)?"/":"."),s=findFileExtensionSafe(e);return{root:t,dir:o,base:i,ext:s,name:i.slice(0,i.length-s.length)}}export function renameFile(e,t){const r=parsePath(e);return f(r.dir,t.includes(".")?t:t+r.ext)}
|
package/dist/get-parent-path.cjs
CHANGED
|
@@ -4,26 +4,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.resolveParentPath = exports.getParentPath = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _cwd = require("./cwd.cjs");
|
|
8
8
|
var _joinPaths = require("./join-paths.cjs");
|
|
9
|
-
const resolveParentPath = (r,
|
|
9
|
+
const resolveParentPath = (r, n = 1) => {
|
|
10
10
|
let t = r.replaceAll(/\/+$/g, "");
|
|
11
|
-
for (let
|
|
11
|
+
for (let i = 0; i < n; i++) t = (0, _joinPaths.joinPaths)(t, "..");
|
|
12
12
|
return t;
|
|
13
13
|
},
|
|
14
|
-
getParentPath = (r,
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
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"));
|
|
14
|
+
getParentPath = (r, n = (0, _cwd.cwd)(), t = {}) => {
|
|
15
|
+
const i = t?.ignoreCase ?? !0,
|
|
16
|
+
p = t?.skipCwd ?? !1;
|
|
17
|
+
let e = n;
|
|
18
|
+
p && (e = resolveParentPath(n));
|
|
19
|
+
let o = Array.isArray(r) ? r : [r];
|
|
20
|
+
for (i && (o = o.map(a => a.toLowerCase()));;) {
|
|
21
|
+
const a = o.find(f => (0, _joinPaths.joinPaths)(e, f));
|
|
23
22
|
if (a) return (0, _joinPaths.joinPaths)(e, a);
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
26
|
-
e =
|
|
23
|
+
const l = resolveParentPath(e);
|
|
24
|
+
if (l === e) return;
|
|
25
|
+
e = l;
|
|
27
26
|
}
|
|
28
27
|
};
|
|
29
28
|
exports.getParentPath = getParentPath;
|
|
@@ -36,4 +36,4 @@ export interface GetParentPathOptions {
|
|
|
36
36
|
* @param cwd - The current working directory.
|
|
37
37
|
* @returns The first parent path that exists.
|
|
38
38
|
*/
|
|
39
|
-
export declare const getParentPath: (name: string | string[], cwd
|
|
39
|
+
export declare const getParentPath: (name: string | string[], cwd?: string, options?: Partial<GetParentPathOptions>) => string | undefined;
|
package/dist/get-parent-path.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{cwd as g}from"./cwd";import{joinPaths as s}from"./join-paths";export const resolveParentPath=(r,n=1)=>{let t=r.replaceAll(/\/+$/g,"");for(let i=0;i<n;i++)t=s(t,"..");return t},getParentPath=(r,n=g(),t={})=>{const i=t?.ignoreCase??!0,p=t?.skipCwd??!1;let e=n;p&&(e=resolveParentPath(n));let o=Array.isArray(r)?r:[r];for(i&&(o=o.map(a=>a.toLowerCase()));;){const a=o.find(f=>s(e,f));if(a)return s(e,a);const l=resolveParentPath(e);if(l===e)return;e=l}};
|
package/dist/index.cjs
CHANGED
|
@@ -25,25 +25,25 @@ Object.keys(_correctPath).forEach(function (key) {
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
|
-
var
|
|
29
|
-
Object.keys(
|
|
28
|
+
var _cwd = require("./cwd.cjs");
|
|
29
|
+
Object.keys(_cwd).forEach(function (key) {
|
|
30
30
|
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] ===
|
|
31
|
+
if (key in exports && exports[key] === _cwd[key]) return;
|
|
32
32
|
Object.defineProperty(exports, key, {
|
|
33
33
|
enumerable: true,
|
|
34
34
|
get: function () {
|
|
35
|
-
return
|
|
35
|
+
return _cwd[key];
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
|
-
var
|
|
40
|
-
Object.keys(
|
|
39
|
+
var _delimiter = require("./delimiter.cjs");
|
|
40
|
+
Object.keys(_delimiter).forEach(function (key) {
|
|
41
41
|
if (key === "default" || key === "__esModule") return;
|
|
42
|
-
if (key in exports && exports[key] ===
|
|
42
|
+
if (key in exports && exports[key] === _delimiter[key]) return;
|
|
43
43
|
Object.defineProperty(exports, key, {
|
|
44
44
|
enumerable: true,
|
|
45
45
|
get: function () {
|
|
46
|
-
return
|
|
46
|
+
return _delimiter[key];
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
});
|
|
@@ -69,28 +69,6 @@ Object.keys(_getParentPath).forEach(function (key) {
|
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
|
-
var _getWorkspaceRoot = require("./get-workspace-root.cjs");
|
|
73
|
-
Object.keys(_getWorkspaceRoot).forEach(function (key) {
|
|
74
|
-
if (key === "default" || key === "__esModule") return;
|
|
75
|
-
if (key in exports && exports[key] === _getWorkspaceRoot[key]) return;
|
|
76
|
-
Object.defineProperty(exports, key, {
|
|
77
|
-
enumerable: true,
|
|
78
|
-
get: function () {
|
|
79
|
-
return _getWorkspaceRoot[key];
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
var _isFile = require("./is-file.cjs");
|
|
84
|
-
Object.keys(_isFile).forEach(function (key) {
|
|
85
|
-
if (key === "default" || key === "__esModule") return;
|
|
86
|
-
if (key in exports && exports[key] === _isFile[key]) return;
|
|
87
|
-
Object.defineProperty(exports, key, {
|
|
88
|
-
enumerable: true,
|
|
89
|
-
get: function () {
|
|
90
|
-
return _isFile[key];
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
72
|
var _isParentPath = require("./is-parent-path.cjs");
|
|
95
73
|
Object.keys(_isParentPath).forEach(function (key) {
|
|
96
74
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -146,17 +124,6 @@ Object.keys(_replace).forEach(function (key) {
|
|
|
146
124
|
}
|
|
147
125
|
});
|
|
148
126
|
});
|
|
149
|
-
var _resolve = require("./resolve.cjs");
|
|
150
|
-
Object.keys(_resolve).forEach(function (key) {
|
|
151
|
-
if (key === "default" || key === "__esModule") return;
|
|
152
|
-
if (key in exports && exports[key] === _resolve[key]) return;
|
|
153
|
-
Object.defineProperty(exports, key, {
|
|
154
|
-
enumerable: true,
|
|
155
|
-
get: function () {
|
|
156
|
-
return _resolve[key];
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
127
|
var _slash = require("./slash.cjs");
|
|
161
128
|
Object.keys(_slash).forEach(function (key) {
|
|
162
129
|
if (key === "default" || key === "__esModule") return;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,16 +8,13 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export * from "./asset-extensions";
|
|
10
10
|
export * from "./correct-path";
|
|
11
|
+
export * from "./cwd";
|
|
11
12
|
export * from "./delimiter";
|
|
12
|
-
export * from "./exists";
|
|
13
13
|
export * from "./file-path-fns";
|
|
14
14
|
export * from "./get-parent-path";
|
|
15
|
-
export * from "./get-workspace-root";
|
|
16
|
-
export * from "./is-file";
|
|
17
15
|
export * from "./is-parent-path";
|
|
18
16
|
export * from "./is-root-dir";
|
|
19
17
|
export * from "./join-paths";
|
|
20
18
|
export * from "./regex";
|
|
21
19
|
export * from "./replace";
|
|
22
|
-
export * from "./resolve";
|
|
23
20
|
export * from "./slash";
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./asset-extensions";export*from"./correct-path";export*from"./
|
|
1
|
+
export*from"./asset-extensions";export*from"./correct-path";export*from"./cwd";export*from"./delimiter";export*from"./file-path-fns";export*from"./get-parent-path";export*from"./is-parent-path";export*from"./is-root-dir";export*from"./join-paths";export*from"./regex";export*from"./replace";export*from"./slash";
|
package/dist/is-root-dir.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isSystemRoot =
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
exports.isSystemRoot = isSystemRoot;
|
|
7
|
+
function isSystemRoot(o) {
|
|
8
|
+
return o === "/" || o === "c:\\" || o === "C:\\";
|
|
9
|
+
}
|
package/dist/is-root-dir.d.ts
CHANGED
package/dist/is-root-dir.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export function isSystemRoot(o){return o==="/"||o==="c:\\"||o==="C:\\"}
|
package/dist/is-type.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isAbsolute = isAbsolute;
|
|
7
|
+
exports.isAbsolutePath = isAbsolutePath;
|
|
8
|
+
exports.isRelative = isRelative;
|
|
9
|
+
exports.isRelativePath = isRelativePath;
|
|
10
|
+
var _regex = require("./regex.cjs");
|
|
11
|
+
var _slash = require("./slash.cjs");
|
|
12
|
+
function isAbsolutePath(t) {
|
|
13
|
+
return _regex.ABSOLUTE_PATH_REGEX.test((0, _slash.slash)(t));
|
|
14
|
+
}
|
|
15
|
+
function isAbsolute(t) {
|
|
16
|
+
return isAbsolutePath(t);
|
|
17
|
+
}
|
|
18
|
+
function isRelativePath(t) {
|
|
19
|
+
return !isAbsolutePath(t);
|
|
20
|
+
}
|
|
21
|
+
function isRelative(t) {
|
|
22
|
+
return isRelativePath(t);
|
|
23
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if the path is an absolute path.
|
|
3
|
+
*
|
|
4
|
+
* @param path - The path to check
|
|
5
|
+
* @returns An indicator specifying if the path is an absolute path
|
|
6
|
+
*/
|
|
7
|
+
export declare function isAbsolutePath(path: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Check if the path is an absolute path.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* This is an alias for {@link isAbsolutePath}.
|
|
13
|
+
*
|
|
14
|
+
* @param path - The path to check
|
|
15
|
+
* @returns An indicator specifying if the path is an absolute path
|
|
16
|
+
*/
|
|
17
|
+
export declare function isAbsolute(path: string): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Check if the path is a relative path.
|
|
20
|
+
*
|
|
21
|
+
* @param path - The path to check
|
|
22
|
+
* @returns An indicator specifying if the path is a relative path
|
|
23
|
+
*/
|
|
24
|
+
export declare function isRelativePath(path: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Check if the path is a relative path.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* This is an alias for {@link isRelativePath}.
|
|
30
|
+
*
|
|
31
|
+
* @param path - The path to check
|
|
32
|
+
* @returns An indicator specifying if the path is a relative path
|
|
33
|
+
*/
|
|
34
|
+
export declare function isRelative(path: string): boolean;
|
package/dist/is-type.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ABSOLUTE_PATH_REGEX as o}from"./regex";import{slash as n}from"./slash";export function isAbsolutePath(t){return o.test(n(t))}export function isAbsolute(t){return isAbsolutePath(t)}export function isRelativePath(t){return!isAbsolutePath(t)}export function isRelative(t){return isRelativePath(t)}
|