@stryke/path 0.24.4 → 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.
Files changed (85) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/append.cjs +59 -1
  3. package/dist/append.mjs +57 -1
  4. package/dist/append.mjs.map +1 -1
  5. package/dist/asset-extensions.cjs +40 -1
  6. package/dist/asset-extensions.mjs +39 -1
  7. package/dist/asset-extensions.mjs.map +1 -1
  8. package/dist/common.cjs +34 -1
  9. package/dist/common.mjs +34 -1
  10. package/dist/common.mjs.map +1 -1
  11. package/dist/correct-path.cjs +176 -1
  12. package/dist/correct-path.mjs +169 -1
  13. package/dist/correct-path.mjs.map +1 -1
  14. package/dist/cwd.cjs +17 -1
  15. package/dist/cwd.mjs +16 -1
  16. package/dist/cwd.mjs.map +1 -1
  17. package/dist/delimiter.cjs +27 -1
  18. package/dist/delimiter.mjs +24 -1
  19. package/dist/delimiter.mjs.map +1 -1
  20. package/dist/file-path-fns.cjs +332 -1
  21. package/dist/file-path-fns.mjs +311 -1
  22. package/dist/file-path-fns.mjs.map +1 -1
  23. package/dist/find.cjs +24 -1
  24. package/dist/find.mjs +3 -1
  25. package/dist/glob-to-regex.cjs +97 -0
  26. package/dist/glob-to-regex.d.cts +50 -0
  27. package/dist/glob-to-regex.d.cts.map +1 -0
  28. package/dist/glob-to-regex.d.mts +50 -0
  29. package/dist/glob-to-regex.d.mts.map +1 -0
  30. package/dist/glob-to-regex.mjs +98 -0
  31. package/dist/glob-to-regex.mjs.map +1 -0
  32. package/dist/index.cjs +73 -1
  33. package/dist/index.d.cts +2 -1
  34. package/dist/index.d.mts +2 -1
  35. package/dist/index.mjs +17 -1
  36. package/dist/is-parent-path.cjs +32 -1
  37. package/dist/is-parent-path.mjs +32 -1
  38. package/dist/is-parent-path.mjs.map +1 -1
  39. package/dist/is-root-dir.cjs +14 -1
  40. package/dist/is-root-dir.mjs +13 -1
  41. package/dist/is-root-dir.mjs.map +1 -1
  42. package/dist/is-type.cjs +92 -1
  43. package/dist/is-type.mjs +87 -1
  44. package/dist/is-type.mjs.map +1 -1
  45. package/dist/join-paths.cjs +108 -1
  46. package/dist/join-paths.mjs +107 -1
  47. package/dist/join-paths.mjs.map +1 -1
  48. package/dist/join.cjs +4 -1
  49. package/dist/join.mjs +3 -1
  50. package/dist/normalize.cjs +10 -1
  51. package/dist/normalize.mjs +3 -1
  52. package/dist/regex.cjs +20 -1
  53. package/dist/regex.mjs +12 -1
  54. package/dist/regex.mjs.map +1 -1
  55. package/dist/replace.cjs +44 -1
  56. package/dist/replace.mjs +43 -1
  57. package/dist/replace.mjs.map +1 -1
  58. package/dist/resolve-parent-path.cjs +18 -1
  59. package/dist/resolve-parent-path.mjs +18 -1
  60. package/dist/resolve-parent-path.mjs.map +1 -1
  61. package/dist/slash.cjs +27 -1
  62. package/dist/slash.mjs +26 -1
  63. package/dist/slash.mjs.map +1 -1
  64. package/dist/type-checks/src/is-empty.cjs +20 -1
  65. package/dist/type-checks/src/is-empty.mjs +20 -1
  66. package/dist/type-checks/src/is-empty.mjs.map +1 -1
  67. package/dist/type-checks/src/is-null.cjs +12 -1
  68. package/dist/type-checks/src/is-null.mjs +11 -1
  69. package/dist/type-checks/src/is-null.mjs.map +1 -1
  70. package/dist/type-checks/src/is-set-string.cjs +20 -1
  71. package/dist/type-checks/src/is-set-string.mjs +20 -1
  72. package/dist/type-checks/src/is-set-string.mjs.map +1 -1
  73. package/dist/type-checks/src/is-set.cjs +19 -1
  74. package/dist/type-checks/src/is-set.mjs +19 -1
  75. package/dist/type-checks/src/is-set.mjs.map +1 -1
  76. package/dist/type-checks/src/is-string.cjs +12 -1
  77. package/dist/type-checks/src/is-string.mjs +11 -1
  78. package/dist/type-checks/src/is-string.mjs.map +1 -1
  79. package/dist/type-checks/src/is-undefined.cjs +8 -1
  80. package/dist/type-checks/src/is-undefined.mjs +7 -1
  81. package/dist/type-checks/src/is-undefined.mjs.map +1 -1
  82. package/dist/types/src/base.cjs +6 -1
  83. package/dist/types/src/base.mjs +5 -1
  84. package/dist/types/src/base.mjs.map +1 -1
  85. package/package.json +9 -5
