@stryke/fs 0.33.70 → 0.33.71
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/CHANGELOG.md +17 -0
- package/dist/_virtual/{rolldown_runtime.cjs → _rolldown/runtime.cjs} +1 -1
- package/dist/buffer.cjs +5 -4
- package/dist/buffer.d.cts.map +1 -1
- package/dist/buffer.d.mts.map +1 -1
- package/dist/buffer.mjs +1 -1
- package/dist/chmod-x.cjs +2 -1
- package/dist/chmod-x.d.cts.map +1 -1
- package/dist/chmod-x.d.mts.map +1 -1
- package/dist/chmod-x.mjs.map +1 -1
- package/dist/command-exists.cjs +3 -2
- package/dist/command-exists.d.cts.map +1 -1
- package/dist/command-exists.d.mts.map +1 -1
- package/dist/command-exists.mjs +1 -1
- package/dist/command-exists.mjs.map +1 -1
- package/dist/compress.cjs +7 -7
- package/dist/compress.d.cts.map +1 -1
- package/dist/compress.d.mts.map +1 -1
- package/dist/compress.mjs +5 -6
- package/dist/compress.mjs.map +1 -1
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts.map +1 -1
- package/dist/copy-file.cjs +16 -15
- package/dist/copy-file.d.cts +0 -1
- package/dist/copy-file.d.cts.map +1 -1
- package/dist/copy-file.d.mts +0 -1
- package/dist/copy-file.d.mts.map +1 -1
- package/dist/copy-file.mjs +6 -6
- package/dist/exists.cjs +2 -1
- package/dist/exists.d.cts.map +1 -1
- package/dist/exists.d.mts.map +1 -1
- package/dist/get-parent-path.cjs +14 -13
- package/dist/get-parent-path.d.cts.map +1 -1
- package/dist/get-parent-path.d.mts.map +1 -1
- package/dist/get-parent-path.mjs +6 -6
- package/dist/get-parent-path.mjs.map +1 -1
- package/dist/get-workspace-root.cjs +14 -13
- package/dist/get-workspace-root.d.cts.map +1 -1
- package/dist/get-workspace-root.d.mts.map +1 -1
- package/dist/get-workspace-root.mjs +3 -3
- package/dist/get-workspace-root.mjs.map +1 -1
- package/dist/helpers.cjs +2 -1
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/install.cjs +6 -5
- package/dist/install.d.cts +0 -2
- package/dist/install.d.cts.map +1 -1
- package/dist/install.d.mts +0 -3
- package/dist/install.d.mts.map +1 -1
- package/dist/install.mjs +1 -1
- package/dist/is-file.cjs +7 -6
- package/dist/is-file.d.cts.map +1 -1
- package/dist/is-file.d.mts.map +1 -1
- package/dist/is-file.mjs +1 -1
- package/dist/json/src/storm-json.cjs +3 -3
- package/dist/json/src/storm-json.mjs +1 -1
- package/dist/json/src/storm-json.mjs.map +1 -1
- package/dist/json/src/types.d.cts +0 -1
- package/dist/json/src/types.d.cts.map +1 -1
- package/dist/json/src/types.d.mts +0 -1
- package/dist/json/src/types.d.mts.map +1 -1
- package/dist/json/src/utils/code-frames.mjs.map +1 -1
- package/dist/json/src/utils/parse-error.cjs +1 -1
- package/dist/json/src/utils/stringify.mjs.map +1 -1
- package/dist/json/src/utils/strip-comments.cjs +4 -5
- package/dist/json/src/utils/strip-comments.mjs +4 -6
- package/dist/json/src/utils/strip-comments.mjs.map +1 -1
- package/dist/json.cjs +6 -4
- package/dist/json.d.cts +0 -1
- package/dist/json.d.cts.map +1 -1
- package/dist/json.d.mts +0 -1
- package/dist/json.d.mts.map +1 -1
- package/dist/json.mjs +2 -2
- package/dist/list-files.cjs +6 -5
- package/dist/list-files.d.cts.map +1 -1
- package/dist/list-files.d.mts.map +1 -1
- package/dist/list-files.mjs +1 -1
- package/dist/list-files.mjs.map +1 -1
- package/dist/package-fns.cjs +12 -11
- package/dist/package-fns.d.cts +0 -1
- package/dist/package-fns.d.cts.map +1 -1
- package/dist/package-fns.d.mts +0 -1
- package/dist/package-fns.d.mts.map +1 -1
- package/dist/package-fns.mjs +4 -4
- package/dist/read-file.cjs +2 -1
- package/dist/read-file.d.cts.map +1 -1
- package/dist/read-file.d.mts.map +1 -1
- package/dist/registry.cjs +4 -3
- package/dist/registry.d.cts.map +1 -1
- package/dist/registry.d.mts.map +1 -1
- package/dist/registry.mjs.map +1 -1
- package/dist/remove-file.cjs +2 -1
- package/dist/remove-file.d.cts.map +1 -1
- package/dist/remove-file.d.mts.map +1 -1
- package/dist/resolve.cjs +38 -37
- package/dist/resolve.d.cts.map +1 -1
- package/dist/resolve.d.mts.map +1 -1
- package/dist/resolve.mjs +18 -18
- package/dist/resolve.mjs.map +1 -1
- package/dist/semver-fns.cjs +5 -4
- package/dist/semver-fns.d.cts.map +1 -1
- package/dist/semver-fns.d.mts.map +1 -1
- package/dist/semver-fns.mjs +1 -1
- package/dist/semver-fns.mjs.map +1 -1
- package/dist/toml.cjs +3 -2
- package/dist/toml.d.cts +3 -4
- package/dist/toml.d.cts.map +1 -1
- package/dist/toml.d.mts +3 -4
- package/dist/toml.d.mts.map +1 -1
- package/dist/tsconfig.cjs +13 -12
- package/dist/tsconfig.d.cts +0 -1
- package/dist/tsconfig.d.cts.map +1 -1
- package/dist/tsconfig.d.mts +0 -1
- package/dist/tsconfig.d.mts.map +1 -1
- package/dist/tsconfig.mjs +5 -5
- package/dist/type-checks/src/index.cjs +3 -3
- package/dist/type-checks/src/index.mjs +3 -3
- package/dist/type-checks/src/is-buffer.cjs +2 -2
- package/dist/type-checks/src/is-buffer.mjs +1 -1
- package/dist/type-checks/src/is-buffer.mjs.map +1 -1
- package/dist/type-checks/src/is-set-string.cjs +1 -1
- package/dist/type-checks/src/is-set-string.mjs +1 -1
- package/dist/types/src/file.d.cts +0 -1
- package/dist/types/src/file.d.cts.map +1 -1
- package/dist/types/src/file.d.mts +0 -1
- package/dist/types/src/file.d.mts.map +1 -1
- package/dist/types/src/package-json.d.cts.map +1 -1
- package/dist/types/src/package-json.d.mts.map +1 -1
- package/dist/types/src/package-manager.d.cts.map +1 -1
- package/dist/types/src/package-manager.d.mts.map +1 -1
- package/dist/types/src/tsconfig.d.cts.map +1 -1
- package/dist/types/src/tsconfig.d.mts.map +1 -1
- package/dist/write-file.cjs +6 -5
- package/dist/write-file.d.cts.map +1 -1
- package/dist/write-file.d.mts.map +1 -1
- package/dist/write-file.mjs +2 -2
- package/dist/yaml.cjs +2 -1
- package/dist/yaml.d.cts.map +1 -1
- package/dist/yaml.d.mts.map +1 -1
- package/package.json +139 -58
- package/dist/convert/src/array-buffer-to-string.cjs +0 -19
- package/dist/convert/src/array-buffer-to-string.mjs +0 -19
- package/dist/convert/src/array-buffer-to-string.mjs.map +0 -1
- package/dist/convert/src/to-array.cjs +0 -15
- package/dist/convert/src/to-array.mjs +0 -15
- package/dist/convert/src/to-array.mjs.map +0 -1
- package/dist/convert/src/uint8-array-to-string.cjs +0 -15
- package/dist/convert/src/uint8-array-to-string.mjs +0 -16
- package/dist/convert/src/uint8-array-to-string.mjs.map +0 -1
- package/dist/helpers/src/get-unique.cjs +0 -14
- package/dist/helpers/src/get-unique.mjs +0 -14
- package/dist/helpers/src/get-unique.mjs.map +0 -1
- package/dist/path/src/append.cjs +0 -57
- package/dist/path/src/append.mjs +0 -57
- package/dist/path/src/append.mjs.map +0 -1
- package/dist/path/src/correct-path.cjs +0 -138
- package/dist/path/src/correct-path.mjs +0 -135
- package/dist/path/src/correct-path.mjs.map +0 -1
- package/dist/path/src/cwd.cjs +0 -17
- package/dist/path/src/cwd.mjs +0 -17
- package/dist/path/src/cwd.mjs.map +0 -1
- package/dist/path/src/file-path-fns.cjs +0 -178
- package/dist/path/src/file-path-fns.mjs +0 -171
- package/dist/path/src/file-path-fns.mjs.map +0 -1
- package/dist/path/src/is-parent-path.cjs +0 -32
- package/dist/path/src/is-parent-path.mjs +0 -33
- package/dist/path/src/is-parent-path.mjs.map +0 -1
- package/dist/path/src/is-root-dir.cjs +0 -14
- package/dist/path/src/is-root-dir.mjs +0 -14
- package/dist/path/src/is-root-dir.mjs.map +0 -1
- package/dist/path/src/is-type.cjs +0 -68
- package/dist/path/src/is-type.mjs +0 -67
- package/dist/path/src/is-type.mjs.map +0 -1
- package/dist/path/src/join-paths.cjs +0 -122
- package/dist/path/src/join-paths.mjs +0 -123
- package/dist/path/src/join-paths.mjs.map +0 -1
- package/dist/path/src/regex.cjs +0 -20
- package/dist/path/src/regex.mjs +0 -13
- package/dist/path/src/regex.mjs.map +0 -1
- package/dist/path/src/replace.cjs +0 -24
- package/dist/path/src/replace.mjs +0 -25
- package/dist/path/src/replace.mjs.map +0 -1
- package/dist/path/src/resolve-parent-path.cjs +0 -18
- package/dist/path/src/resolve-parent-path.mjs +0 -19
- package/dist/path/src/resolve-parent-path.mjs.map +0 -1
- package/dist/path/src/slash.cjs +0 -15
- package/dist/path/src/slash.mjs +0 -15
- package/dist/path/src/slash.mjs.map +0 -1
- package/dist/string-format/src/package.cjs +0 -92
- package/dist/string-format/src/package.mjs +0 -92
- package/dist/string-format/src/package.mjs.map +0 -1
- package/dist/types/src/base.cjs +0 -6
- package/dist/types/src/base.mjs +0 -6
- package/dist/types/src/base.mjs.map +0 -1
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
const require_regex = require('./regex.cjs');
|
|
2
|
-
const require_is_type = require('./is-type.cjs');
|
|
3
|
-
const require_slash = require('./slash.cjs');
|
|
4
|
-
|
|
5
|
-
//#region ../path/src/join-paths.ts
|
|
6
|
-
function normalizeWindowsPath(input = "") {
|
|
7
|
-
if (!input) return input;
|
|
8
|
-
return input.replace(/\\/g, "/").replace(require_regex.DRIVE_LETTER_START_REGEX, (r) => r.toUpperCase());
|
|
9
|
-
}
|
|
10
|
-
function correctPaths(path) {
|
|
11
|
-
if (!path || path.length === 0) return ".";
|
|
12
|
-
path = normalizeWindowsPath(path);
|
|
13
|
-
const isUNCPath = path.match(require_regex.UNC_REGEX);
|
|
14
|
-
const isPathAbsolute = require_is_type.isAbsolute(path);
|
|
15
|
-
const trailingSeparator = path[path.length - 1] === "/";
|
|
16
|
-
path = normalizeString(path, !isPathAbsolute);
|
|
17
|
-
if (path.length === 0) {
|
|
18
|
-
if (isPathAbsolute) return "/";
|
|
19
|
-
return trailingSeparator ? "./" : ".";
|
|
20
|
-
}
|
|
21
|
-
if (trailingSeparator) path += "/";
|
|
22
|
-
if (require_regex.DRIVE_LETTER_REGEX.test(path)) path += "/";
|
|
23
|
-
if (isUNCPath) {
|
|
24
|
-
if (!isPathAbsolute) return `//./${path}`;
|
|
25
|
-
return `//${path}`;
|
|
26
|
-
}
|
|
27
|
-
return isPathAbsolute && !require_is_type.isAbsolute(path) ? `/${path}` : path;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Joins all given path segments together using the platform-specific separator as a delimiter.
|
|
31
|
-
*
|
|
32
|
-
* @remarks
|
|
33
|
-
* Multiple segments can be provided as separate arguments. The resulting path is normalized to remove any redundant or unnecessary segments.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* import { joinPaths } from 'stryke/path';
|
|
38
|
-
*
|
|
39
|
-
* const fullPath = joinPaths('folder1', 'folder2', '..', 'folder3', 'file.txt');
|
|
40
|
-
* console.log(fullPath); // Output: 'folder1/folder3/file.txt'
|
|
41
|
-
*
|
|
42
|
-
* const absolutePath = joinPaths('/root', 'folder', '.', 'subfolder', 'file.txt');
|
|
43
|
-
* console.log(absolutePath); // Output: '/root/folder/subfolder/file.txt'
|
|
44
|
-
*
|
|
45
|
-
* const windowsPath = joinPaths('C:\\', 'Users', 'Public', '..', 'Documents', 'file.txt');
|
|
46
|
-
* console.log(windowsPath); // Output: 'C:/Users/Documents/file.txt'
|
|
47
|
-
*
|
|
48
|
-
* const uncPath = joinPaths('\\\\Server\\Share', 'Folder', 'File.txt');
|
|
49
|
-
* console.log(uncPath); // Output: '//Server/Share/Folder/File.txt'
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @param segments - The path segments to join.
|
|
53
|
-
* @returns The joined and normalized path string.
|
|
54
|
-
*/
|
|
55
|
-
function joinPaths(...segments) {
|
|
56
|
-
let result = "";
|
|
57
|
-
for (const segment of segments) if (segment && require_slash.slash(segment).replaceAll(/\//g, "") !== ".") {
|
|
58
|
-
if (result) if (require_slash.slash(segment).replaceAll(/\//g, "") === "..") result = require_slash.slash(result).replace(/\/+$/, "").replace(/\/*[^/]+$/, "");
|
|
59
|
-
else result = `${require_slash.slash(result).replace(/\/+$/, "")}/${require_slash.slash(segment).replace(/^\/+/, "")}`;
|
|
60
|
-
else if (require_slash.slash(segment).replaceAll(/\//g, "") !== "..") result = segment;
|
|
61
|
-
}
|
|
62
|
-
return correctPaths(result);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.
|
|
66
|
-
*
|
|
67
|
-
* @param path - The path to normalize.
|
|
68
|
-
* @param allowAboveRoot - Whether to allow the resulting path to be above the root directory.
|
|
69
|
-
* @returns the normalized path string.
|
|
70
|
-
*/
|
|
71
|
-
function normalizeString(path, allowAboveRoot) {
|
|
72
|
-
let res = "";
|
|
73
|
-
let lastSegmentLength = 0;
|
|
74
|
-
let lastSlash = -1;
|
|
75
|
-
let dots = 0;
|
|
76
|
-
let char = null;
|
|
77
|
-
for (let index = 0; index <= path.length; ++index) {
|
|
78
|
-
if (index < path.length) char = path[index];
|
|
79
|
-
else if (char === "/") break;
|
|
80
|
-
else char = "/";
|
|
81
|
-
if (char === "/") {
|
|
82
|
-
if (lastSlash === index - 1 || dots === 1) {} else if (dots === 2) {
|
|
83
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
84
|
-
if (res.length > 2) {
|
|
85
|
-
const lastSlashIndex = res.lastIndexOf("/");
|
|
86
|
-
if (lastSlashIndex === -1) {
|
|
87
|
-
res = "";
|
|
88
|
-
lastSegmentLength = 0;
|
|
89
|
-
} else {
|
|
90
|
-
res = res.slice(0, lastSlashIndex);
|
|
91
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
92
|
-
}
|
|
93
|
-
lastSlash = index;
|
|
94
|
-
dots = 0;
|
|
95
|
-
continue;
|
|
96
|
-
} else if (res.length > 0) {
|
|
97
|
-
res = "";
|
|
98
|
-
lastSegmentLength = 0;
|
|
99
|
-
lastSlash = index;
|
|
100
|
-
dots = 0;
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (allowAboveRoot) {
|
|
105
|
-
res += res.length > 0 ? "/.." : "..";
|
|
106
|
-
lastSegmentLength = 2;
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
|
|
110
|
-
else res = path.slice(lastSlash + 1, index);
|
|
111
|
-
lastSegmentLength = index - lastSlash - 1;
|
|
112
|
-
}
|
|
113
|
-
lastSlash = index;
|
|
114
|
-
dots = 0;
|
|
115
|
-
} else if (char === "." && dots !== -1) ++dots;
|
|
116
|
-
else dots = -1;
|
|
117
|
-
}
|
|
118
|
-
return res;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
//#endregion
|
|
122
|
-
exports.joinPaths = joinPaths;
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { DRIVE_LETTER_REGEX, DRIVE_LETTER_START_REGEX, UNC_REGEX } from "./regex.mjs";
|
|
2
|
-
import { isAbsolute } from "./is-type.mjs";
|
|
3
|
-
import { slash } from "./slash.mjs";
|
|
4
|
-
|
|
5
|
-
//#region ../path/src/join-paths.ts
|
|
6
|
-
function normalizeWindowsPath(input = "") {
|
|
7
|
-
if (!input) return input;
|
|
8
|
-
return input.replace(/\\/g, "/").replace(DRIVE_LETTER_START_REGEX, (r) => r.toUpperCase());
|
|
9
|
-
}
|
|
10
|
-
function correctPaths(path) {
|
|
11
|
-
if (!path || path.length === 0) return ".";
|
|
12
|
-
path = normalizeWindowsPath(path);
|
|
13
|
-
const isUNCPath = path.match(UNC_REGEX);
|
|
14
|
-
const isPathAbsolute = isAbsolute(path);
|
|
15
|
-
const trailingSeparator = path[path.length - 1] === "/";
|
|
16
|
-
path = normalizeString(path, !isPathAbsolute);
|
|
17
|
-
if (path.length === 0) {
|
|
18
|
-
if (isPathAbsolute) return "/";
|
|
19
|
-
return trailingSeparator ? "./" : ".";
|
|
20
|
-
}
|
|
21
|
-
if (trailingSeparator) path += "/";
|
|
22
|
-
if (DRIVE_LETTER_REGEX.test(path)) path += "/";
|
|
23
|
-
if (isUNCPath) {
|
|
24
|
-
if (!isPathAbsolute) return `//./${path}`;
|
|
25
|
-
return `//${path}`;
|
|
26
|
-
}
|
|
27
|
-
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Joins all given path segments together using the platform-specific separator as a delimiter.
|
|
31
|
-
*
|
|
32
|
-
* @remarks
|
|
33
|
-
* Multiple segments can be provided as separate arguments. The resulting path is normalized to remove any redundant or unnecessary segments.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* import { joinPaths } from 'stryke/path';
|
|
38
|
-
*
|
|
39
|
-
* const fullPath = joinPaths('folder1', 'folder2', '..', 'folder3', 'file.txt');
|
|
40
|
-
* console.log(fullPath); // Output: 'folder1/folder3/file.txt'
|
|
41
|
-
*
|
|
42
|
-
* const absolutePath = joinPaths('/root', 'folder', '.', 'subfolder', 'file.txt');
|
|
43
|
-
* console.log(absolutePath); // Output: '/root/folder/subfolder/file.txt'
|
|
44
|
-
*
|
|
45
|
-
* const windowsPath = joinPaths('C:\\', 'Users', 'Public', '..', 'Documents', 'file.txt');
|
|
46
|
-
* console.log(windowsPath); // Output: 'C:/Users/Documents/file.txt'
|
|
47
|
-
*
|
|
48
|
-
* const uncPath = joinPaths('\\\\Server\\Share', 'Folder', 'File.txt');
|
|
49
|
-
* console.log(uncPath); // Output: '//Server/Share/Folder/File.txt'
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @param segments - The path segments to join.
|
|
53
|
-
* @returns The joined and normalized path string.
|
|
54
|
-
*/
|
|
55
|
-
function joinPaths(...segments) {
|
|
56
|
-
let result = "";
|
|
57
|
-
for (const segment of segments) if (segment && slash(segment).replaceAll(/\//g, "") !== ".") {
|
|
58
|
-
if (result) if (slash(segment).replaceAll(/\//g, "") === "..") result = slash(result).replace(/\/+$/, "").replace(/\/*[^/]+$/, "");
|
|
59
|
-
else result = `${slash(result).replace(/\/+$/, "")}/${slash(segment).replace(/^\/+/, "")}`;
|
|
60
|
-
else if (slash(segment).replaceAll(/\//g, "") !== "..") result = segment;
|
|
61
|
-
}
|
|
62
|
-
return correctPaths(result);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.
|
|
66
|
-
*
|
|
67
|
-
* @param path - The path to normalize.
|
|
68
|
-
* @param allowAboveRoot - Whether to allow the resulting path to be above the root directory.
|
|
69
|
-
* @returns the normalized path string.
|
|
70
|
-
*/
|
|
71
|
-
function normalizeString(path, allowAboveRoot) {
|
|
72
|
-
let res = "";
|
|
73
|
-
let lastSegmentLength = 0;
|
|
74
|
-
let lastSlash = -1;
|
|
75
|
-
let dots = 0;
|
|
76
|
-
let char = null;
|
|
77
|
-
for (let index = 0; index <= path.length; ++index) {
|
|
78
|
-
if (index < path.length) char = path[index];
|
|
79
|
-
else if (char === "/") break;
|
|
80
|
-
else char = "/";
|
|
81
|
-
if (char === "/") {
|
|
82
|
-
if (lastSlash === index - 1 || dots === 1) {} else if (dots === 2) {
|
|
83
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
84
|
-
if (res.length > 2) {
|
|
85
|
-
const lastSlashIndex = res.lastIndexOf("/");
|
|
86
|
-
if (lastSlashIndex === -1) {
|
|
87
|
-
res = "";
|
|
88
|
-
lastSegmentLength = 0;
|
|
89
|
-
} else {
|
|
90
|
-
res = res.slice(0, lastSlashIndex);
|
|
91
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
92
|
-
}
|
|
93
|
-
lastSlash = index;
|
|
94
|
-
dots = 0;
|
|
95
|
-
continue;
|
|
96
|
-
} else if (res.length > 0) {
|
|
97
|
-
res = "";
|
|
98
|
-
lastSegmentLength = 0;
|
|
99
|
-
lastSlash = index;
|
|
100
|
-
dots = 0;
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (allowAboveRoot) {
|
|
105
|
-
res += res.length > 0 ? "/.." : "..";
|
|
106
|
-
lastSegmentLength = 2;
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
|
|
110
|
-
else res = path.slice(lastSlash + 1, index);
|
|
111
|
-
lastSegmentLength = index - lastSlash - 1;
|
|
112
|
-
}
|
|
113
|
-
lastSlash = index;
|
|
114
|
-
dots = 0;
|
|
115
|
-
} else if (char === "." && dots !== -1) ++dots;
|
|
116
|
-
else dots = -1;
|
|
117
|
-
}
|
|
118
|
-
return res;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
//#endregion
|
|
122
|
-
export { joinPaths };
|
|
123
|
-
//# sourceMappingURL=join-paths.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"join-paths.mjs","names":["char: string | null"],"sources":["../../../../path/src/join-paths.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isAbsolute } from \"./is-type\";\nimport {\n DRIVE_LETTER_REGEX,\n DRIVE_LETTER_START_REGEX,\n UNC_REGEX\n} from \"./regex\";\nimport { slash } from \"./slash\";\n\n// Util to normalize windows paths to posix\nfunction normalizeWindowsPath(input = \"\") {\n if (!input) {\n return input;\n }\n return input\n .replace(/\\\\/g, \"/\")\n .replace(DRIVE_LETTER_START_REGEX, r => r.toUpperCase());\n}\n\nfunction correctPaths(path?: string) {\n if (!path || path.length === 0) {\n return \".\";\n }\n\n // Normalize windows argument\n path = normalizeWindowsPath(path);\n\n const isUNCPath = path.match(UNC_REGEX);\n const isPathAbsolute = isAbsolute(path);\n const trailingSeparator = path[path.length - 1] === \"/\";\n\n // Normalize the path\n path = normalizeString(path, !isPathAbsolute);\n\n if (path.length === 0) {\n if (isPathAbsolute) {\n return \"/\";\n }\n return trailingSeparator ? \"./\" : \".\";\n }\n if (trailingSeparator) {\n path += \"/\";\n }\n if (DRIVE_LETTER_REGEX.test(path)) {\n path += \"/\";\n }\n\n if (isUNCPath) {\n if (!isPathAbsolute) {\n return `//./${path}`;\n }\n return `//${path}`;\n }\n\n return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;\n}\n\n/**\n * Joins all given path segments together using the platform-specific separator as a delimiter.\n *\n * @remarks\n * Multiple segments can be provided as separate arguments. The resulting path is normalized to remove any redundant or unnecessary segments.\n *\n * @example\n * ```ts\n * import { joinPaths } from 'stryke/path';\n *\n * const fullPath = joinPaths('folder1', 'folder2', '..', 'folder3', 'file.txt');\n * console.log(fullPath); // Output: 'folder1/folder3/file.txt'\n *\n * const absolutePath = joinPaths('/root', 'folder', '.', 'subfolder', 'file.txt');\n * console.log(absolutePath); // Output: '/root/folder/subfolder/file.txt'\n *\n * const windowsPath = joinPaths('C:\\\\', 'Users', 'Public', '..', 'Documents', 'file.txt');\n * console.log(windowsPath); // Output: 'C:/Users/Documents/file.txt'\n *\n * const uncPath = joinPaths('\\\\\\\\Server\\\\Share', 'Folder', 'File.txt');\n * console.log(uncPath); // Output: '//Server/Share/Folder/File.txt'\n * ```\n *\n * @param segments - The path segments to join.\n * @returns The joined and normalized path string.\n */\nexport function joinPaths(...segments: string[]): string {\n let result = \"\";\n for (const segment of segments) {\n if (segment && slash(segment).replaceAll(/\\//g, \"\") !== \".\") {\n if (result) {\n if (slash(segment).replaceAll(/\\//g, \"\") === \"..\") {\n result = slash(result)\n .replace(/\\/+$/, \"\")\n .replace(/\\/*[^/]+$/, \"\");\n } else {\n result = `${slash(result).replace(/\\/+$/, \"\")}/${slash(\n segment\n ).replace(/^\\/+/, \"\")}`;\n }\n } else if (slash(segment).replaceAll(/\\//g, \"\") !== \"..\") {\n result = segment;\n }\n }\n }\n\n return correctPaths(result);\n}\n\nexport const join = joinPaths;\n\n/**\n * Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.\n *\n * @param path - The path to normalize.\n * @param allowAboveRoot - Whether to allow the resulting path to be above the root directory.\n * @returns the normalized path string.\n */\nfunction normalizeString(path: string, allowAboveRoot: boolean) {\n let res = \"\";\n let lastSegmentLength = 0;\n let lastSlash = -1;\n let dots = 0;\n let char: string | null = null;\n for (let index = 0; index <= path.length; ++index) {\n if (index < path.length) {\n // casted because we know it exists thanks to the length check\n char = path[index] as string;\n } else if (char === \"/\") {\n break;\n } else {\n char = \"/\";\n }\n if (char === \"/\") {\n if (lastSlash === index - 1 || dots === 1) {\n // NOOP\n } else if (dots === 2) {\n if (\n res.length < 2 ||\n lastSegmentLength !== 2 ||\n res[res.length - 1] !== \".\" ||\n res[res.length - 2] !== \".\"\n ) {\n if (res.length > 2) {\n const lastSlashIndex = res.lastIndexOf(\"/\");\n if (lastSlashIndex === -1) {\n res = \"\";\n lastSegmentLength = 0;\n } else {\n res = res.slice(0, lastSlashIndex);\n lastSegmentLength = res.length - 1 - res.lastIndexOf(\"/\");\n }\n lastSlash = index;\n dots = 0;\n continue;\n } else if (res.length > 0) {\n res = \"\";\n lastSegmentLength = 0;\n lastSlash = index;\n dots = 0;\n continue;\n }\n }\n if (allowAboveRoot) {\n res += res.length > 0 ? \"/..\" : \"..\";\n lastSegmentLength = 2;\n }\n } else {\n if (res.length > 0) {\n res += `/${path.slice(lastSlash + 1, index)}`;\n } else {\n res = path.slice(lastSlash + 1, index);\n }\n lastSegmentLength = index - lastSlash - 1;\n }\n lastSlash = index;\n dots = 0;\n } else if (char === \".\" && dots !== -1) {\n ++dots;\n } else {\n dots = -1;\n }\n }\n return res;\n}\n"],"mappings":";;;;;AA2BA,SAAS,qBAAqB,QAAQ,IAAI;AACxC,KAAI,CAAC,MACH,QAAO;AAET,QAAO,MACJ,QAAQ,OAAO,IAAI,CACnB,QAAQ,2BAA0B,MAAK,EAAE,aAAa,CAAC;;AAG5D,SAAS,aAAa,MAAe;AACnC,KAAI,CAAC,QAAQ,KAAK,WAAW,EAC3B,QAAO;AAIT,QAAO,qBAAqB,KAAK;CAEjC,MAAM,YAAY,KAAK,MAAM,UAAU;CACvC,MAAM,iBAAiB,WAAW,KAAK;CACvC,MAAM,oBAAoB,KAAK,KAAK,SAAS,OAAO;AAGpD,QAAO,gBAAgB,MAAM,CAAC,eAAe;AAE7C,KAAI,KAAK,WAAW,GAAG;AACrB,MAAI,eACF,QAAO;AAET,SAAO,oBAAoB,OAAO;;AAEpC,KAAI,kBACF,SAAQ;AAEV,KAAI,mBAAmB,KAAK,KAAK,CAC/B,SAAQ;AAGV,KAAI,WAAW;AACb,MAAI,CAAC,eACH,QAAO,OAAO;AAEhB,SAAO,KAAK;;AAGd,QAAO,kBAAkB,CAAC,WAAW,KAAK,GAAG,IAAI,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6B5D,SAAgB,UAAU,GAAG,UAA4B;CACvD,IAAI,SAAS;AACb,MAAK,MAAM,WAAW,SACpB,KAAI,WAAW,MAAM,QAAQ,CAAC,WAAW,OAAO,GAAG,KAAK,KACtD;MAAI,OACF,KAAI,MAAM,QAAQ,CAAC,WAAW,OAAO,GAAG,KAAK,KAC3C,UAAS,MAAM,OAAO,CACnB,QAAQ,QAAQ,GAAG,CACnB,QAAQ,aAAa,GAAG;MAE3B,UAAS,GAAG,MAAM,OAAO,CAAC,QAAQ,QAAQ,GAAG,CAAC,GAAG,MAC/C,QACD,CAAC,QAAQ,QAAQ,GAAG;WAEd,MAAM,QAAQ,CAAC,WAAW,OAAO,GAAG,KAAK,KAClD,UAAS;;AAKf,QAAO,aAAa,OAAO;;;;;;;;;AAY7B,SAAS,gBAAgB,MAAc,gBAAyB;CAC9D,IAAI,MAAM;CACV,IAAI,oBAAoB;CACxB,IAAI,YAAY;CAChB,IAAI,OAAO;CACX,IAAIA,OAAsB;AAC1B,MAAK,IAAI,QAAQ,GAAG,SAAS,KAAK,QAAQ,EAAE,OAAO;AACjD,MAAI,QAAQ,KAAK,OAEf,QAAO,KAAK;WACH,SAAS,IAClB;MAEA,QAAO;AAET,MAAI,SAAS,KAAK;AAChB,OAAI,cAAc,QAAQ,KAAK,SAAS,GAAG,YAEhC,SAAS,GAAG;AACrB,QACE,IAAI,SAAS,KACb,sBAAsB,KACtB,IAAI,IAAI,SAAS,OAAO,OACxB,IAAI,IAAI,SAAS,OAAO,KAExB;SAAI,IAAI,SAAS,GAAG;MAClB,MAAM,iBAAiB,IAAI,YAAY,IAAI;AAC3C,UAAI,mBAAmB,IAAI;AACzB,aAAM;AACN,2BAAoB;aACf;AACL,aAAM,IAAI,MAAM,GAAG,eAAe;AAClC,2BAAoB,IAAI,SAAS,IAAI,IAAI,YAAY,IAAI;;AAE3D,kBAAY;AACZ,aAAO;AACP;gBACS,IAAI,SAAS,GAAG;AACzB,YAAM;AACN,0BAAoB;AACpB,kBAAY;AACZ,aAAO;AACP;;;AAGJ,QAAI,gBAAgB;AAClB,YAAO,IAAI,SAAS,IAAI,QAAQ;AAChC,yBAAoB;;UAEjB;AACL,QAAI,IAAI,SAAS,EACf,QAAO,IAAI,KAAK,MAAM,YAAY,GAAG,MAAM;QAE3C,OAAM,KAAK,MAAM,YAAY,GAAG,MAAM;AAExC,wBAAoB,QAAQ,YAAY;;AAE1C,eAAY;AACZ,UAAO;aACE,SAAS,OAAO,SAAS,GAClC,GAAE;MAEF,QAAO;;AAGX,QAAO"}
|
package/dist/path/src/regex.cjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region ../path/src/regex.ts
|
|
3
|
-
const DRIVE_LETTER_START_REGEX = /^[A-Z]:\//i;
|
|
4
|
-
const DRIVE_LETTER_REGEX = /^[A-Z]:$/i;
|
|
5
|
-
const UNC_REGEX = /^[/\\]{2}/;
|
|
6
|
-
const ABSOLUTE_PATH_REGEX = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i;
|
|
7
|
-
const ROOT_FOLDER_REGEX = /^\/([A-Z]:)?$/i;
|
|
8
|
-
const FILE_EXTENSION_REGEX = /\.[0-9a-z]+$/i;
|
|
9
|
-
const FULL_FILE_EXTENSION_REGEX = /(\.d)?\.[0-9a-z]+(\.map)?$/i;
|
|
10
|
-
const NPM_SCOPED_PACKAGE_REGEX = /^(?:@[\w-]+\/)?[\w-]+$/;
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
|
-
exports.ABSOLUTE_PATH_REGEX = ABSOLUTE_PATH_REGEX;
|
|
14
|
-
exports.DRIVE_LETTER_REGEX = DRIVE_LETTER_REGEX;
|
|
15
|
-
exports.DRIVE_LETTER_START_REGEX = DRIVE_LETTER_START_REGEX;
|
|
16
|
-
exports.FILE_EXTENSION_REGEX = FILE_EXTENSION_REGEX;
|
|
17
|
-
exports.FULL_FILE_EXTENSION_REGEX = FULL_FILE_EXTENSION_REGEX;
|
|
18
|
-
exports.NPM_SCOPED_PACKAGE_REGEX = NPM_SCOPED_PACKAGE_REGEX;
|
|
19
|
-
exports.ROOT_FOLDER_REGEX = ROOT_FOLDER_REGEX;
|
|
20
|
-
exports.UNC_REGEX = UNC_REGEX;
|
package/dist/path/src/regex.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//#region ../path/src/regex.ts
|
|
2
|
-
const DRIVE_LETTER_START_REGEX = /^[A-Z]:\//i;
|
|
3
|
-
const DRIVE_LETTER_REGEX = /^[A-Z]:$/i;
|
|
4
|
-
const UNC_REGEX = /^[/\\]{2}/;
|
|
5
|
-
const ABSOLUTE_PATH_REGEX = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i;
|
|
6
|
-
const ROOT_FOLDER_REGEX = /^\/([A-Z]:)?$/i;
|
|
7
|
-
const FILE_EXTENSION_REGEX = /\.[0-9a-z]+$/i;
|
|
8
|
-
const FULL_FILE_EXTENSION_REGEX = /(\.d)?\.[0-9a-z]+(\.map)?$/i;
|
|
9
|
-
const NPM_SCOPED_PACKAGE_REGEX = /^(?:@[\w-]+\/)?[\w-]+$/;
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
export { ABSOLUTE_PATH_REGEX, DRIVE_LETTER_REGEX, DRIVE_LETTER_START_REGEX, FILE_EXTENSION_REGEX, FULL_FILE_EXTENSION_REGEX, NPM_SCOPED_PACKAGE_REGEX, ROOT_FOLDER_REGEX, UNC_REGEX };
|
|
13
|
-
//# sourceMappingURL=regex.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"regex.mjs","names":[],"sources":["../../../../path/src/regex.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nexport const DRIVE_LETTER_START_REGEX = /^[A-Z]:\\//i;\nexport const DRIVE_LETTER_REGEX = /^[A-Z]:$/i;\n\nexport const UNC_REGEX = /^[/\\\\]{2}/;\n\nexport const ABSOLUTE_PATH_REGEX =\n /^[/\\\\](?![/\\\\])|^[/\\\\]{2}(?!\\.)|^~[/\\\\]|^[A-Z]:[/\\\\]/i;\n\nexport const ROOT_FOLDER_REGEX = /^\\/([A-Z]:)?$/i;\n\nexport const FILE_EXTENSION_REGEX = /\\.[0-9a-z]+$/i;\nexport const FULL_FILE_EXTENSION_REGEX = /(\\.d)?\\.[0-9a-z]+(\\.map)?$/i;\n\nexport const PACKAGE_PATH_REGEX = /^@\\w+\\/.*$/;\nexport const NPM_SCOPED_PACKAGE_REGEX = /^(?:@[\\w-]+\\/)?[\\w-]+$/;\n"],"mappings":";AAkBA,MAAa,2BAA2B;AACxC,MAAa,qBAAqB;AAElC,MAAa,YAAY;AAEzB,MAAa,sBACX;AAEF,MAAa,oBAAoB;AAEjC,MAAa,uBAAuB;AACpC,MAAa,4BAA4B;AAGzC,MAAa,2BAA2B"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const require_cwd = require('./cwd.cjs');
|
|
2
|
-
const require_slash = require('./slash.cjs');
|
|
3
|
-
const require_is_parent_path = require('./is-parent-path.cjs');
|
|
4
|
-
|
|
5
|
-
//#region ../path/src/replace.ts
|
|
6
|
-
/**
|
|
7
|
-
* Replace the base path from the beginning of the given path.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* replacePath("/home/user/project/src/index.ts", "/home/user/project");
|
|
12
|
-
* // returns "src/index.ts"
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* @param childPath - The child path to replace the {@link parentPath} substring from
|
|
16
|
-
* @param parentPath - The parent path to remove from the {@link childPath} parameter
|
|
17
|
-
* @returns The {@link childPath} with the {@link parentPath} path removed
|
|
18
|
-
*/
|
|
19
|
-
function replacePath(childPath, parentPath = require_cwd.cwd()) {
|
|
20
|
-
return require_is_parent_path.isParentPath(childPath, parentPath) ? require_slash.slash(childPath).replace(require_slash.slash(parentPath), "").replace(/^\//, "") : childPath;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
exports.replacePath = replacePath;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { cwd } from "./cwd.mjs";
|
|
2
|
-
import { slash } from "./slash.mjs";
|
|
3
|
-
import { isParentPath } from "./is-parent-path.mjs";
|
|
4
|
-
|
|
5
|
-
//#region ../path/src/replace.ts
|
|
6
|
-
/**
|
|
7
|
-
* Replace the base path from the beginning of the given path.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* replacePath("/home/user/project/src/index.ts", "/home/user/project");
|
|
12
|
-
* // returns "src/index.ts"
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* @param childPath - The child path to replace the {@link parentPath} substring from
|
|
16
|
-
* @param parentPath - The parent path to remove from the {@link childPath} parameter
|
|
17
|
-
* @returns The {@link childPath} with the {@link parentPath} path removed
|
|
18
|
-
*/
|
|
19
|
-
function replacePath(childPath, parentPath = cwd()) {
|
|
20
|
-
return isParentPath(childPath, parentPath) ? slash(childPath).replace(slash(parentPath), "").replace(/^\//, "") : childPath;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
export { replacePath };
|
|
25
|
-
//# sourceMappingURL=replace.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"replace.mjs","names":[],"sources":["../../../../path/src/replace.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { cwd } from \"./cwd\";\nimport type { FindFileExtensionOptions } from \"./file-path-fns\";\nimport {\n findFileDotExtensionSafe,\n findFileExtensionSafe\n} from \"./file-path-fns\";\nimport { isParentPath } from \"./is-parent-path\";\nimport { slash } from \"./slash\";\n\n/**\n * Replace the base path from the beginning of the given path.\n *\n * @example\n * ```ts\n * replacePath(\"/home/user/project/src/index.ts\", \"/home/user/project\");\n * // returns \"src/index.ts\"\n * ```\n *\n * @param childPath - The child path to replace the {@link parentPath} substring from\n * @param parentPath - The parent path to remove from the {@link childPath} parameter\n * @returns The {@link childPath} with the {@link parentPath} path removed\n */\nexport function replacePath(\n childPath: string,\n parentPath: string = cwd()\n): string {\n return isParentPath(childPath, parentPath)\n ? slash(childPath).replace(slash(parentPath), \"\").replace(/^\\//, \"\")\n : childPath;\n}\n\n/**\n * Replace the extension of a given path with the provided value.\n *\n * @example\n * ```ts\n * replaceExtension(\"/home/user/project/src/index.ts\", \".js\");\n * // returns \"/home/user/project/src/index.js\"\n * replaceExtension(\"/home/user/project/src/index.ts\");\n * // returns \"/home/user/project/src/index\"\n * ```\n *\n * @param path - The path that will have its current extension replaced\n * @param replacement - The value (or an empty string) to replace the current extension with\n * @returns The path with the replaced extension\n */\nexport function replaceExtension(\n path: string,\n replacement = \"\",\n options?: FindFileExtensionOptions\n): string {\n return path.replace(\n !replacement || replacement.includes(\".\")\n ? findFileDotExtensionSafe(path, options)\n : findFileExtensionSafe(path, options),\n replacement\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwCA,SAAgB,YACd,WACA,aAAqB,KAAK,EAClB;AACR,QAAO,aAAa,WAAW,WAAW,GACtC,MAAM,UAAU,CAAC,QAAQ,MAAM,WAAW,EAAE,GAAG,CAAC,QAAQ,OAAO,GAAG,GAClE"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const require_join_paths = require('./join-paths.cjs');
|
|
2
|
-
|
|
3
|
-
//#region ../path/src/resolve-parent-path.ts
|
|
4
|
-
/**
|
|
5
|
-
* Resolve the parent path of the provided path.
|
|
6
|
-
*
|
|
7
|
-
* @param path - The path to resolve.
|
|
8
|
-
* @param count - The number of parent directories to traverse.
|
|
9
|
-
* @returns The parent path of the provided path.
|
|
10
|
-
*/
|
|
11
|
-
const resolveParentPath = (path, count = 1) => {
|
|
12
|
-
let parentPath = path.replaceAll(/\/+$/g, "");
|
|
13
|
-
for (let i = 0; i < count; i++) parentPath = require_join_paths.joinPaths(parentPath, "..");
|
|
14
|
-
return parentPath;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
exports.resolveParentPath = resolveParentPath;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { joinPaths } from "./join-paths.mjs";
|
|
2
|
-
|
|
3
|
-
//#region ../path/src/resolve-parent-path.ts
|
|
4
|
-
/**
|
|
5
|
-
* Resolve the parent path of the provided path.
|
|
6
|
-
*
|
|
7
|
-
* @param path - The path to resolve.
|
|
8
|
-
* @param count - The number of parent directories to traverse.
|
|
9
|
-
* @returns The parent path of the provided path.
|
|
10
|
-
*/
|
|
11
|
-
const resolveParentPath = (path, count = 1) => {
|
|
12
|
-
let parentPath = path.replaceAll(/\/+$/g, "");
|
|
13
|
-
for (let i = 0; i < count; i++) parentPath = joinPaths(parentPath, "..");
|
|
14
|
-
return parentPath;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
export { resolveParentPath };
|
|
19
|
-
//# sourceMappingURL=resolve-parent-path.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-parent-path.mjs","names":[],"sources":["../../../../path/src/resolve-parent-path.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { joinPaths } from \"./join-paths\";\n\n/**\n * Resolve the parent path of the provided path.\n *\n * @param path - The path to resolve.\n * @param count - The number of parent directories to traverse.\n * @returns The parent path of the provided path.\n */\nexport const resolveParentPath = (path: string, count: number = 1): string => {\n let parentPath = path.replaceAll(/\\/+$/g, \"\");\n for (let i = 0; i < count; i++) {\n parentPath = joinPaths(parentPath, \"..\");\n }\n return parentPath;\n};\n"],"mappings":";;;;;;;;;;AA2BA,MAAa,qBAAqB,MAAc,QAAgB,MAAc;CAC5E,IAAI,aAAa,KAAK,WAAW,SAAS,GAAG;AAC7C,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,IACzB,cAAa,UAAU,YAAY,KAAK;AAE1C,QAAO"}
|
package/dist/path/src/slash.cjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region ../path/src/slash.ts
|
|
3
|
-
/**
|
|
4
|
-
* Replace backslash to slash
|
|
5
|
-
*
|
|
6
|
-
* @param path - The string to replace
|
|
7
|
-
* @returns The string with replaced backslashes
|
|
8
|
-
*/
|
|
9
|
-
function slash(path) {
|
|
10
|
-
if (path.startsWith("\\\\?\\")) return path;
|
|
11
|
-
return path.replace(/\\/g, "/");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
//#endregion
|
|
15
|
-
exports.slash = slash;
|
package/dist/path/src/slash.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//#region ../path/src/slash.ts
|
|
2
|
-
/**
|
|
3
|
-
* Replace backslash to slash
|
|
4
|
-
*
|
|
5
|
-
* @param path - The string to replace
|
|
6
|
-
* @returns The string with replaced backslashes
|
|
7
|
-
*/
|
|
8
|
-
function slash(path) {
|
|
9
|
-
if (path.startsWith("\\\\?\\")) return path;
|
|
10
|
-
return path.replace(/\\/g, "/");
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
//#endregion
|
|
14
|
-
export { slash };
|
|
15
|
-
//# sourceMappingURL=slash.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"slash.mjs","names":[],"sources":["../../../../path/src/slash.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isAbsolutePath } from \"./is-type\";\n\n/**\n * Replace backslash to slash\n *\n * @param path - The string to replace\n * @returns The string with replaced backslashes\n */\nexport function slash(path: string) {\n if (path.startsWith(\"\\\\\\\\?\\\\\")) {\n return path;\n }\n\n return path.replace(/\\\\/g, \"/\");\n}\n\n/**\n * Replace backslash to slash and remove unneeded leading and trailing slashes\n *\n * @param path - The string to replace\n * @returns The string with replaced backslashes\n */\nexport function formatSlash(path: string) {\n const formatted = slash(path);\n\n return isAbsolutePath(formatted)\n ? formatted.replace(/\\/+$/g, \"\")\n : formatted.replace(/^\\.\\//g, \"\").replace(/\\/+$/g, \"\");\n}\n"],"mappings":";;;;;;;AA0BA,SAAgB,MAAM,MAAc;AAClC,KAAI,KAAK,WAAW,UAAU,CAC5B,QAAO;AAGT,QAAO,KAAK,QAAQ,OAAO,IAAI"}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region ../string-format/src/package.ts
|
|
3
|
-
/**
|
|
4
|
-
* Check if a package name has a version
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```typescript
|
|
8
|
-
* hasPackageVersion("lodash@4.17.21");
|
|
9
|
-
* // => true
|
|
10
|
-
* hasPackageVersion("@stryke/core@4.17.21");
|
|
11
|
-
* // => true
|
|
12
|
-
* hasPackageVersion("lodash");
|
|
13
|
-
* // => false
|
|
14
|
-
* hasPackageVersion("@stryke/core");
|
|
15
|
-
* // => false
|
|
16
|
-
* hasPackageVersion("lodash/module");
|
|
17
|
-
* // => false
|
|
18
|
-
* hasPackageVersion("@stryke/core/module");
|
|
19
|
-
* // => false
|
|
20
|
-
* hasPackageVersion("lodash/module@4.17.21");
|
|
21
|
-
* // => true
|
|
22
|
-
* hasPackageVersion("@stryke/core/module@4.17.21");
|
|
23
|
-
* // => true
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @param value - The package name with version
|
|
27
|
-
* @returns Whether the package name has a version
|
|
28
|
-
*/
|
|
29
|
-
function hasPackageVersion(value) {
|
|
30
|
-
return /^.[^\n\r@\u2028\u2029]*@.*$/.test(value);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Remove the version from a package name (if it exists)
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```typescript
|
|
37
|
-
* removePackageVersion("lodash@4.17.21");
|
|
38
|
-
* // => "lodash"
|
|
39
|
-
* removePackageVersion("@stryke/core@4.17.21");
|
|
40
|
-
* // => "@stryke/core"
|
|
41
|
-
* removePackageVersion("lodash");
|
|
42
|
-
* // => "lodash"
|
|
43
|
-
* removePackageVersion("@stryke/core");
|
|
44
|
-
* // => "@stryke/core"
|
|
45
|
-
* getPackageName("lodash/module");
|
|
46
|
-
* // => "lodash/module"
|
|
47
|
-
* getPackageName("@stryke/core/module");
|
|
48
|
-
* // => "@stryke/core/module"
|
|
49
|
-
* getPackageName("lodash/module@4.17.21");
|
|
50
|
-
* // => "lodash/module"
|
|
51
|
-
* getPackageName("@stryke/core/module@4.17.21");
|
|
52
|
-
* // => "@stryke/core/module"
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* @param value - The package name with version
|
|
56
|
-
* @returns The package name without version
|
|
57
|
-
*/
|
|
58
|
-
function removePackageVersion(value) {
|
|
59
|
-
return hasPackageVersion(value) ? value.substring(0, value.lastIndexOf("@")) : value;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Get the package name from a scoped package string
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* getPackageName("lodash@4.17.21");
|
|
67
|
-
* // => "lodash"
|
|
68
|
-
* getPackageName("@stryke/core@4.17.21");
|
|
69
|
-
* // => "@stryke/core"
|
|
70
|
-
* getPackageName("lodash");
|
|
71
|
-
* // => "lodash"
|
|
72
|
-
* getPackageName("@stryke/core");
|
|
73
|
-
* // => "@stryke/core"
|
|
74
|
-
* getPackageName("lodash/module");
|
|
75
|
-
* // => "lodash"
|
|
76
|
-
* getPackageName("@stryke/core/module");
|
|
77
|
-
* // => "@stryke/core"
|
|
78
|
-
* getPackageName("lodash/module@4.17.21");
|
|
79
|
-
* // => "lodash"
|
|
80
|
-
* getPackageName("@stryke/core/module@4.17.21");
|
|
81
|
-
* // => "@stryke/core"
|
|
82
|
-
* ```
|
|
83
|
-
*
|
|
84
|
-
* @param value - The scoped package string
|
|
85
|
-
* @returns The package name without the scope
|
|
86
|
-
*/
|
|
87
|
-
function getPackageName(value) {
|
|
88
|
-
return /^[^\n\r/\u2028\u2029]*\/.[^\n\r/\u2028\u2029]*\/.*$/.test(value) ? value.substring(0, value.lastIndexOf("/")) : removePackageVersion(value);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
//#endregion
|
|
92
|
-
exports.getPackageName = getPackageName;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
//#region ../string-format/src/package.ts
|
|
2
|
-
/**
|
|
3
|
-
* Check if a package name has a version
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* ```typescript
|
|
7
|
-
* hasPackageVersion("lodash@4.17.21");
|
|
8
|
-
* // => true
|
|
9
|
-
* hasPackageVersion("@stryke/core@4.17.21");
|
|
10
|
-
* // => true
|
|
11
|
-
* hasPackageVersion("lodash");
|
|
12
|
-
* // => false
|
|
13
|
-
* hasPackageVersion("@stryke/core");
|
|
14
|
-
* // => false
|
|
15
|
-
* hasPackageVersion("lodash/module");
|
|
16
|
-
* // => false
|
|
17
|
-
* hasPackageVersion("@stryke/core/module");
|
|
18
|
-
* // => false
|
|
19
|
-
* hasPackageVersion("lodash/module@4.17.21");
|
|
20
|
-
* // => true
|
|
21
|
-
* hasPackageVersion("@stryke/core/module@4.17.21");
|
|
22
|
-
* // => true
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* @param value - The package name with version
|
|
26
|
-
* @returns Whether the package name has a version
|
|
27
|
-
*/
|
|
28
|
-
function hasPackageVersion(value) {
|
|
29
|
-
return /^.[^\n\r@\u2028\u2029]*@.*$/.test(value);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Remove the version from a package name (if it exists)
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```typescript
|
|
36
|
-
* removePackageVersion("lodash@4.17.21");
|
|
37
|
-
* // => "lodash"
|
|
38
|
-
* removePackageVersion("@stryke/core@4.17.21");
|
|
39
|
-
* // => "@stryke/core"
|
|
40
|
-
* removePackageVersion("lodash");
|
|
41
|
-
* // => "lodash"
|
|
42
|
-
* removePackageVersion("@stryke/core");
|
|
43
|
-
* // => "@stryke/core"
|
|
44
|
-
* getPackageName("lodash/module");
|
|
45
|
-
* // => "lodash/module"
|
|
46
|
-
* getPackageName("@stryke/core/module");
|
|
47
|
-
* // => "@stryke/core/module"
|
|
48
|
-
* getPackageName("lodash/module@4.17.21");
|
|
49
|
-
* // => "lodash/module"
|
|
50
|
-
* getPackageName("@stryke/core/module@4.17.21");
|
|
51
|
-
* // => "@stryke/core/module"
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* @param value - The package name with version
|
|
55
|
-
* @returns The package name without version
|
|
56
|
-
*/
|
|
57
|
-
function removePackageVersion(value) {
|
|
58
|
-
return hasPackageVersion(value) ? value.substring(0, value.lastIndexOf("@")) : value;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Get the package name from a scoped package string
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```typescript
|
|
65
|
-
* getPackageName("lodash@4.17.21");
|
|
66
|
-
* // => "lodash"
|
|
67
|
-
* getPackageName("@stryke/core@4.17.21");
|
|
68
|
-
* // => "@stryke/core"
|
|
69
|
-
* getPackageName("lodash");
|
|
70
|
-
* // => "lodash"
|
|
71
|
-
* getPackageName("@stryke/core");
|
|
72
|
-
* // => "@stryke/core"
|
|
73
|
-
* getPackageName("lodash/module");
|
|
74
|
-
* // => "lodash"
|
|
75
|
-
* getPackageName("@stryke/core/module");
|
|
76
|
-
* // => "@stryke/core"
|
|
77
|
-
* getPackageName("lodash/module@4.17.21");
|
|
78
|
-
* // => "lodash"
|
|
79
|
-
* getPackageName("@stryke/core/module@4.17.21");
|
|
80
|
-
* // => "@stryke/core"
|
|
81
|
-
* ```
|
|
82
|
-
*
|
|
83
|
-
* @param value - The scoped package string
|
|
84
|
-
* @returns The package name without the scope
|
|
85
|
-
*/
|
|
86
|
-
function getPackageName(value) {
|
|
87
|
-
return /^[^\n\r/\u2028\u2029]*\/.[^\n\r/\u2028\u2029]*\/.*$/.test(value) ? value.substring(0, value.lastIndexOf("/")) : removePackageVersion(value);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
//#endregion
|
|
91
|
-
export { getPackageName };
|
|
92
|
-
//# sourceMappingURL=package.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"package.mjs","names":[],"sources":["../../../../string-format/src/package.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Check if a package name has a version\n *\n * @example\n * ```typescript\n * hasPackageVersion(\"lodash@4.17.21\");\n * // => true\n * hasPackageVersion(\"@stryke/core@4.17.21\");\n * // => true\n * hasPackageVersion(\"lodash\");\n * // => false\n * hasPackageVersion(\"@stryke/core\");\n * // => false\n * hasPackageVersion(\"lodash/module\");\n * // => false\n * hasPackageVersion(\"@stryke/core/module\");\n * // => false\n * hasPackageVersion(\"lodash/module@4.17.21\");\n * // => true\n * hasPackageVersion(\"@stryke/core/module@4.17.21\");\n * // => true\n * ```\n *\n * @param value - The package name with version\n * @returns Whether the package name has a version\n */\nexport function hasPackageVersion(value: string): boolean {\n return /^.[^\\n\\r@\\u2028\\u2029]*@.*$/.test(value);\n}\n\n/**\n * Remove the version from a package name (if it exists)\n *\n * @example\n * ```typescript\n * removePackageVersion(\"lodash@4.17.21\");\n * // => \"lodash\"\n * removePackageVersion(\"@stryke/core@4.17.21\");\n * // => \"@stryke/core\"\n * removePackageVersion(\"lodash\");\n * // => \"lodash\"\n * removePackageVersion(\"@stryke/core\");\n * // => \"@stryke/core\"\n * getPackageName(\"lodash/module\");\n * // => \"lodash/module\"\n * getPackageName(\"@stryke/core/module\");\n * // => \"@stryke/core/module\"\n * getPackageName(\"lodash/module@4.17.21\");\n * // => \"lodash/module\"\n * getPackageName(\"@stryke/core/module@4.17.21\");\n * // => \"@stryke/core/module\"\n * ```\n *\n * @param value - The package name with version\n * @returns The package name without version\n */\nexport function removePackageVersion(value: string) {\n return hasPackageVersion(value)\n ? value.substring(0, value.lastIndexOf(\"@\"))\n : value;\n}\n\n/**\n * Get the package name from a scoped package string\n *\n * @example\n * ```typescript\n * getPackageName(\"lodash@4.17.21\");\n * // => \"lodash\"\n * getPackageName(\"@stryke/core@4.17.21\");\n * // => \"@stryke/core\"\n * getPackageName(\"lodash\");\n * // => \"lodash\"\n * getPackageName(\"@stryke/core\");\n * // => \"@stryke/core\"\n * getPackageName(\"lodash/module\");\n * // => \"lodash\"\n * getPackageName(\"@stryke/core/module\");\n * // => \"@stryke/core\"\n * getPackageName(\"lodash/module@4.17.21\");\n * // => \"lodash\"\n * getPackageName(\"@stryke/core/module@4.17.21\");\n * // => \"@stryke/core\"\n * ```\n *\n * @param value - The scoped package string\n * @returns The package name without the scope\n */\nexport function getPackageName(value: string) {\n return /^[^\\n\\r/\\u2028\\u2029]*\\/.[^\\n\\r/\\u2028\\u2029]*\\/.*$/.test(value)\n ? value.substring(0, value.lastIndexOf(\"/\"))\n : removePackageVersion(value);\n}\n\n/**\n * Get the package version from a scoped package string\n *\n * @example\n * ```typescript\n * getPackageName(\"lodash@4.17.21\");\n * // => \"4.17.21\"\n * getPackageName(\"@stryke/core@4.17.21\");\n * // => \"4.17.21\"\n * getPackageName(\"lodash\");\n * // => undefined\n * getPackageName(\"@stryke/core\");\n * // => undefined\n * getPackageName(\"lodash/module\");\n * // => undefined\n * getPackageName(\"@stryke/core/module\");\n * // => undefined\n * getPackageName(\"lodash/module@4.17.21\");\n * // => \"4.17.21\"\n * getPackageName(\"@stryke/core/module@4.17.21\");\n * // => \"4.17.21\"\n * ```\n *\n * @param value - The scoped package string\n * @returns The package version without the package name if it exists. If not, returns undefined.\n */\nexport function getPackageVersion(value: string): string | undefined {\n return hasPackageVersion(value) ? value.replace(/^.+@/, \"\") : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,SAAgB,kBAAkB,OAAwB;AACxD,QAAO,8BAA8B,KAAK,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BlD,SAAgB,qBAAqB,OAAe;AAClD,QAAO,kBAAkB,MAAM,GAC3B,MAAM,UAAU,GAAG,MAAM,YAAY,IAAI,CAAC,GAC1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BN,SAAgB,eAAe,OAAe;AAC5C,QAAO,sDAAsD,KAAK,MAAM,GACpE,MAAM,UAAU,GAAG,MAAM,YAAY,IAAI,CAAC,GAC1C,qBAAqB,MAAM"}
|