@stryke/path 0.25.0 → 0.25.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/CHANGELOG.md +7 -0
- package/dist/append.cjs +59 -1
- package/dist/append.mjs +57 -1
- package/dist/append.mjs.map +1 -1
- package/dist/asset-extensions.cjs +40 -1
- package/dist/asset-extensions.mjs +39 -1
- package/dist/asset-extensions.mjs.map +1 -1
- package/dist/common.cjs +34 -1
- package/dist/common.mjs +34 -1
- package/dist/common.mjs.map +1 -1
- package/dist/correct-path.cjs +176 -1
- package/dist/correct-path.mjs +169 -1
- package/dist/correct-path.mjs.map +1 -1
- package/dist/cwd.cjs +17 -1
- package/dist/cwd.mjs +16 -1
- package/dist/cwd.mjs.map +1 -1
- package/dist/delimiter.cjs +27 -1
- package/dist/delimiter.mjs +24 -1
- package/dist/delimiter.mjs.map +1 -1
- package/dist/file-path-fns.cjs +332 -1
- package/dist/file-path-fns.mjs +311 -1
- package/dist/file-path-fns.mjs.map +1 -1
- package/dist/find.cjs +24 -1
- package/dist/find.mjs +3 -1
- package/dist/glob-to-regex.cjs +97 -1
- package/dist/glob-to-regex.mjs +97 -1
- package/dist/glob-to-regex.mjs.map +1 -1
- package/dist/index.cjs +73 -1
- package/dist/index.mjs +17 -1
- package/dist/is-parent-path.cjs +32 -1
- package/dist/is-parent-path.mjs +32 -1
- package/dist/is-parent-path.mjs.map +1 -1
- package/dist/is-root-dir.cjs +14 -1
- package/dist/is-root-dir.mjs +13 -1
- package/dist/is-root-dir.mjs.map +1 -1
- package/dist/is-type.cjs +92 -1
- package/dist/is-type.mjs +87 -1
- package/dist/is-type.mjs.map +1 -1
- package/dist/join-paths.cjs +108 -1
- package/dist/join-paths.mjs +107 -1
- package/dist/join-paths.mjs.map +1 -1
- package/dist/join.cjs +4 -1
- package/dist/join.mjs +3 -1
- package/dist/normalize.cjs +10 -1
- package/dist/normalize.mjs +3 -1
- package/dist/regex.cjs +20 -1
- package/dist/regex.mjs +12 -1
- package/dist/regex.mjs.map +1 -1
- package/dist/replace.cjs +44 -1
- package/dist/replace.mjs +43 -1
- package/dist/replace.mjs.map +1 -1
- package/dist/resolve-parent-path.cjs +18 -1
- package/dist/resolve-parent-path.mjs +18 -1
- package/dist/resolve-parent-path.mjs.map +1 -1
- package/dist/slash.cjs +27 -1
- package/dist/slash.mjs +26 -1
- package/dist/slash.mjs.map +1 -1
- package/dist/type-checks/src/is-empty.cjs +20 -1
- package/dist/type-checks/src/is-empty.mjs +20 -1
- package/dist/type-checks/src/is-empty.mjs.map +1 -1
- package/dist/type-checks/src/is-null.cjs +12 -1
- package/dist/type-checks/src/is-null.mjs +11 -1
- package/dist/type-checks/src/is-null.mjs.map +1 -1
- package/dist/type-checks/src/is-set-string.cjs +20 -1
- package/dist/type-checks/src/is-set-string.mjs +20 -1
- package/dist/type-checks/src/is-set-string.mjs.map +1 -1
- package/dist/type-checks/src/is-set.cjs +19 -1
- package/dist/type-checks/src/is-set.mjs +19 -1
- package/dist/type-checks/src/is-set.mjs.map +1 -1
- package/dist/type-checks/src/is-string.cjs +12 -1
- package/dist/type-checks/src/is-string.mjs +11 -1
- package/dist/type-checks/src/is-string.mjs.map +1 -1
- package/dist/type-checks/src/is-undefined.cjs +8 -1
- package/dist/type-checks/src/is-undefined.mjs +7 -1
- package/dist/type-checks/src/is-undefined.mjs.map +1 -1
- package/dist/types/src/base.cjs +6 -1
- package/dist/types/src/base.mjs +5 -1
- package/dist/types/src/base.mjs.map +1 -1
- package/package.json +5 -5
package/dist/is-type.cjs
CHANGED
|
@@ -1 +1,92 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_regex = require('./regex.cjs');
|
|
2
|
+
const require_slash = require('./slash.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/is-type.ts
|
|
5
|
+
/**
|
|
6
|
+
* Check if the path is an absolute path.
|
|
7
|
+
*
|
|
8
|
+
* @param path - The path to check
|
|
9
|
+
* @returns An indicator specifying if the path is an absolute path
|
|
10
|
+
*/
|
|
11
|
+
function isAbsolutePath(path) {
|
|
12
|
+
return require_regex.ABSOLUTE_PATH_REGEX.test(require_slash.slash(path));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Check if the path is an absolute path.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* This is an alias for {@link isAbsolutePath}.
|
|
19
|
+
*
|
|
20
|
+
* @param path - The path to check
|
|
21
|
+
* @returns An indicator specifying if the path is an absolute path
|
|
22
|
+
*/
|
|
23
|
+
function isAbsolute(path) {
|
|
24
|
+
return isAbsolutePath(path);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Check if the path is a relative path.
|
|
28
|
+
*
|
|
29
|
+
* @param path - The path to check
|
|
30
|
+
* @returns An indicator specifying if the path is a relative path
|
|
31
|
+
*/
|
|
32
|
+
function isRelativePath(path) {
|
|
33
|
+
return !isAbsolutePath(path);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Check if the path is a relative path.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* This is an alias for {@link isRelativePath}.
|
|
40
|
+
*
|
|
41
|
+
* @param path - The path to check
|
|
42
|
+
* @returns An indicator specifying if the path is a relative path
|
|
43
|
+
*/
|
|
44
|
+
function isRelative(path) {
|
|
45
|
+
return isRelativePath(path);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check if the path is a npm package path.
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* This only checks if the path matches the npm namespace scoped package naming convention such as `@scope/package-name`. This is an alias for {@link isNpmScopedPackage}.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* isNpmScopedPackage("@stryke/path"); // returns true
|
|
56
|
+
* isNpmScopedPackage("lodash"); // returns false
|
|
57
|
+
* isNpmNamespacePackage("./src/index.ts"); // returns false
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @param path - The path to check
|
|
61
|
+
* @returns An indicator specifying if the path is a npm package path
|
|
62
|
+
*/
|
|
63
|
+
function isNpmScopedPackagePath(path) {
|
|
64
|
+
return require_regex.NPM_SCOPED_PACKAGE_REGEX.test(require_slash.slash(path));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Check if the path is a npm package path.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* This only checks if the path matches the npm namespace scoped package naming convention such as `@scope/package-name`. This is an alias for {@link isNpmScopedPackagePath}.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* isNpmScopedPackagePath("@stryke/path"); // returns true
|
|
75
|
+
* isNpmScopedPackagePath("lodash"); // returns false
|
|
76
|
+
* isNpmScopedPackagePath("./src/index.ts"); // returns false
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @param path - The path to check
|
|
80
|
+
* @returns An indicator specifying if the path is a npm package path
|
|
81
|
+
*/
|
|
82
|
+
function isNpmScopedPackage(path) {
|
|
83
|
+
return isNpmScopedPackagePath(path);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
exports.isAbsolute = isAbsolute;
|
|
88
|
+
exports.isAbsolutePath = isAbsolutePath;
|
|
89
|
+
exports.isNpmScopedPackage = isNpmScopedPackage;
|
|
90
|
+
exports.isNpmScopedPackagePath = isNpmScopedPackagePath;
|
|
91
|
+
exports.isRelative = isRelative;
|
|
92
|
+
exports.isRelativePath = isRelativePath;
|
package/dist/is-type.mjs
CHANGED
|
@@ -1,2 +1,88 @@
|
|
|
1
|
-
import{ABSOLUTE_PATH_REGEX
|
|
1
|
+
import { ABSOLUTE_PATH_REGEX, NPM_SCOPED_PACKAGE_REGEX } from "./regex.mjs";
|
|
2
|
+
import { slash } from "./slash.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/is-type.ts
|
|
5
|
+
/**
|
|
6
|
+
* Check if the path is an absolute path.
|
|
7
|
+
*
|
|
8
|
+
* @param path - The path to check
|
|
9
|
+
* @returns An indicator specifying if the path is an absolute path
|
|
10
|
+
*/
|
|
11
|
+
function isAbsolutePath(path) {
|
|
12
|
+
return ABSOLUTE_PATH_REGEX.test(slash(path));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Check if the path is an absolute path.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* This is an alias for {@link isAbsolutePath}.
|
|
19
|
+
*
|
|
20
|
+
* @param path - The path to check
|
|
21
|
+
* @returns An indicator specifying if the path is an absolute path
|
|
22
|
+
*/
|
|
23
|
+
function isAbsolute(path) {
|
|
24
|
+
return isAbsolutePath(path);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Check if the path is a relative path.
|
|
28
|
+
*
|
|
29
|
+
* @param path - The path to check
|
|
30
|
+
* @returns An indicator specifying if the path is a relative path
|
|
31
|
+
*/
|
|
32
|
+
function isRelativePath(path) {
|
|
33
|
+
return !isAbsolutePath(path);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Check if the path is a relative path.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* This is an alias for {@link isRelativePath}.
|
|
40
|
+
*
|
|
41
|
+
* @param path - The path to check
|
|
42
|
+
* @returns An indicator specifying if the path is a relative path
|
|
43
|
+
*/
|
|
44
|
+
function isRelative(path) {
|
|
45
|
+
return isRelativePath(path);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check if the path is a npm package path.
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* This only checks if the path matches the npm namespace scoped package naming convention such as `@scope/package-name`. This is an alias for {@link isNpmScopedPackage}.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* isNpmScopedPackage("@stryke/path"); // returns true
|
|
56
|
+
* isNpmScopedPackage("lodash"); // returns false
|
|
57
|
+
* isNpmNamespacePackage("./src/index.ts"); // returns false
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @param path - The path to check
|
|
61
|
+
* @returns An indicator specifying if the path is a npm package path
|
|
62
|
+
*/
|
|
63
|
+
function isNpmScopedPackagePath(path) {
|
|
64
|
+
return NPM_SCOPED_PACKAGE_REGEX.test(slash(path));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Check if the path is a npm package path.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* This only checks if the path matches the npm namespace scoped package naming convention such as `@scope/package-name`. This is an alias for {@link isNpmScopedPackagePath}.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* isNpmScopedPackagePath("@stryke/path"); // returns true
|
|
75
|
+
* isNpmScopedPackagePath("lodash"); // returns false
|
|
76
|
+
* isNpmScopedPackagePath("./src/index.ts"); // returns false
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @param path - The path to check
|
|
80
|
+
* @returns An indicator specifying if the path is a npm package path
|
|
81
|
+
*/
|
|
82
|
+
function isNpmScopedPackage(path) {
|
|
83
|
+
return isNpmScopedPackagePath(path);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
export { isAbsolute, isAbsolutePath, isNpmScopedPackage, isNpmScopedPackagePath, isRelative, isRelativePath };
|
|
2
88
|
//# sourceMappingURL=is-type.mjs.map
|
package/dist/is-type.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-type.mjs","names":[],"sources":["../src/is-type.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 { ABSOLUTE_PATH_REGEX, NPM_SCOPED_PACKAGE_REGEX } from \"./regex\";\nimport { slash } from \"./slash\";\n\n/**\n * Check if the path is an absolute path.\n *\n * @param path - The path to check\n * @returns An indicator specifying if the path is an absolute path\n */\nexport function isAbsolutePath(path: string): boolean {\n return ABSOLUTE_PATH_REGEX.test(slash(path));\n}\n\n/**\n * Check if the path is an absolute path.\n *\n * @remarks\n * This is an alias for {@link isAbsolutePath}.\n *\n * @param path - The path to check\n * @returns An indicator specifying if the path is an absolute path\n */\nexport function isAbsolute(path: string): boolean {\n return isAbsolutePath(path);\n}\n\n/**\n * Check if the path is a relative path.\n *\n * @param path - The path to check\n * @returns An indicator specifying if the path is a relative path\n */\nexport function isRelativePath(path: string): boolean {\n return !isAbsolutePath(path);\n}\n\n/**\n * Check if the path is a relative path.\n *\n * @remarks\n * This is an alias for {@link isRelativePath}.\n *\n * @param path - The path to check\n * @returns An indicator specifying if the path is a relative path\n */\nexport function isRelative(path: string): boolean {\n return isRelativePath(path);\n}\n\n/**\n * Check if the path is a npm package path.\n *\n * @remarks\n * This only checks if the path matches the npm namespace scoped package naming convention such as `@scope/package-name`. This is an alias for {@link isNpmScopedPackage}.\n *\n * @example\n * ```ts\n * isNpmScopedPackage(\"@stryke/path\"); // returns true\n * isNpmScopedPackage(\"lodash\"); // returns false\n * isNpmNamespacePackage(\"./src/index.ts\"); // returns false\n * ```\n *\n * @param path - The path to check\n * @returns An indicator specifying if the path is a npm package path\n */\nexport function isNpmScopedPackagePath(path: string): boolean {\n return NPM_SCOPED_PACKAGE_REGEX.test(slash(path));\n}\n\n/**\n * Check if the path is a npm package path.\n *\n * @remarks\n * This only checks if the path matches the npm namespace scoped package naming convention such as `@scope/package-name`. This is an alias for {@link isNpmScopedPackagePath}.\n *\n * @example\n * ```ts\n * isNpmScopedPackagePath(\"@stryke/path\"); // returns true\n * isNpmScopedPackagePath(\"lodash\"); // returns false\n * isNpmScopedPackagePath(\"./src/index.ts\"); // returns false\n * ```\n *\n * @param path - The path to check\n * @returns An indicator specifying if the path is a npm package path\n */\nexport function isNpmScopedPackage(path: string): boolean {\n return isNpmScopedPackagePath(path);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"is-type.mjs","names":[],"sources":["../src/is-type.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 { ABSOLUTE_PATH_REGEX, NPM_SCOPED_PACKAGE_REGEX } from \"./regex\";\nimport { slash } from \"./slash\";\n\n/**\n * Check if the path is an absolute path.\n *\n * @param path - The path to check\n * @returns An indicator specifying if the path is an absolute path\n */\nexport function isAbsolutePath(path: string): boolean {\n return ABSOLUTE_PATH_REGEX.test(slash(path));\n}\n\n/**\n * Check if the path is an absolute path.\n *\n * @remarks\n * This is an alias for {@link isAbsolutePath}.\n *\n * @param path - The path to check\n * @returns An indicator specifying if the path is an absolute path\n */\nexport function isAbsolute(path: string): boolean {\n return isAbsolutePath(path);\n}\n\n/**\n * Check if the path is a relative path.\n *\n * @param path - The path to check\n * @returns An indicator specifying if the path is a relative path\n */\nexport function isRelativePath(path: string): boolean {\n return !isAbsolutePath(path);\n}\n\n/**\n * Check if the path is a relative path.\n *\n * @remarks\n * This is an alias for {@link isRelativePath}.\n *\n * @param path - The path to check\n * @returns An indicator specifying if the path is a relative path\n */\nexport function isRelative(path: string): boolean {\n return isRelativePath(path);\n}\n\n/**\n * Check if the path is a npm package path.\n *\n * @remarks\n * This only checks if the path matches the npm namespace scoped package naming convention such as `@scope/package-name`. This is an alias for {@link isNpmScopedPackage}.\n *\n * @example\n * ```ts\n * isNpmScopedPackage(\"@stryke/path\"); // returns true\n * isNpmScopedPackage(\"lodash\"); // returns false\n * isNpmNamespacePackage(\"./src/index.ts\"); // returns false\n * ```\n *\n * @param path - The path to check\n * @returns An indicator specifying if the path is a npm package path\n */\nexport function isNpmScopedPackagePath(path: string): boolean {\n return NPM_SCOPED_PACKAGE_REGEX.test(slash(path));\n}\n\n/**\n * Check if the path is a npm package path.\n *\n * @remarks\n * This only checks if the path matches the npm namespace scoped package naming convention such as `@scope/package-name`. This is an alias for {@link isNpmScopedPackagePath}.\n *\n * @example\n * ```ts\n * isNpmScopedPackagePath(\"@stryke/path\"); // returns true\n * isNpmScopedPackagePath(\"lodash\"); // returns false\n * isNpmScopedPackagePath(\"./src/index.ts\"); // returns false\n * ```\n *\n * @param path - The path to check\n * @returns An indicator specifying if the path is a npm package path\n */\nexport function isNpmScopedPackage(path: string): boolean {\n return isNpmScopedPackagePath(path);\n}\n"],"mappings":";;;;;;;;;;AA2BA,SAAgB,eAAe,MAAuB;AACpD,QAAO,oBAAoB,KAAK,MAAM,KAAK,CAAC;;;;;;;;;;;AAY9C,SAAgB,WAAW,MAAuB;AAChD,QAAO,eAAe,KAAK;;;;;;;;AAS7B,SAAgB,eAAe,MAAuB;AACpD,QAAO,CAAC,eAAe,KAAK;;;;;;;;;;;AAY9B,SAAgB,WAAW,MAAuB;AAChD,QAAO,eAAe,KAAK;;;;;;;;;;;;;;;;;;AAmB7B,SAAgB,uBAAuB,MAAuB;AAC5D,QAAO,yBAAyB,KAAK,MAAM,KAAK,CAAC;;;;;;;;;;;;;;;;;;AAmBnD,SAAgB,mBAAmB,MAAuB;AACxD,QAAO,uBAAuB,KAAK"}
|
package/dist/join-paths.cjs
CHANGED
|
@@ -1 +1,108 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_regex = require('./regex.cjs');
|
|
2
|
+
const require_is_type = require('./is-type.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/join-paths.ts
|
|
5
|
+
function normalizeWindowsPath(input = "") {
|
|
6
|
+
if (!input) return input;
|
|
7
|
+
return input.replace(/\\/g, "/").replace(require_regex.DRIVE_LETTER_START_REGEX, (r) => r.toUpperCase());
|
|
8
|
+
}
|
|
9
|
+
function correctPaths(path) {
|
|
10
|
+
if (!path || path.length === 0) return ".";
|
|
11
|
+
path = normalizeWindowsPath(path);
|
|
12
|
+
const isUNCPath = path.match(require_regex.UNC_REGEX);
|
|
13
|
+
const isPathAbsolute = require_is_type.isAbsolute(path);
|
|
14
|
+
const trailingSeparator = path[path.length - 1] === "/";
|
|
15
|
+
path = normalizeString(path, !isPathAbsolute);
|
|
16
|
+
if (path.length === 0) {
|
|
17
|
+
if (isPathAbsolute) return "/";
|
|
18
|
+
return trailingSeparator ? "./" : ".";
|
|
19
|
+
}
|
|
20
|
+
if (trailingSeparator) path += "/";
|
|
21
|
+
if (require_regex.DRIVE_LETTER_REGEX.test(path)) path += "/";
|
|
22
|
+
if (isUNCPath) {
|
|
23
|
+
if (!isPathAbsolute) return `//./${path}`;
|
|
24
|
+
return `//${path}`;
|
|
25
|
+
}
|
|
26
|
+
return isPathAbsolute && !require_is_type.isAbsolute(path) ? `/${path}` : path;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Joins all given path segments together using the platform-specific separator as a delimiter.
|
|
30
|
+
* The resulting path is normalized to remove any redundant or unnecessary segments.
|
|
31
|
+
*
|
|
32
|
+
* @param segments - The path segments to join.
|
|
33
|
+
* @returns The joined and normalized path string.
|
|
34
|
+
*/
|
|
35
|
+
function joinPaths(...segments) {
|
|
36
|
+
let path = "";
|
|
37
|
+
for (const seg of segments) {
|
|
38
|
+
if (!seg) continue;
|
|
39
|
+
if (path.length > 0) {
|
|
40
|
+
const pathTrailing = path[path.length - 1] === "/";
|
|
41
|
+
const segLeading = seg[0] === "/";
|
|
42
|
+
if (pathTrailing && segLeading) path += seg.slice(1);
|
|
43
|
+
else path += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
44
|
+
} else path += seg;
|
|
45
|
+
}
|
|
46
|
+
return correctPaths(path);
|
|
47
|
+
}
|
|
48
|
+
const join = joinPaths;
|
|
49
|
+
/**
|
|
50
|
+
* Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.
|
|
51
|
+
*
|
|
52
|
+
* @param path - The path to normalize.
|
|
53
|
+
* @param allowAboveRoot - Whether to allow the resulting path to be above the root directory.
|
|
54
|
+
* @returns the normalized path string.
|
|
55
|
+
*/
|
|
56
|
+
function normalizeString(path, allowAboveRoot) {
|
|
57
|
+
let res = "";
|
|
58
|
+
let lastSegmentLength = 0;
|
|
59
|
+
let lastSlash = -1;
|
|
60
|
+
let dots = 0;
|
|
61
|
+
let char = null;
|
|
62
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
63
|
+
if (index < path.length) char = path[index];
|
|
64
|
+
else if (char === "/") break;
|
|
65
|
+
else char = "/";
|
|
66
|
+
if (char === "/") {
|
|
67
|
+
if (lastSlash === index - 1 || dots === 1) {} else if (dots === 2) {
|
|
68
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
69
|
+
if (res.length > 2) {
|
|
70
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
71
|
+
if (lastSlashIndex === -1) {
|
|
72
|
+
res = "";
|
|
73
|
+
lastSegmentLength = 0;
|
|
74
|
+
} else {
|
|
75
|
+
res = res.slice(0, lastSlashIndex);
|
|
76
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
77
|
+
}
|
|
78
|
+
lastSlash = index;
|
|
79
|
+
dots = 0;
|
|
80
|
+
continue;
|
|
81
|
+
} else if (res.length > 0) {
|
|
82
|
+
res = "";
|
|
83
|
+
lastSegmentLength = 0;
|
|
84
|
+
lastSlash = index;
|
|
85
|
+
dots = 0;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (allowAboveRoot) {
|
|
90
|
+
res += res.length > 0 ? "/.." : "..";
|
|
91
|
+
lastSegmentLength = 2;
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
|
|
95
|
+
else res = path.slice(lastSlash + 1, index);
|
|
96
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
97
|
+
}
|
|
98
|
+
lastSlash = index;
|
|
99
|
+
dots = 0;
|
|
100
|
+
} else if (char === "." && dots !== -1) ++dots;
|
|
101
|
+
else dots = -1;
|
|
102
|
+
}
|
|
103
|
+
return res;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
exports.join = join;
|
|
108
|
+
exports.joinPaths = joinPaths;
|
package/dist/join-paths.mjs
CHANGED
|
@@ -1,2 +1,108 @@
|
|
|
1
|
-
import{DRIVE_LETTER_REGEX
|
|
1
|
+
import { DRIVE_LETTER_REGEX, DRIVE_LETTER_START_REGEX, UNC_REGEX } from "./regex.mjs";
|
|
2
|
+
import { isAbsolute } from "./is-type.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/join-paths.ts
|
|
5
|
+
function normalizeWindowsPath(input = "") {
|
|
6
|
+
if (!input) return input;
|
|
7
|
+
return input.replace(/\\/g, "/").replace(DRIVE_LETTER_START_REGEX, (r) => r.toUpperCase());
|
|
8
|
+
}
|
|
9
|
+
function correctPaths(path) {
|
|
10
|
+
if (!path || path.length === 0) return ".";
|
|
11
|
+
path = normalizeWindowsPath(path);
|
|
12
|
+
const isUNCPath = path.match(UNC_REGEX);
|
|
13
|
+
const isPathAbsolute = isAbsolute(path);
|
|
14
|
+
const trailingSeparator = path[path.length - 1] === "/";
|
|
15
|
+
path = normalizeString(path, !isPathAbsolute);
|
|
16
|
+
if (path.length === 0) {
|
|
17
|
+
if (isPathAbsolute) return "/";
|
|
18
|
+
return trailingSeparator ? "./" : ".";
|
|
19
|
+
}
|
|
20
|
+
if (trailingSeparator) path += "/";
|
|
21
|
+
if (DRIVE_LETTER_REGEX.test(path)) path += "/";
|
|
22
|
+
if (isUNCPath) {
|
|
23
|
+
if (!isPathAbsolute) return `//./${path}`;
|
|
24
|
+
return `//${path}`;
|
|
25
|
+
}
|
|
26
|
+
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Joins all given path segments together using the platform-specific separator as a delimiter.
|
|
30
|
+
* The resulting path is normalized to remove any redundant or unnecessary segments.
|
|
31
|
+
*
|
|
32
|
+
* @param segments - The path segments to join.
|
|
33
|
+
* @returns The joined and normalized path string.
|
|
34
|
+
*/
|
|
35
|
+
function joinPaths(...segments) {
|
|
36
|
+
let path = "";
|
|
37
|
+
for (const seg of segments) {
|
|
38
|
+
if (!seg) continue;
|
|
39
|
+
if (path.length > 0) {
|
|
40
|
+
const pathTrailing = path[path.length - 1] === "/";
|
|
41
|
+
const segLeading = seg[0] === "/";
|
|
42
|
+
if (pathTrailing && segLeading) path += seg.slice(1);
|
|
43
|
+
else path += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
44
|
+
} else path += seg;
|
|
45
|
+
}
|
|
46
|
+
return correctPaths(path);
|
|
47
|
+
}
|
|
48
|
+
const join = joinPaths;
|
|
49
|
+
/**
|
|
50
|
+
* Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.
|
|
51
|
+
*
|
|
52
|
+
* @param path - The path to normalize.
|
|
53
|
+
* @param allowAboveRoot - Whether to allow the resulting path to be above the root directory.
|
|
54
|
+
* @returns the normalized path string.
|
|
55
|
+
*/
|
|
56
|
+
function normalizeString(path, allowAboveRoot) {
|
|
57
|
+
let res = "";
|
|
58
|
+
let lastSegmentLength = 0;
|
|
59
|
+
let lastSlash = -1;
|
|
60
|
+
let dots = 0;
|
|
61
|
+
let char = null;
|
|
62
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
63
|
+
if (index < path.length) char = path[index];
|
|
64
|
+
else if (char === "/") break;
|
|
65
|
+
else char = "/";
|
|
66
|
+
if (char === "/") {
|
|
67
|
+
if (lastSlash === index - 1 || dots === 1) {} else if (dots === 2) {
|
|
68
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
69
|
+
if (res.length > 2) {
|
|
70
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
71
|
+
if (lastSlashIndex === -1) {
|
|
72
|
+
res = "";
|
|
73
|
+
lastSegmentLength = 0;
|
|
74
|
+
} else {
|
|
75
|
+
res = res.slice(0, lastSlashIndex);
|
|
76
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
77
|
+
}
|
|
78
|
+
lastSlash = index;
|
|
79
|
+
dots = 0;
|
|
80
|
+
continue;
|
|
81
|
+
} else if (res.length > 0) {
|
|
82
|
+
res = "";
|
|
83
|
+
lastSegmentLength = 0;
|
|
84
|
+
lastSlash = index;
|
|
85
|
+
dots = 0;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (allowAboveRoot) {
|
|
90
|
+
res += res.length > 0 ? "/.." : "..";
|
|
91
|
+
lastSegmentLength = 2;
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
|
|
95
|
+
else res = path.slice(lastSlash + 1, index);
|
|
96
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
97
|
+
}
|
|
98
|
+
lastSlash = index;
|
|
99
|
+
dots = 0;
|
|
100
|
+
} else if (char === "." && dots !== -1) ++dots;
|
|
101
|
+
else dots = -1;
|
|
102
|
+
}
|
|
103
|
+
return res;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
//#endregion
|
|
107
|
+
export { join, joinPaths };
|
|
2
108
|
//# sourceMappingURL=join-paths.mjs.map
|
package/dist/join-paths.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"join-paths.mjs","names":["char: string | null"],"sources":["../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\";\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 * The resulting path is normalized to remove any redundant or unnecessary segments.\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 path = \"\";\n\n for (const seg of segments) {\n if (!seg) {\n continue;\n }\n if (path.length > 0) {\n const pathTrailing = path[path.length - 1] === \"/\";\n const segLeading = seg[0] === \"/\";\n const both = pathTrailing && segLeading;\n if (both) {\n path += seg.slice(1);\n } else {\n path += pathTrailing || segLeading ? seg : `/${seg}`;\n }\n } else {\n path += seg;\n }\n }\n\n return correctPaths(path);\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":"
|
|
1
|
+
{"version":3,"file":"join-paths.mjs","names":["char: string | null"],"sources":["../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\";\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 * The resulting path is normalized to remove any redundant or unnecessary segments.\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 path = \"\";\n\n for (const seg of segments) {\n if (!seg) {\n continue;\n }\n if (path.length > 0) {\n const pathTrailing = path[path.length - 1] === \"/\";\n const segLeading = seg[0] === \"/\";\n const both = pathTrailing && segLeading;\n if (both) {\n path += seg.slice(1);\n } else {\n path += pathTrailing || segLeading ? seg : `/${seg}`;\n }\n } else {\n path += seg;\n }\n }\n\n return correctPaths(path);\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":";;;;AA0BA,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;;;;;;;;;AAU5D,SAAgB,UAAU,GAAG,UAA4B;CACvD,IAAI,OAAO;AAEX,MAAK,MAAM,OAAO,UAAU;AAC1B,MAAI,CAAC,IACH;AAEF,MAAI,KAAK,SAAS,GAAG;GACnB,MAAM,eAAe,KAAK,KAAK,SAAS,OAAO;GAC/C,MAAM,aAAa,IAAI,OAAO;AAE9B,OADa,gBAAgB,WAE3B,SAAQ,IAAI,MAAM,EAAE;OAEpB,SAAQ,gBAAgB,aAAa,MAAM,IAAI;QAGjD,SAAQ;;AAIZ,QAAO,aAAa,KAAK;;AAG3B,MAAa,OAAO;;;;;;;;AASpB,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/join.cjs
CHANGED
package/dist/join.mjs
CHANGED
package/dist/normalize.cjs
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_correct_path = require('./correct-path.cjs');
|
|
2
|
+
|
|
3
|
+
exports.correctPath = require_correct_path.correctPath;
|
|
4
|
+
exports.normalizeString = require_correct_path.normalizeString;
|
|
5
|
+
exports.normalizeWindowsPath = require_correct_path.normalizeWindowsPath;
|
|
6
|
+
exports.stripStars = require_correct_path.stripStars;
|
|
7
|
+
exports.toAbsolutePath = require_correct_path.toAbsolutePath;
|
|
8
|
+
exports.toRelativePath = require_correct_path.toRelativePath;
|
|
9
|
+
exports.withTrailingSlash = require_correct_path.withTrailingSlash;
|
|
10
|
+
exports.withoutTrailingSlash = require_correct_path.withoutTrailingSlash;
|
package/dist/normalize.mjs
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
import{correctPath
|
|
1
|
+
import { correctPath, normalizeString, normalizeWindowsPath, stripStars, toAbsolutePath, toRelativePath, withTrailingSlash, withoutTrailingSlash } from "./correct-path.mjs";
|
|
2
|
+
|
|
3
|
+
export { correctPath, normalizeString, normalizeWindowsPath, stripStars, toAbsolutePath, toRelativePath, withTrailingSlash, withoutTrailingSlash };
|
package/dist/regex.cjs
CHANGED
|
@@ -1 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region 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 PACKAGE_PATH_REGEX = /^@\w+\/.*$/;
|
|
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.NPM_SCOPED_PACKAGE_REGEX = NPM_SCOPED_PACKAGE_REGEX;
|
|
18
|
+
exports.PACKAGE_PATH_REGEX = PACKAGE_PATH_REGEX;
|
|
19
|
+
exports.ROOT_FOLDER_REGEX = ROOT_FOLDER_REGEX;
|
|
20
|
+
exports.UNC_REGEX = UNC_REGEX;
|
package/dist/regex.mjs
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
//#region 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 PACKAGE_PATH_REGEX = /^@\w+\/.*$/;
|
|
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, NPM_SCOPED_PACKAGE_REGEX, PACKAGE_PATH_REGEX, ROOT_FOLDER_REGEX, UNC_REGEX };
|
|
2
13
|
//# sourceMappingURL=regex.mjs.map
|
package/dist/regex.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regex.mjs","names":[],"sources":["../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;\n\nexport const PACKAGE_PATH_REGEX = /^@\\w+\\/.*$/;\nexport const NPM_SCOPED_PACKAGE_REGEX = /^(?:@[\\w-]+\\/)?[\\w-]+$/;\n"],"mappings":"AAkBA,MAAa,
|
|
1
|
+
{"version":3,"file":"regex.mjs","names":[],"sources":["../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;\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;AAEpC,MAAa,qBAAqB;AAClC,MAAa,2BAA2B"}
|
package/dist/replace.cjs
CHANGED
|
@@ -1 +1,44 @@
|
|
|
1
|
-
const
|
|
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
|
+
const require_file_path_fns = require('./file-path-fns.cjs');
|
|
5
|
+
|
|
6
|
+
//#region src/replace.ts
|
|
7
|
+
/**
|
|
8
|
+
* Replace the base path from the beginning of the given path.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* replacePath("/home/user/project/src/index.ts", "/home/user/project");
|
|
13
|
+
* // returns "src/index.ts"
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param childPath - The child path to replace the {@link parentPath} substring from
|
|
17
|
+
* @param parentPath - The parent path to remove from the {@link childPath} parameter
|
|
18
|
+
* @returns The {@link childPath} with the {@link parentPath} path removed
|
|
19
|
+
*/
|
|
20
|
+
function replacePath(childPath, parentPath = require_cwd.cwd()) {
|
|
21
|
+
return require_is_parent_path.isParentPath(childPath, parentPath) ? require_slash.slash(childPath).replace(require_slash.slash(parentPath), "").replace(/^\//, "") : childPath;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Replace the extension of a given path with the provided value.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* replaceExtension("/home/user/project/src/index.ts", ".js");
|
|
29
|
+
* // returns "/home/user/project/src/index.js"
|
|
30
|
+
* replaceExtension("/home/user/project/src/index.ts");
|
|
31
|
+
* // returns "/home/user/project/src/index"
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param path - The path that will have its current extension replaced
|
|
35
|
+
* @param replacement - The value (or an empty string) to replace the current extension with
|
|
36
|
+
* @returns The path with the replaced extension
|
|
37
|
+
*/
|
|
38
|
+
function replaceExtension(path, replacement = "") {
|
|
39
|
+
return path.replace(!replacement || replacement.includes(".") ? require_file_path_fns.findFileDotExtensionSafe(path) : require_file_path_fns.findFileExtensionSafe(path), replacement);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
exports.replaceExtension = replaceExtension;
|
|
44
|
+
exports.replacePath = replacePath;
|
package/dist/replace.mjs
CHANGED
|
@@ -1,2 +1,44 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { cwd } from "./cwd.mjs";
|
|
2
|
+
import { slash } from "./slash.mjs";
|
|
3
|
+
import { isParentPath } from "./is-parent-path.mjs";
|
|
4
|
+
import { findFileDotExtensionSafe, findFileExtensionSafe } from "./file-path-fns.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/replace.ts
|
|
7
|
+
/**
|
|
8
|
+
* Replace the base path from the beginning of the given path.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* replacePath("/home/user/project/src/index.ts", "/home/user/project");
|
|
13
|
+
* // returns "src/index.ts"
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param childPath - The child path to replace the {@link parentPath} substring from
|
|
17
|
+
* @param parentPath - The parent path to remove from the {@link childPath} parameter
|
|
18
|
+
* @returns The {@link childPath} with the {@link parentPath} path removed
|
|
19
|
+
*/
|
|
20
|
+
function replacePath(childPath, parentPath = cwd()) {
|
|
21
|
+
return isParentPath(childPath, parentPath) ? slash(childPath).replace(slash(parentPath), "").replace(/^\//, "") : childPath;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Replace the extension of a given path with the provided value.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* replaceExtension("/home/user/project/src/index.ts", ".js");
|
|
29
|
+
* // returns "/home/user/project/src/index.js"
|
|
30
|
+
* replaceExtension("/home/user/project/src/index.ts");
|
|
31
|
+
* // returns "/home/user/project/src/index"
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param path - The path that will have its current extension replaced
|
|
35
|
+
* @param replacement - The value (or an empty string) to replace the current extension with
|
|
36
|
+
* @returns The path with the replaced extension
|
|
37
|
+
*/
|
|
38
|
+
function replaceExtension(path, replacement = "") {
|
|
39
|
+
return path.replace(!replacement || replacement.includes(".") ? findFileDotExtensionSafe(path) : findFileExtensionSafe(path), replacement);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { replaceExtension, replacePath };
|
|
2
44
|
//# sourceMappingURL=replace.mjs.map
|