@@ -1,2 +1,33 @@
1
- import{slash as e}from"./slash.mjs";function t(t,n){let r=e(t.replaceAll(/\\/g,`/`).replace(/\/*$/,``))?.toLowerCase(),i=e(n.replaceAll(/\\/g,`/`).replace(/\/*$/,``))?.toLowerCase();return t!==n&&r!==i&&r.startsWith(`${i}/`)}export{t as isParentPath};
1
+ import { slash } from "./slash.mjs";
2
+
3
+ //#region src/is-parent-path.ts
4
+ /**
5
+ * Check if a given path is a parent of another path.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * isParentPath("/home/user/project/src/index.ts", "/home/user/project/src");
10
+ * // returns true
11
+ * isParentPath("/home/user/project/src/index.ts", "/home/user/project");
12
+ * // returns true
13
+ * isParentPath("/home/user/project/src/index.ts", "/home/user/project/src/other");
14
+ * // returns false
15
+ * isParentPath("/home/user/project/src/index.ts", "/home/user/other");
16
+ * // returns false
17
+ * isParentPath("/home/user/project/src/index.ts", "/home/user/project/src/index.ts");
18
+ * // returns false
19
+ * ```
20
+ *
21
+ * @param childPath - The path to check if it is a child of the parent path.
22
+ * @param parentPath - The path to check if it is a parent of the child path.
23
+ * @returns `true` if `childPath` is a child of `parentPath`, otherwise `false`.
24
+ */
25
+ function isParentPath(childPath, parentPath) {
26
+ const normalizedChild = slash(childPath.replaceAll(/\\/g, "/").replace(/\/*$/, ""))?.toLowerCase();
27
+ const normalizedParent = slash(parentPath.replaceAll(/\\/g, "/").replace(/\/*$/, ""))?.toLowerCase();
28
+ return childPath !== parentPath && normalizedChild !== normalizedParent && normalizedChild.startsWith(`${normalizedParent}/`);
29
+ }
30
+
31
+ //#endregion
32
+ export { isParentPath };
2
33
  //# sourceMappingURL=is-parent-path.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-parent-path.mjs","names":[],"sources":["../src/is-parent-path.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { slash } from \"./slash\";\n\n/**\n * Check if a given path is a parent of another path.\n *\n * @example\n * ```ts\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/project/src\");\n * // returns true\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/project\");\n * // returns true\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/project/src/other\");\n * // returns false\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/other\");\n * // returns false\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/project/src/index.ts\");\n * // returns false\n * ```\n *\n * @param childPath - The path to check if it is a child of the parent path.\n * @param parentPath - The path to check if it is a parent of the child path.\n * @returns `true` if `childPath` is a child of `parentPath`, otherwise `false`.\n */\nexport function isParentPath(childPath: string, parentPath: string): boolean {\n const normalizedChild = slash(\n childPath.replaceAll(/\\\\/g, \"/\").replace(/\\/*$/, \"\")\n )?.toLowerCase();\n const normalizedParent = slash(\n parentPath.replaceAll(/\\\\/g, \"/\").replace(/\\/*$/, \"\")\n )?.toLowerCase();\n\n return (\n childPath !== parentPath &&\n normalizedChild !== normalizedParent &&\n normalizedChild.startsWith(`${normalizedParent}/`)\n );\n}\n"],"mappings":"oCAyCA,SAAgB,EAAa,EAAmB,EAA6B,CAC3E,IAAM,EAAkB,EACtB,EAAU,WAAW,MAAO,IAAI,CAAC,QAAQ,OAAQ,GAAG,CACrD,EAAE,aAAa,CACV,EAAmB,EACvB,EAAW,WAAW,MAAO,IAAI,CAAC,QAAQ,OAAQ,GAAG,CACtD,EAAE,aAAa,CAEhB,OACE,IAAc,GACd,IAAoB,GACpB,EAAgB,WAAW,GAAG,EAAiB,GAAG"}
1
+ {"version":3,"file":"is-parent-path.mjs","names":[],"sources":["../src/is-parent-path.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { slash } from \"./slash\";\n\n/**\n * Check if a given path is a parent of another path.\n *\n * @example\n * ```ts\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/project/src\");\n * // returns true\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/project\");\n * // returns true\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/project/src/other\");\n * // returns false\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/other\");\n * // returns false\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/project/src/index.ts\");\n * // returns false\n * ```\n *\n * @param childPath - The path to check if it is a child of the parent path.\n * @param parentPath - The path to check if it is a parent of the child path.\n * @returns `true` if `childPath` is a child of `parentPath`, otherwise `false`.\n */\nexport function isParentPath(childPath: string, parentPath: string): boolean {\n const normalizedChild = slash(\n childPath.replaceAll(/\\\\/g, \"/\").replace(/\\/*$/, \"\")\n )?.toLowerCase();\n const normalizedParent = slash(\n parentPath.replaceAll(/\\\\/g, \"/\").replace(/\\/*$/, \"\")\n )?.toLowerCase();\n\n return (\n childPath !== parentPath &&\n normalizedChild !== normalizedParent &&\n normalizedChild.startsWith(`${normalizedParent}/`)\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,aAAa,WAAmB,YAA6B;CAC3E,MAAM,kBAAkB,MACtB,UAAU,WAAW,OAAO,IAAI,CAAC,QAAQ,QAAQ,GAAG,CACrD,EAAE,aAAa;CAChB,MAAM,mBAAmB,MACvB,WAAW,WAAW,OAAO,IAAI,CAAC,QAAQ,QAAQ,GAAG,CACtD,EAAE,aAAa;AAEhB,QACE,cAAc,cACd,oBAAoB,oBACpB,gBAAgB,WAAW,GAAG,iBAAiB,GAAG"}
@@ -1 +1,14 @@
1
- function e(e){return e===`/`||e===`c:\\`||e===`C:\\`}exports.isSystemRoot=e;
1
+
2
+ //#region src/is-root-dir.ts
3
+ /**
4
+ * Check if the directory is the current system's root directory.
5
+ *
6
+ * @param dir - The directory to check.
7
+ * @returns Returns true if the directory is the root directory.
8
+ */
9
+ function isSystemRoot(dir) {
10
+ return Boolean(dir === "/" || dir === "c:\\" || dir === "C:\\");
11
+ }
12
+
13
+ //#endregion
14
+ exports.isSystemRoot = isSystemRoot;
@@ -1,2 +1,14 @@
1
- function e(e){return e===`/`||e===`c:\\`||e===`C:\\`}export{e as isSystemRoot};
1
+ //#region src/is-root-dir.ts
2
+ /**
3
+ * Check if the directory is the current system's root directory.
4
+ *
5
+ * @param dir - The directory to check.
6
+ * @returns Returns true if the directory is the root directory.
7
+ */
8
+ function isSystemRoot(dir) {
9
+ return Boolean(dir === "/" || dir === "c:\\" || dir === "C:\\");
10
+ }
11
+
12
+ //#endregion
13
+ export { isSystemRoot };
2
14
  //# sourceMappingURL=is-root-dir.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-root-dir.mjs","names":[],"sources":["../src/is-root-dir.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Check if the directory is the current system's root directory.\n *\n * @param dir - The directory to check.\n * @returns Returns true if the directory is the root directory.\n */\nexport function isSystemRoot(dir: string): boolean {\n return Boolean(dir === \"/\" || dir === \"c:\\\\\" || dir === \"C:\\\\\");\n}\n"],"mappings":"AAwBA,SAAgB,EAAa,EAAsB,CACjD,OAAe,IAAQ,KAAO,IAAQ,QAAU,IAAQ"}
1
+ {"version":3,"file":"is-root-dir.mjs","names":[],"sources":["../src/is-root-dir.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Check if the directory is the current system's root directory.\n *\n * @param dir - The directory to check.\n * @returns Returns true if the directory is the root directory.\n */\nexport function isSystemRoot(dir: string): boolean {\n return Boolean(dir === \"/\" || dir === \"c:\\\\\" || dir === \"C:\\\\\");\n}\n"],"mappings":";;;;;;;AAwBA,SAAgB,aAAa,KAAsB;AACjD,QAAO,QAAQ,QAAQ,OAAO,QAAQ,UAAU,QAAQ,OAAO"}
package/dist/is-type.cjs CHANGED
@@ -1 +1,92 @@
1
- const e=require(`./regex.cjs`),t=require(`./slash.cjs`);function n(n){return e.ABSOLUTE_PATH_REGEX.test(t.slash(n))}function r(e){return n(e)}function i(e){return!n(e)}function a(e){return i(e)}function o(n){return e.NPM_SCOPED_PACKAGE_REGEX.test(t.slash(n))}function s(e){return o(e)}exports.isAbsolute=r,exports.isAbsolutePath=n,exports.isNpmScopedPackage=s,exports.isNpmScopedPackagePath=o,exports.isRelative=a,exports.isRelativePath=i;
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 as e,NPM_SCOPED_PACKAGE_REGEX as t}from"./regex.mjs";import{slash as n}from"./slash.mjs";function r(t){return e.test(n(t))}function i(e){return r(e)}function a(e){return!r(e)}function o(e){return a(e)}function s(e){return t.test(n(e))}function c(e){return s(e)}export{i as isAbsolute,r as isAbsolutePath,c as isNpmScopedPackage,s as isNpmScopedPackagePath,o as isRelative,a as isRelativePath};
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
@@ -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":"oHA2BA,SAAgB,EAAe,EAAuB,CACpD,OAAO,EAAoB,KAAK,EAAM,EAAK,CAAC,CAY9C,SAAgB,EAAW,EAAuB,CAChD,OAAO,EAAe,EAAK,CAS7B,SAAgB,EAAe,EAAuB,CACpD,MAAO,CAAC,EAAe,EAAK,CAY9B,SAAgB,EAAW,EAAuB,CAChD,OAAO,EAAe,EAAK,CAmB7B,SAAgB,EAAuB,EAAuB,CAC5D,OAAO,EAAyB,KAAK,EAAM,EAAK,CAAC,CAmBnD,SAAgB,EAAmB,EAAuB,CACxD,OAAO,EAAuB,EAAK"}
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"}
@@ -1 +1,108 @@
1
- const e=require(`./regex.cjs`),t=require(`./is-type.cjs`);function n(t=``){return t&&t.replace(/\\/g,`/`).replace(e.DRIVE_LETTER_START_REGEX,e=>e.toUpperCase())}function r(r){if(!r||r.length===0)return`.`;r=n(r);let i=r.match(e.UNC_REGEX),a=t.isAbsolute(r),s=r[r.length-1]===`/`;return r=o(r,!a),r.length===0?a?`/`:s?`./`:`.`:(s&&(r+=`/`),e.DRIVE_LETTER_REGEX.test(r)&&(r+=`/`),i?a?`//${r}`:`//./${r}`:a&&!t.isAbsolute(r)?`/${r}`:r)}function i(...e){let t=``;for(let n of e)if(n)if(t.length>0){let e=t[t.length-1]===`/`,r=n[0]===`/`;e&&r?t+=n.slice(1):t+=e||r?n:`/${n}`}else t+=n;return r(t)}const a=i;function o(e,t){let n=``,r=0,i=-1,a=0,o=null;for(let s=0;s<=e.length;++s){if(s<e.length)o=e[s];else if(o===`/`)break;else o=`/`;if(o===`/`){if(!(i===s-1||a===1))if(a===2){if(n.length<2||r!==2||n[n.length-1]!==`.`||n[n.length-2]!==`.`){if(n.length>2){let e=n.lastIndexOf(`/`);e===-1?(n=``,r=0):(n=n.slice(0,e),r=n.length-1-n.lastIndexOf(`/`)),i=s,a=0;continue}else if(n.length>0){n=``,r=0,i=s,a=0;continue}}t&&(n+=n.length>0?`/..`:`..`,r=2)}else n.length>0?n+=`/${e.slice(i+1,s)}`:n=e.slice(i+1,s),r=s-i-1;i=s,a=0}else o===`.`&&a!==-1?++a:a=-1}return n}exports.join=a,exports.joinPaths=i;
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;
@@ -1,2 +1,108 @@
1
- import{DRIVE_LETTER_REGEX as e,DRIVE_LETTER_START_REGEX as t,UNC_REGEX as n}from"./regex.mjs";import{isAbsolute as r}from"./is-type.mjs";function i(e=``){return e&&e.replace(/\\/g,`/`).replace(t,e=>e.toUpperCase())}function a(t){if(!t||t.length===0)return`.`;t=i(t);let a=t.match(n),o=r(t),s=t[t.length-1]===`/`;return t=c(t,!o),t.length===0?o?`/`:s?`./`:`.`:(s&&(t+=`/`),e.test(t)&&(t+=`/`),a?o?`//${t}`:`//./${t}`:o&&!r(t)?`/${t}`:t)}function o(...e){let t=``;for(let n of e)if(n)if(t.length>0){let e=t[t.length-1]===`/`,r=n[0]===`/`;e&&r?t+=n.slice(1):t+=e||r?n:`/${n}`}else t+=n;return a(t)}const s=o;function c(e,t){let n=``,r=0,i=-1,a=0,o=null;for(let s=0;s<=e.length;++s){if(s<e.length)o=e[s];else if(o===`/`)break;else o=`/`;if(o===`/`){if(!(i===s-1||a===1))if(a===2){if(n.length<2||r!==2||n[n.length-1]!==`.`||n[n.length-2]!==`.`){if(n.length>2){let e=n.lastIndexOf(`/`);e===-1?(n=``,r=0):(n=n.slice(0,e),r=n.length-1-n.lastIndexOf(`/`)),i=s,a=0;continue}else if(n.length>0){n=``,r=0,i=s,a=0;continue}}t&&(n+=n.length>0?`/..`:`..`,r=2)}else n.length>0?n+=`/${e.slice(i+1,s)}`:n=e.slice(i+1,s),r=s-i-1;i=s,a=0}else o===`.`&&a!==-1?++a:a=-1}return n}export{s as join,o as joinPaths};
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
@@ -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":"yIA0BA,SAAS,EAAqB,EAAQ,GAAI,CAIxC,OAHK,GAGE,EACJ,QAAQ,MAAO,IAAI,CACnB,QAAQ,EAA0B,GAAK,EAAE,aAAa,CAAC,CAG5D,SAAS,EAAa,EAAe,CACnC,GAAI,CAAC,GAAQ,EAAK,SAAW,EAC3B,MAAO,IAIT,EAAO,EAAqB,EAAK,CAEjC,IAAM,EAAY,EAAK,MAAM,EAAU,CACjC,EAAiB,EAAW,EAAK,CACjC,EAAoB,EAAK,EAAK,OAAS,KAAO,IAyBpD,MAtBA,GAAO,EAAgB,EAAM,CAAC,EAAe,CAEzC,EAAK,SAAW,EACd,EACK,IAEF,EAAoB,KAAO,KAEhC,IACF,GAAQ,KAEN,EAAmB,KAAK,EAAK,GAC/B,GAAQ,KAGN,EACG,EAGE,KAAK,IAFH,OAAO,IAKX,GAAkB,CAAC,EAAW,EAAK,CAAG,IAAI,IAAS,GAU5D,SAAgB,EAAU,GAAG,EAA4B,CACvD,IAAI,EAAO,GAEX,IAAK,IAAM,KAAO,EACX,KAGL,GAAI,EAAK,OAAS,EAAG,CACnB,IAAM,EAAe,EAAK,EAAK,OAAS,KAAO,IACzC,EAAa,EAAI,KAAO,IACjB,GAAgB,EAE3B,GAAQ,EAAI,MAAM,EAAE,CAEpB,GAAQ,GAAgB,EAAa,EAAM,IAAI,SAGjD,GAAQ,EAIZ,OAAO,EAAa,EAAK,CAG3B,MAAa,EAAO,EASpB,SAAS,EAAgB,EAAc,EAAyB,CAC9D,IAAI,EAAM,GACN,EAAoB,EACpB,EAAY,GACZ,EAAO,EACPA,EAAsB,KAC1B,IAAK,IAAI,EAAQ,EAAG,GAAS,EAAK,OAAQ,EAAE,EAAO,CACjD,GAAI,EAAQ,EAAK,OAEf,EAAO,EAAK,WACH,IAAS,IAClB,WAEA,EAAO,IAET,GAAI,IAAS,IAAK,CAChB,GAAI,MAAc,EAAQ,GAAK,IAAS,GAAG,GAEhC,IAAS,EAAG,CACrB,GACE,EAAI,OAAS,GACb,IAAsB,GACtB,EAAI,EAAI,OAAS,KAAO,KACxB,EAAI,EAAI,OAAS,KAAO,QAEpB,EAAI,OAAS,EAAG,CAClB,IAAM,EAAiB,EAAI,YAAY,IAAI,CACvC,IAAmB,IACrB,EAAM,GACN,EAAoB,IAEpB,EAAM,EAAI,MAAM,EAAG,EAAe,CAClC,EAAoB,EAAI,OAAS,EAAI,EAAI,YAAY,IAAI,EAE3D,EAAY,EACZ,EAAO,EACP,iBACS,EAAI,OAAS,EAAG,CACzB,EAAM,GACN,EAAoB,EACpB,EAAY,EACZ,EAAO,EACP,UAGA,IACF,GAAO,EAAI,OAAS,EAAI,MAAQ,KAChC,EAAoB,QAGlB,EAAI,OAAS,EACf,GAAO,IAAI,EAAK,MAAM,EAAY,EAAG,EAAM,GAE3C,EAAM,EAAK,MAAM,EAAY,EAAG,EAAM,CAExC,EAAoB,EAAQ,EAAY,EAE1C,EAAY,EACZ,EAAO,OACE,IAAS,KAAO,IAAS,GAClC,EAAE,EAEF,EAAO,GAGX,OAAO"}
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
@@ -1 +1,4 @@
1
- const e=require(`./join-paths.cjs`);exports.join=e.join,exports.joinPaths=e.joinPaths;
1
+ const require_join_paths = require('./join-paths.cjs');
2
+
3
+ exports.join = require_join_paths.join;
4
+ exports.joinPaths = require_join_paths.joinPaths;
package/dist/join.mjs CHANGED
@@ -1 +1,3 @@
1
- import{join as e,joinPaths as t}from"./join-paths.mjs";export{e as join,t as joinPaths};
1
+ import { join, joinPaths } from "./join-paths.mjs";
2
+
3
+ export { join, joinPaths };
@@ -1 +1,10 @@
1
- const e=require(`./correct-path.cjs`);exports.correctPath=e.correctPath,exports.normalizeString=e.normalizeString,exports.normalizeWindowsPath=e.normalizeWindowsPath,exports.stripStars=e.stripStars,exports.toAbsolutePath=e.toAbsolutePath,exports.toRelativePath=e.toRelativePath,exports.withTrailingSlash=e.withTrailingSlash,exports.withoutTrailingSlash=e.withoutTrailingSlash;
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;
@@ -1 +1,3 @@
1
- import{correctPath as e,normalizeString as t,normalizeWindowsPath as n,stripStars as r,toAbsolutePath as i,toRelativePath as a,withTrailingSlash as o,withoutTrailingSlash as s}from"./correct-path.mjs";export{e as correctPath,t as normalizeString,n as normalizeWindowsPath,r as stripStars,i as toAbsolutePath,a as toRelativePath,o as withTrailingSlash,s as withoutTrailingSlash};
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
- const e=/^[A-Z]:\//i,t=/^[A-Z]:$/i,n=/^[/\\]{2}/,r=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i,i=/^\/([A-Z]:)?$/i,a=/\.[0-9a-z]+$/i,o=/^@\w+\/.*$/,s=/^(?:@[\w-]+\/)?[\w-]+$/;exports.ABSOLUTE_PATH_REGEX=r,exports.DRIVE_LETTER_REGEX=t,exports.DRIVE_LETTER_START_REGEX=e,exports.FILE_EXTENSION_REGEX=a,exports.NPM_SCOPED_PACKAGE_REGEX=s,exports.PACKAGE_PATH_REGEX=o,exports.ROOT_FOLDER_REGEX=i,exports.UNC_REGEX=n;
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
- const e=/^[A-Z]:\//i,t=/^[A-Z]:$/i,n=/^[/\\]{2}/,r=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i,i=/^\/([A-Z]:)?$/i,a=/\.[0-9a-z]+$/i,o=/^@\w+\/.*$/,s=/^(?:@[\w-]+\/)?[\w-]+$/;export{r as ABSOLUTE_PATH_REGEX,t as DRIVE_LETTER_REGEX,e as DRIVE_LETTER_START_REGEX,a as FILE_EXTENSION_REGEX,s as NPM_SCOPED_PACKAGE_REGEX,o as PACKAGE_PATH_REGEX,i as ROOT_FOLDER_REGEX,n as UNC_REGEX};
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