@stryke/url 0.3.26 → 0.3.28
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 +14 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -1
- package/dist/helpers.cjs +28 -1
- package/dist/helpers.mjs +26 -1
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +5 -1
- package/dist/index.mjs +4 -1
- package/dist/json/src/storm-json.cjs +117 -1
- package/dist/json/src/storm-json.mjs +115 -1
- package/dist/json/src/storm-json.mjs.map +1 -1
- package/dist/json/src/utils/code-frames.cjs +77 -3
- package/dist/json/src/utils/code-frames.mjs +76 -3
- package/dist/json/src/utils/code-frames.mjs.map +1 -1
- package/dist/json/src/utils/parse-error.cjs +34 -1
- package/dist/json/src/utils/parse-error.mjs +33 -1
- package/dist/json/src/utils/parse-error.mjs.map +1 -1
- package/dist/json/src/utils/parse.cjs +45 -1
- package/dist/json/src/utils/parse.mjs +45 -1
- package/dist/json/src/utils/parse.mjs.map +1 -1
- package/dist/json/src/utils/stringify.cjs +67 -1
- package/dist/json/src/utils/stringify.mjs +67 -1
- package/dist/json/src/utils/stringify.mjs.map +1 -1
- package/dist/json/src/utils/strip-comments.cjs +86 -4
- package/dist/json/src/utils/strip-comments.mjs +86 -4
- package/dist/json/src/utils/strip-comments.mjs.map +1 -1
- package/dist/path/src/is-type.cjs +28 -1
- package/dist/path/src/is-type.mjs +28 -1
- package/dist/path/src/is-type.mjs.map +1 -1
- package/dist/path/src/join-paths.cjs +106 -1
- package/dist/path/src/join-paths.mjs +106 -1
- package/dist/path/src/join-paths.mjs.map +1 -1
- package/dist/path/src/regex.cjs +12 -1
- package/dist/path/src/regex.mjs +8 -1
- package/dist/path/src/regex.mjs.map +1 -1
- package/dist/path/src/slash.cjs +15 -1
- package/dist/path/src/slash.mjs +14 -1
- package/dist/path/src/slash.mjs.map +1 -1
- package/dist/storm-url.cjs +227 -1
- package/dist/storm-url.mjs +226 -1
- package/dist/storm-url.mjs.map +1 -1
- package/dist/type-checks/src/get-object-tag.cjs +15 -1
- package/dist/type-checks/src/get-object-tag.mjs +14 -1
- package/dist/type-checks/src/get-object-tag.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-integer.cjs +14 -1
- package/dist/type-checks/src/is-integer.mjs +14 -1
- package/dist/type-checks/src/is-integer.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-number.cjs +18 -1
- package/dist/type-checks/src/is-number.mjs +17 -1
- package/dist/type-checks/src/is-number.mjs.map +1 -1
- package/dist/type-checks/src/is-object.cjs +19 -1
- package/dist/type-checks/src/is-object.mjs +19 -1
- package/dist/type-checks/src/is-object.mjs.map +1 -1
- package/dist/type-checks/src/is-plain-object.cjs +63 -1
- package/dist/type-checks/src/is-plain-object.mjs +63 -1
- package/dist/type-checks/src/is-plain-object.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/dist/types.cjs +6 -1
- package/dist/types.mjs +5 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1,2 +1,29 @@
|
|
|
1
|
-
import{ABSOLUTE_PATH_REGEX
|
|
1
|
+
import { ABSOLUTE_PATH_REGEX } from "./regex.mjs";
|
|
2
|
+
import { slash } from "./slash.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../path/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
|
+
//#endregion
|
|
28
|
+
export { isAbsolute };
|
|
2
29
|
//# sourceMappingURL=is-type.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-type.mjs","names":[],"sources":["../../../../path/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":["../../../../path/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"}
|
|
@@ -1 +1,106 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_regex = require('./regex.cjs');
|
|
2
|
+
const require_is_type = require('./is-type.cjs');
|
|
3
|
+
|
|
4
|
+
//#region ../path/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
|
+
/**
|
|
49
|
+
* Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.
|
|
50
|
+
*
|
|
51
|
+
* @param path - The path to normalize.
|
|
52
|
+
* @param allowAboveRoot - Whether to allow the resulting path to be above the root directory.
|
|
53
|
+
* @returns the normalized path string.
|
|
54
|
+
*/
|
|
55
|
+
function normalizeString(path, allowAboveRoot) {
|
|
56
|
+
let res = "";
|
|
57
|
+
let lastSegmentLength = 0;
|
|
58
|
+
let lastSlash = -1;
|
|
59
|
+
let dots = 0;
|
|
60
|
+
let char = null;
|
|
61
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
62
|
+
if (index < path.length) char = path[index];
|
|
63
|
+
else if (char === "/") break;
|
|
64
|
+
else char = "/";
|
|
65
|
+
if (char === "/") {
|
|
66
|
+
if (lastSlash === index - 1 || dots === 1) {} else if (dots === 2) {
|
|
67
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
68
|
+
if (res.length > 2) {
|
|
69
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
70
|
+
if (lastSlashIndex === -1) {
|
|
71
|
+
res = "";
|
|
72
|
+
lastSegmentLength = 0;
|
|
73
|
+
} else {
|
|
74
|
+
res = res.slice(0, lastSlashIndex);
|
|
75
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
76
|
+
}
|
|
77
|
+
lastSlash = index;
|
|
78
|
+
dots = 0;
|
|
79
|
+
continue;
|
|
80
|
+
} else if (res.length > 0) {
|
|
81
|
+
res = "";
|
|
82
|
+
lastSegmentLength = 0;
|
|
83
|
+
lastSlash = index;
|
|
84
|
+
dots = 0;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (allowAboveRoot) {
|
|
89
|
+
res += res.length > 0 ? "/.." : "..";
|
|
90
|
+
lastSegmentLength = 2;
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
|
|
94
|
+
else res = path.slice(lastSlash + 1, index);
|
|
95
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
96
|
+
}
|
|
97
|
+
lastSlash = index;
|
|
98
|
+
dots = 0;
|
|
99
|
+
} else if (char === "." && dots !== -1) ++dots;
|
|
100
|
+
else dots = -1;
|
|
101
|
+
}
|
|
102
|
+
return res;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
exports.joinPaths = joinPaths;
|
|
@@ -1,2 +1,107 @@
|
|
|
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 ../path/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
|
+
/**
|
|
49
|
+
* Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.
|
|
50
|
+
*
|
|
51
|
+
* @param path - The path to normalize.
|
|
52
|
+
* @param allowAboveRoot - Whether to allow the resulting path to be above the root directory.
|
|
53
|
+
* @returns the normalized path string.
|
|
54
|
+
*/
|
|
55
|
+
function normalizeString(path, allowAboveRoot) {
|
|
56
|
+
let res = "";
|
|
57
|
+
let lastSegmentLength = 0;
|
|
58
|
+
let lastSlash = -1;
|
|
59
|
+
let dots = 0;
|
|
60
|
+
let char = null;
|
|
61
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
62
|
+
if (index < path.length) char = path[index];
|
|
63
|
+
else if (char === "/") break;
|
|
64
|
+
else char = "/";
|
|
65
|
+
if (char === "/") {
|
|
66
|
+
if (lastSlash === index - 1 || dots === 1) {} else if (dots === 2) {
|
|
67
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
68
|
+
if (res.length > 2) {
|
|
69
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
70
|
+
if (lastSlashIndex === -1) {
|
|
71
|
+
res = "";
|
|
72
|
+
lastSegmentLength = 0;
|
|
73
|
+
} else {
|
|
74
|
+
res = res.slice(0, lastSlashIndex);
|
|
75
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
76
|
+
}
|
|
77
|
+
lastSlash = index;
|
|
78
|
+
dots = 0;
|
|
79
|
+
continue;
|
|
80
|
+
} else if (res.length > 0) {
|
|
81
|
+
res = "";
|
|
82
|
+
lastSegmentLength = 0;
|
|
83
|
+
lastSlash = index;
|
|
84
|
+
dots = 0;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (allowAboveRoot) {
|
|
89
|
+
res += res.length > 0 ? "/.." : "..";
|
|
90
|
+
lastSegmentLength = 2;
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
|
|
94
|
+
else res = path.slice(lastSlash + 1, index);
|
|
95
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
96
|
+
}
|
|
97
|
+
lastSlash = index;
|
|
98
|
+
dots = 0;
|
|
99
|
+
} else if (char === "." && dots !== -1) ++dots;
|
|
100
|
+
else dots = -1;
|
|
101
|
+
}
|
|
102
|
+
return res;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
export { joinPaths };
|
|
2
107
|
//# sourceMappingURL=join-paths.mjs.map
|
|
@@ -1 +1 @@
|
|
|
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\";\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":["../../../../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\";\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;;;;;;;;;AAY3B,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
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
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
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
exports.ABSOLUTE_PATH_REGEX = ABSOLUTE_PATH_REGEX;
|
|
10
|
+
exports.DRIVE_LETTER_REGEX = DRIVE_LETTER_REGEX;
|
|
11
|
+
exports.DRIVE_LETTER_START_REGEX = DRIVE_LETTER_START_REGEX;
|
|
12
|
+
exports.UNC_REGEX = UNC_REGEX;
|
package/dist/path/src/regex.mjs
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
|
|
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
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { ABSOLUTE_PATH_REGEX, DRIVE_LETTER_REGEX, DRIVE_LETTER_START_REGEX, UNC_REGEX };
|
|
2
9
|
//# sourceMappingURL=regex.mjs.map
|
|
@@ -1 +1 @@
|
|
|
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;\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":["../../../../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;\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"}
|
package/dist/path/src/slash.cjs
CHANGED
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
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
CHANGED
|
@@ -1,2 +1,15 @@
|
|
|
1
|
-
|
|
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 };
|
|
2
15
|
//# sourceMappingURL=slash.mjs.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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"}
|
package/dist/storm-url.cjs
CHANGED
|
@@ -1 +1,227 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_helpers = require('./helpers.cjs');
|
|
3
|
+
const require_is_undefined = require('./type-checks/src/is-undefined.cjs');
|
|
4
|
+
const require_storm_json = require('./json/src/storm-json.cjs');
|
|
5
|
+
const require_join_paths = require('./path/src/join-paths.cjs');
|
|
6
|
+
const require_is_integer = require('./type-checks/src/is-integer.cjs');
|
|
7
|
+
const require_is_set_string = require('./type-checks/src/is-set-string.cjs');
|
|
8
|
+
let ufo = require("ufo");
|
|
9
|
+
|
|
10
|
+
//#region src/storm-url.ts
|
|
11
|
+
/**
|
|
12
|
+
* A class used to build URLs
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* This class is used to build URLs with a fluent API.
|
|
16
|
+
*
|
|
17
|
+
* The [UFO](https://github.com/unjs/ufo) library is used under the hood to parse and stringify URLs.
|
|
18
|
+
*/
|
|
19
|
+
var StormURL = class StormURL {
|
|
20
|
+
#options;
|
|
21
|
+
/**
|
|
22
|
+
* A string containing the username specified before the domain name.
|
|
23
|
+
*/
|
|
24
|
+
#username;
|
|
25
|
+
/**
|
|
26
|
+
* A string containing the password specified before the domain name.
|
|
27
|
+
*/
|
|
28
|
+
#password;
|
|
29
|
+
/**
|
|
30
|
+
* A string containing the domain of the URL.
|
|
31
|
+
*/
|
|
32
|
+
#hostname;
|
|
33
|
+
/**
|
|
34
|
+
* A string containing the port number of the URL.
|
|
35
|
+
*/
|
|
36
|
+
#port;
|
|
37
|
+
/**
|
|
38
|
+
* A string containing the protocol scheme of the URL, including the final `:`.
|
|
39
|
+
*/
|
|
40
|
+
#protocol;
|
|
41
|
+
/**
|
|
42
|
+
* The paths of the URL
|
|
43
|
+
*/
|
|
44
|
+
#paths = [];
|
|
45
|
+
/**
|
|
46
|
+
* A string containing a `#` followed by the fragment identifier of the URL.
|
|
47
|
+
*/
|
|
48
|
+
#hash;
|
|
49
|
+
/**
|
|
50
|
+
* The search parameters of the URL
|
|
51
|
+
*/
|
|
52
|
+
#params;
|
|
53
|
+
constructor(initialURL, options = { decode: true }) {
|
|
54
|
+
if (initialURL && !require_helpers.isValidURL(initialURL)) throw new TypeError(`Invalid URL: ${initialURL}`);
|
|
55
|
+
this.#options = options;
|
|
56
|
+
const parsedURL = (0, ufo.parseURL)(this.#options.decode ? (0, ufo.decode)(initialURL) : initialURL);
|
|
57
|
+
const parsedAuth = (0, ufo.parseAuth)(parsedURL.auth);
|
|
58
|
+
this.#username = parsedAuth.username;
|
|
59
|
+
this.#password = parsedAuth.password;
|
|
60
|
+
const parsedHost = (0, ufo.parseHost)(parsedURL.host);
|
|
61
|
+
this.#hostname = parsedHost.hostname;
|
|
62
|
+
this.#port = parsedHost.port;
|
|
63
|
+
this.#protocol = parsedURL.protocol;
|
|
64
|
+
this.#hash = parsedURL.hash || "";
|
|
65
|
+
this.#params = (0, ufo.parseQuery)(parsedURL.search);
|
|
66
|
+
this.#paths = parsedURL.pathname ? parsedURL.pathname.split("/").filter(Boolean) : [];
|
|
67
|
+
if (options.locale) this.#paths.unshift(require_helpers.formatLocalePath((require_is_set_string.isSetString(options.locale) ? options.locale : process.env.DEFAULT_LOCALE) || "en-us"));
|
|
68
|
+
}
|
|
69
|
+
set params(value) {
|
|
70
|
+
this.#params = value;
|
|
71
|
+
}
|
|
72
|
+
get params() {
|
|
73
|
+
return this.#params;
|
|
74
|
+
}
|
|
75
|
+
get searchParams() {
|
|
76
|
+
const params = new URLSearchParams();
|
|
77
|
+
for (const [key, value] of Object.entries(this.params)) params.append(key, value);
|
|
78
|
+
return params;
|
|
79
|
+
}
|
|
80
|
+
set searchParams(value) {
|
|
81
|
+
this.params = Object.fromEntries(value.entries());
|
|
82
|
+
}
|
|
83
|
+
set search(value) {
|
|
84
|
+
this.params = (0, ufo.parseQuery)(value);
|
|
85
|
+
}
|
|
86
|
+
get search() {
|
|
87
|
+
const search = (0, ufo.stringifyQuery)(this.params);
|
|
88
|
+
return search ? search.startsWith("?") ? search : `?${search}` : "";
|
|
89
|
+
}
|
|
90
|
+
set hash(value) {
|
|
91
|
+
this.#hash = value.startsWith("#") ? value : `#${value}`;
|
|
92
|
+
}
|
|
93
|
+
get hash() {
|
|
94
|
+
return this.#hash;
|
|
95
|
+
}
|
|
96
|
+
set port(value) {
|
|
97
|
+
this.#port = !require_is_undefined.isUndefined(value) && require_is_integer.isInteger(value) ? `${value}` : "";
|
|
98
|
+
}
|
|
99
|
+
get port() {
|
|
100
|
+
return this.#port || "";
|
|
101
|
+
}
|
|
102
|
+
set username(value) {
|
|
103
|
+
this.auth = `${value}:${this.#password}`;
|
|
104
|
+
}
|
|
105
|
+
get username() {
|
|
106
|
+
return this.#username || "";
|
|
107
|
+
}
|
|
108
|
+
set password(value) {
|
|
109
|
+
this.auth = `${this.#username}:${value}`;
|
|
110
|
+
}
|
|
111
|
+
get password() {
|
|
112
|
+
return this.#password || "";
|
|
113
|
+
}
|
|
114
|
+
set auth(value) {
|
|
115
|
+
const parsedAuth = (0, ufo.parseAuth)(value);
|
|
116
|
+
this.#username = parsedAuth.username;
|
|
117
|
+
this.#password = parsedAuth.password;
|
|
118
|
+
}
|
|
119
|
+
get auth() {
|
|
120
|
+
return this.#username && this.#password ? `${this.#username}:${this.#password}` : this.#username ? this.#username : this.#password ? this.#password : "";
|
|
121
|
+
}
|
|
122
|
+
set protocol(value) {
|
|
123
|
+
this.#protocol = value.endsWith(":") ? value : value.endsWith("://") ? value.slice(0, -2) : `${value}:`;
|
|
124
|
+
}
|
|
125
|
+
get protocol() {
|
|
126
|
+
return this.#protocol || this.#options.defaultProtocol || "https:";
|
|
127
|
+
}
|
|
128
|
+
set hostname(value) {
|
|
129
|
+
this.#hostname = value;
|
|
130
|
+
}
|
|
131
|
+
get hostname() {
|
|
132
|
+
return this.#hostname;
|
|
133
|
+
}
|
|
134
|
+
set host(value) {
|
|
135
|
+
const parsedHost = (0, ufo.parseHost)(value);
|
|
136
|
+
this.#hostname = parsedHost.hostname;
|
|
137
|
+
this.#port = parsedHost.port;
|
|
138
|
+
}
|
|
139
|
+
get host() {
|
|
140
|
+
return this.#hostname && this.#port ? `${this.#hostname}:${this.#port}` : this.#hostname ? this.#hostname : this.#port ? this.#port : "";
|
|
141
|
+
}
|
|
142
|
+
set paths(value) {
|
|
143
|
+
this.#paths = value.filter(Boolean);
|
|
144
|
+
}
|
|
145
|
+
get paths() {
|
|
146
|
+
return this.#paths;
|
|
147
|
+
}
|
|
148
|
+
set pathname(value) {
|
|
149
|
+
this.paths = (0, ufo.cleanDoubleSlashes)(value).split("/");
|
|
150
|
+
}
|
|
151
|
+
get pathname() {
|
|
152
|
+
return `/${this.paths ? require_join_paths.joinPaths(...this.paths.map((path) => require_storm_json.StormJSON.stringify(path))) : ""}`;
|
|
153
|
+
}
|
|
154
|
+
set path(value) {
|
|
155
|
+
const parsedPath = (0, ufo.parsePath)(value);
|
|
156
|
+
this.pathname = parsedPath.pathname;
|
|
157
|
+
this.search = parsedPath.search;
|
|
158
|
+
this.#hash = parsedPath.hash;
|
|
159
|
+
}
|
|
160
|
+
get path() {
|
|
161
|
+
return (0, ufo.stringifyParsedURL)({
|
|
162
|
+
pathname: this.pathname,
|
|
163
|
+
search: this.search,
|
|
164
|
+
hash: this.hash
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
get href() {
|
|
168
|
+
return this.toString();
|
|
169
|
+
}
|
|
170
|
+
set href(value) {
|
|
171
|
+
const parsedURL = (0, ufo.parseURL)(value);
|
|
172
|
+
this.protocol = parsedURL.protocol || this.protocol;
|
|
173
|
+
this.auth = parsedURL.auth || this.auth;
|
|
174
|
+
this.host = parsedURL.host || this.host;
|
|
175
|
+
this.pathname = parsedURL.pathname || this.pathname;
|
|
176
|
+
this.search = parsedURL.search || this.search;
|
|
177
|
+
this.hash = parsedURL.hash || this.hash;
|
|
178
|
+
}
|
|
179
|
+
get origin() {
|
|
180
|
+
return `${this.protocol}//${this.host}`;
|
|
181
|
+
}
|
|
182
|
+
get isScriptProtocol() {
|
|
183
|
+
return (0, ufo.isScriptProtocol)(this.protocol);
|
|
184
|
+
}
|
|
185
|
+
get isRelative() {
|
|
186
|
+
return (0, ufo.isRelative)(this.toString());
|
|
187
|
+
}
|
|
188
|
+
get isNonEmptyURL() {
|
|
189
|
+
return (0, ufo.isNonEmptyURL)(this.toString());
|
|
190
|
+
}
|
|
191
|
+
get __typename() {
|
|
192
|
+
return "StormURL";
|
|
193
|
+
}
|
|
194
|
+
isSamePath(path) {
|
|
195
|
+
return (0, ufo.isSamePath)(this.path, path);
|
|
196
|
+
}
|
|
197
|
+
isEqual(url) {
|
|
198
|
+
return (0, ufo.isEqual)(this.toString(), typeof url === "string" ? url : url instanceof StormURL ? url.toString() : (0, ufo.stringifyParsedURL)(url));
|
|
199
|
+
}
|
|
200
|
+
toParsed() {
|
|
201
|
+
return {
|
|
202
|
+
protocol: this.protocol,
|
|
203
|
+
auth: this.auth,
|
|
204
|
+
host: this.host,
|
|
205
|
+
pathname: this.pathname,
|
|
206
|
+
search: this.search,
|
|
207
|
+
hash: this.hash
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
toString() {
|
|
211
|
+
return (0, ufo.stringifyParsedURL)(this.toParsed());
|
|
212
|
+
}
|
|
213
|
+
toEncoded() {
|
|
214
|
+
return (0, ufo.normalizeURL)(this.toString());
|
|
215
|
+
}
|
|
216
|
+
toJSON() {
|
|
217
|
+
return require_storm_json.StormJSON.stringify(this.toParsed());
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
require_storm_json.StormJSON.instance.registerCustom({
|
|
221
|
+
isApplicable: (v) => v.__typename === "StormURL",
|
|
222
|
+
serialize: (v) => v.toEncoded(),
|
|
223
|
+
deserialize: (v) => new StormURL(v, { decode: true })
|
|
224
|
+
}, "StormURL");
|
|
225
|
+
|
|
226
|
+
//#endregion
|
|
227
|
+
exports.StormURL = StormURL;
|