@stryke/fs 0.33.32 → 0.33.33

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 (191) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -1
  3. package/dist/buffer.cjs +60 -1
  4. package/dist/buffer.mjs +56 -1
  5. package/dist/buffer.mjs.map +1 -1
  6. package/dist/chmod-x.cjs +93 -1
  7. package/dist/chmod-x.d.cts.map +1 -1
  8. package/dist/chmod-x.mjs +87 -1
  9. package/dist/chmod-x.mjs.map +1 -1
  10. package/dist/command-exists.cjs +102 -1
  11. package/dist/command-exists.mjs +100 -1
  12. package/dist/command-exists.mjs.map +1 -1
  13. package/dist/compress.cjs +29 -1
  14. package/dist/compress.mjs +28 -1
  15. package/dist/compress.mjs.map +1 -1
  16. package/dist/constants.mjs +1 -1
  17. package/dist/convert/src/array-buffer-to-string.cjs +19 -1
  18. package/dist/convert/src/array-buffer-to-string.mjs +18 -1
  19. package/dist/convert/src/array-buffer-to-string.mjs.map +1 -1
  20. package/dist/convert/src/to-array.cjs +15 -1
  21. package/dist/convert/src/to-array.mjs +14 -1
  22. package/dist/convert/src/to-array.mjs.map +1 -1
  23. package/dist/convert/src/uint8-array-to-string.cjs +15 -1
  24. package/dist/convert/src/uint8-array-to-string.mjs +15 -1
  25. package/dist/convert/src/uint8-array-to-string.mjs.map +1 -1
  26. package/dist/copy-file.cjs +87 -1
  27. package/dist/copy-file.mjs +83 -1
  28. package/dist/copy-file.mjs.map +1 -1
  29. package/dist/exists.cjs +27 -1
  30. package/dist/exists.mjs +25 -1
  31. package/dist/exists.mjs.map +1 -1
  32. package/dist/get-parent-path.cjs +35 -1
  33. package/dist/get-parent-path.mjs +34 -1
  34. package/dist/get-parent-path.mjs.map +1 -1
  35. package/dist/get-workspace-root.cjs +158 -1
  36. package/dist/get-workspace-root.mjs +150 -1
  37. package/dist/get-workspace-root.mjs.map +1 -1
  38. package/dist/helpers/src/get-unique.cjs +14 -1
  39. package/dist/helpers/src/get-unique.mjs +13 -1
  40. package/dist/helpers/src/get-unique.mjs.map +1 -1
  41. package/dist/helpers.cjs +83 -1
  42. package/dist/helpers.mjs +77 -1
  43. package/dist/helpers.mjs.map +1 -1
  44. package/dist/index.cjs +122 -1
  45. package/dist/index.mjs +25 -1
  46. package/dist/install.cjs +35 -1
  47. package/dist/install.mjs +33 -1
  48. package/dist/install.mjs.map +1 -1
  49. package/dist/is-file.cjs +51 -1
  50. package/dist/is-file.mjs +47 -1
  51. package/dist/is-file.mjs.map +1 -1
  52. package/dist/json/src/storm-json.cjs +117 -1
  53. package/dist/json/src/storm-json.mjs +115 -1
  54. package/dist/json/src/storm-json.mjs.map +1 -1
  55. package/dist/json/src/utils/code-frames.cjs +77 -3
  56. package/dist/json/src/utils/code-frames.mjs +76 -3
  57. package/dist/json/src/utils/code-frames.mjs.map +1 -1
  58. package/dist/json/src/utils/parse-error.cjs +34 -1
  59. package/dist/json/src/utils/parse-error.mjs +33 -1
  60. package/dist/json/src/utils/parse-error.mjs.map +1 -1
  61. package/dist/json/src/utils/parse.cjs +45 -1
  62. package/dist/json/src/utils/parse.mjs +45 -1
  63. package/dist/json/src/utils/parse.mjs.map +1 -1
  64. package/dist/json/src/utils/stringify.cjs +67 -1
  65. package/dist/json/src/utils/stringify.mjs +67 -1
  66. package/dist/json/src/utils/stringify.mjs.map +1 -1
  67. package/dist/json/src/utils/strip-comments.cjs +86 -4
  68. package/dist/json/src/utils/strip-comments.mjs +86 -4
  69. package/dist/json/src/utils/strip-comments.mjs.map +1 -1
  70. package/dist/json.cjs +74 -1
  71. package/dist/json.mjs +71 -1
  72. package/dist/json.mjs.map +1 -1
  73. package/dist/list-files.cjs +86 -1
  74. package/dist/list-files.mjs +79 -1
  75. package/dist/list-files.mjs.map +1 -1
  76. package/dist/package-fns.cjs +148 -1
  77. package/dist/package-fns.mjs +141 -1
  78. package/dist/package-fns.mjs.map +1 -1
  79. package/dist/path/src/append.cjs +57 -1
  80. package/dist/path/src/append.mjs +56 -1
  81. package/dist/path/src/append.mjs.map +1 -1
  82. package/dist/path/src/correct-path.cjs +138 -1
  83. package/dist/path/src/correct-path.mjs +134 -1
  84. package/dist/path/src/correct-path.mjs.map +1 -1
  85. package/dist/path/src/cwd.cjs +17 -1
  86. package/dist/path/src/cwd.mjs +16 -1
  87. package/dist/path/src/cwd.mjs.map +1 -1
  88. package/dist/path/src/file-path-fns.cjs +169 -1
  89. package/dist/path/src/file-path-fns.mjs +164 -1
  90. package/dist/path/src/file-path-fns.mjs.map +1 -1
  91. package/dist/path/src/is-parent-path.cjs +32 -1
  92. package/dist/path/src/is-parent-path.mjs +32 -1
  93. package/dist/path/src/is-parent-path.mjs.map +1 -1
  94. package/dist/path/src/is-root-dir.cjs +14 -1
  95. package/dist/path/src/is-root-dir.mjs +13 -1
  96. package/dist/path/src/is-root-dir.mjs.map +1 -1
  97. package/dist/path/src/is-type.cjs +68 -1
  98. package/dist/path/src/is-type.mjs +66 -1
  99. package/dist/path/src/is-type.mjs.map +1 -1
  100. package/dist/path/src/join-paths.cjs +106 -1
  101. package/dist/path/src/join-paths.mjs +106 -1
  102. package/dist/path/src/join-paths.mjs.map +1 -1
  103. package/dist/path/src/regex.cjs +18 -1
  104. package/dist/path/src/regex.mjs +11 -1
  105. package/dist/path/src/regex.mjs.map +1 -1
  106. package/dist/path/src/replace.cjs +24 -1
  107. package/dist/path/src/replace.mjs +24 -1
  108. package/dist/path/src/replace.mjs.map +1 -1
  109. package/dist/path/src/resolve-parent-path.cjs +18 -1
  110. package/dist/path/src/resolve-parent-path.mjs +18 -1
  111. package/dist/path/src/resolve-parent-path.mjs.map +1 -1
  112. package/dist/path/src/slash.cjs +15 -1
  113. package/dist/path/src/slash.mjs +14 -1
  114. package/dist/path/src/slash.mjs.map +1 -1
  115. package/dist/read-file.cjs +47 -1
  116. package/dist/read-file.mjs +43 -1
  117. package/dist/read-file.mjs.map +1 -1
  118. package/dist/registry.cjs +142 -1
  119. package/dist/registry.mjs +137 -1
  120. package/dist/registry.mjs.map +1 -1
  121. package/dist/remove-file.cjs +27 -1
  122. package/dist/remove-file.mjs +25 -1
  123. package/dist/remove-file.mjs.map +1 -1
  124. package/dist/resolve.cjs +228 -3
  125. package/dist/resolve.mjs +217 -3
  126. package/dist/resolve.mjs.map +1 -1
  127. package/dist/semver-fns.cjs +129 -1
  128. package/dist/semver-fns.mjs +119 -1
  129. package/dist/semver-fns.mjs.map +1 -1
  130. package/dist/string-format/src/package.cjs +92 -1
  131. package/dist/string-format/src/package.mjs +91 -1
  132. package/dist/string-format/src/package.mjs.map +1 -1
  133. package/dist/toml.cjs +66 -3
  134. package/dist/toml.mjs +61 -3
  135. package/dist/toml.mjs.map +1 -1
  136. package/dist/tsconfig.cjs +37 -1
  137. package/dist/tsconfig.mjs +35 -1
  138. package/dist/tsconfig.mjs.map +1 -1
  139. package/dist/type-checks/src/get-object-tag.cjs +15 -1
  140. package/dist/type-checks/src/get-object-tag.mjs +14 -1
  141. package/dist/type-checks/src/get-object-tag.mjs.map +1 -1
  142. package/dist/type-checks/src/index.cjs +14 -1
  143. package/dist/type-checks/src/index.mjs +16 -1
  144. package/dist/type-checks/src/is-buffer.cjs +12 -1
  145. package/dist/type-checks/src/is-buffer.mjs +11 -1
  146. package/dist/type-checks/src/is-buffer.mjs.map +1 -1
  147. package/dist/type-checks/src/is-collection.cjs +1 -1
  148. package/dist/type-checks/src/is-collection.mjs +3 -1
  149. package/dist/type-checks/src/is-empty.cjs +20 -1
  150. package/dist/type-checks/src/is-empty.mjs +20 -1
  151. package/dist/type-checks/src/is-empty.mjs.map +1 -1
  152. package/dist/type-checks/src/is-error.cjs +29 -1
  153. package/dist/type-checks/src/is-error.mjs +29 -1
  154. package/dist/type-checks/src/is-error.mjs.map +1 -1
  155. package/dist/type-checks/src/is-null.cjs +12 -1
  156. package/dist/type-checks/src/is-null.mjs +11 -1
  157. package/dist/type-checks/src/is-null.mjs.map +1 -1
  158. package/dist/type-checks/src/is-number.cjs +18 -1
  159. package/dist/type-checks/src/is-number.mjs +17 -1
  160. package/dist/type-checks/src/is-number.mjs.map +1 -1
  161. package/dist/type-checks/src/is-object.cjs +19 -1
  162. package/dist/type-checks/src/is-object.mjs +19 -1
  163. package/dist/type-checks/src/is-object.mjs.map +1 -1
  164. package/dist/type-checks/src/is-plain-object.cjs +64 -1
  165. package/dist/type-checks/src/is-plain-object.mjs +63 -1
  166. package/dist/type-checks/src/is-plain-object.mjs.map +1 -1
  167. package/dist/type-checks/src/is-set-string.cjs +20 -1
  168. package/dist/type-checks/src/is-set-string.mjs +20 -1
  169. package/dist/type-checks/src/is-set-string.mjs.map +1 -1
  170. package/dist/type-checks/src/is-set.cjs +19 -1
  171. package/dist/type-checks/src/is-set.mjs +19 -1
  172. package/dist/type-checks/src/is-set.mjs.map +1 -1
  173. package/dist/type-checks/src/is-string.cjs +12 -1
  174. package/dist/type-checks/src/is-string.mjs +11 -1
  175. package/dist/type-checks/src/is-string.mjs.map +1 -1
  176. package/dist/type-checks/src/is-undefined.cjs +8 -1
  177. package/dist/type-checks/src/is-undefined.mjs +7 -1
  178. package/dist/type-checks/src/is-undefined.mjs.map +1 -1
  179. package/dist/type-checks/src/type-detect.cjs +15 -1
  180. package/dist/type-checks/src/type-detect.mjs +16 -1
  181. package/dist/type-checks/src/type-detect.mjs.map +1 -1
  182. package/dist/types/src/base.cjs +6 -1
  183. package/dist/types/src/base.mjs +5 -1
  184. package/dist/types/src/base.mjs.map +1 -1
  185. package/dist/write-file.cjs +40 -1
  186. package/dist/write-file.mjs +38 -1
  187. package/dist/write-file.mjs.map +1 -1
  188. package/dist/yaml.cjs +29 -1
  189. package/dist/yaml.mjs +27 -1
  190. package/dist/yaml.mjs.map +1 -1
  191. package/package.json +6 -6
@@ -1,2 +1,57 @@
1
- import{cwd as e}from"./cwd.mjs";import{slash as t}from"./slash.mjs";import{isParentPath as n}from"./is-parent-path.mjs";import{joinPaths as r}from"./join-paths.mjs";function i(i,a=e(),o={}){return t(o.skipIfAlreadyParent!==!1&&n(i,a)?i:r(a,i))}function a(e,t){return`${e}.${t.replace(/^\./,``)}`}export{a as appendExtension,i as appendPath};
1
+ import { cwd } from "./cwd.mjs";
2
+ import { slash } from "./slash.mjs";
3
+ import { isParentPath } from "./is-parent-path.mjs";
4
+ import { joinPaths } from "./join-paths.mjs";
5
+
6
+ //#region ../path/src/append.ts
7
+ /**
8
+ * If not already a parent path, append the base path from the beginning of the given child path.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * appendPath("src/index.ts", "/home/user/project");
13
+ * // returns "/home/user/project/src/index.ts"
14
+ *
15
+ * appendPath("/user/dev/app.ts", "/user/dev");
16
+ * // returns "/user/dev/app.ts"
17
+ *
18
+ * appendPath("docs/readme.md");
19
+ * // returns "<current_working_directory>/docs/readme.md"
20
+ *
21
+ * appendPath("src/index.ts", "/home/user/project", { skipIfAlreadyParent: false });
22
+ * // returns "/home/user/project/src/index.ts"
23
+ *
24
+ * appendPath("/home/user/project/src/index.ts", "/home/user/project", { skipIfAlreadyParent: false });
25
+ * // returns "/home/user/project/src/index.ts"
26
+ * ```
27
+ *
28
+ * @param childPath - The child path to append to the {@link parentPath}
29
+ * @param parentPath - The parent path to add the {@link childPath} to
30
+ * @param options - Options for appending the path
31
+ * @returns The {@link parentPath} with the {@link childPath} appended
32
+ */
33
+ function appendPath(childPath, parentPath = cwd(), options = {}) {
34
+ return slash(options.skipIfAlreadyParent !== false && isParentPath(childPath, parentPath) ? childPath : joinPaths(parentPath, childPath));
35
+ }
36
+ /**
37
+ * Append the extension to the given path.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * appendExtension("/home/user/project/src/index", ".ts");
42
+ * // returns "/home/user/project/src/index.ts"
43
+ * appendExtension("/home/user/project/src/index.ts", ".js");
44
+ * // returns "/home/user/project/src/index.ts.js"
45
+ * ```
46
+ *
47
+ * @param path - The path to append the extension to.
48
+ * @param extension - The extension to append.
49
+ * @returns The path with the appended extension.
50
+ */
51
+ function appendExtension(path, extension) {
52
+ return `${path}.${extension.replace(/^\./, "")}`;
53
+ }
54
+
55
+ //#endregion
56
+ export { appendExtension, appendPath };
2
57
  //# sourceMappingURL=append.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"append.mjs","names":[],"sources":["../../../../path/src/append.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { cwd } from \"./cwd\";\nimport { isParentPath } from \"./is-parent-path\";\nimport { joinPaths } from \"./join-paths\";\nimport { slash } from \"./slash\";\n\nexport interface AppendPathOptions {\n /**\n * If `true`, the function will skip appending if the `childPath` is already a child of the `parentPath`.\n *\n * @defaultValue true\n */\n skipIfAlreadyParent?: boolean;\n}\n\n/**\n * If not already a parent path, append the base path from the beginning of the given child path.\n *\n * @example\n * ```ts\n * appendPath(\"src/index.ts\", \"/home/user/project\");\n * // returns \"/home/user/project/src/index.ts\"\n *\n * appendPath(\"/user/dev/app.ts\", \"/user/dev\");\n * // returns \"/user/dev/app.ts\"\n *\n * appendPath(\"docs/readme.md\");\n * // returns \"<current_working_directory>/docs/readme.md\"\n *\n * appendPath(\"src/index.ts\", \"/home/user/project\", { skipIfAlreadyParent: false });\n * // returns \"/home/user/project/src/index.ts\"\n *\n * appendPath(\"/home/user/project/src/index.ts\", \"/home/user/project\", { skipIfAlreadyParent: false });\n * // returns \"/home/user/project/src/index.ts\"\n * ```\n *\n * @param childPath - The child path to append to the {@link parentPath}\n * @param parentPath - The parent path to add the {@link childPath} to\n * @param options - Options for appending the path\n * @returns The {@link parentPath} with the {@link childPath} appended\n */\nexport function appendPath(\n childPath: string,\n parentPath: string = cwd(),\n options: AppendPathOptions = {}\n): string {\n return slash(\n options.skipIfAlreadyParent !== false && isParentPath(childPath, parentPath)\n ? childPath\n : joinPaths(parentPath, childPath)\n );\n}\n\nexport const append = appendPath;\n\n/**\n * Append the extension to the given path.\n *\n * @example\n * ```ts\n * appendExtension(\"/home/user/project/src/index\", \".ts\");\n * // returns \"/home/user/project/src/index.ts\"\n * appendExtension(\"/home/user/project/src/index.ts\", \".js\");\n * // returns \"/home/user/project/src/index.ts.js\"\n * ```\n *\n * @param path - The path to append the extension to.\n * @param extension - The extension to append.\n * @returns The path with the appended extension.\n */\nexport function appendExtension(path: string, extension: string): string {\n return `${path}.${extension.replace(/^\\./, \"\")}`;\n}\n"],"mappings":"qKA0DA,SAAgB,EACd,EACA,EAAqB,GAAK,CAC1B,EAA6B,EAAE,CACvB,CACR,OAAO,EACL,EAAQ,sBAAwB,IAAS,EAAa,EAAW,EAAW,CACxE,EACA,EAAU,EAAY,EAAU,CACrC,CAoBH,SAAgB,EAAgB,EAAc,EAA2B,CACvE,MAAO,GAAG,EAAK,GAAG,EAAU,QAAQ,MAAO,GAAG"}
1
+ {"version":3,"file":"append.mjs","names":[],"sources":["../../../../path/src/append.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { cwd } from \"./cwd\";\nimport { isParentPath } from \"./is-parent-path\";\nimport { joinPaths } from \"./join-paths\";\nimport { slash } from \"./slash\";\n\nexport interface AppendPathOptions {\n /**\n * If `true`, the function will skip appending if the `childPath` is already a child of the `parentPath`.\n *\n * @defaultValue true\n */\n skipIfAlreadyParent?: boolean;\n}\n\n/**\n * If not already a parent path, append the base path from the beginning of the given child path.\n *\n * @example\n * ```ts\n * appendPath(\"src/index.ts\", \"/home/user/project\");\n * // returns \"/home/user/project/src/index.ts\"\n *\n * appendPath(\"/user/dev/app.ts\", \"/user/dev\");\n * // returns \"/user/dev/app.ts\"\n *\n * appendPath(\"docs/readme.md\");\n * // returns \"<current_working_directory>/docs/readme.md\"\n *\n * appendPath(\"src/index.ts\", \"/home/user/project\", { skipIfAlreadyParent: false });\n * // returns \"/home/user/project/src/index.ts\"\n *\n * appendPath(\"/home/user/project/src/index.ts\", \"/home/user/project\", { skipIfAlreadyParent: false });\n * // returns \"/home/user/project/src/index.ts\"\n * ```\n *\n * @param childPath - The child path to append to the {@link parentPath}\n * @param parentPath - The parent path to add the {@link childPath} to\n * @param options - Options for appending the path\n * @returns The {@link parentPath} with the {@link childPath} appended\n */\nexport function appendPath(\n childPath: string,\n parentPath: string = cwd(),\n options: AppendPathOptions = {}\n): string {\n return slash(\n options.skipIfAlreadyParent !== false && isParentPath(childPath, parentPath)\n ? childPath\n : joinPaths(parentPath, childPath)\n );\n}\n\nexport const append = appendPath;\n\n/**\n * Append the extension to the given path.\n *\n * @example\n * ```ts\n * appendExtension(\"/home/user/project/src/index\", \".ts\");\n * // returns \"/home/user/project/src/index.ts\"\n * appendExtension(\"/home/user/project/src/index.ts\", \".js\");\n * // returns \"/home/user/project/src/index.ts.js\"\n * ```\n *\n * @param path - The path to append the extension to.\n * @param extension - The extension to append.\n * @returns The path with the appended extension.\n */\nexport function appendExtension(path: string, extension: string): string {\n return `${path}.${extension.replace(/^\\./, \"\")}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,WACd,WACA,aAAqB,KAAK,EAC1B,UAA6B,EAAE,EACvB;AACR,QAAO,MACL,QAAQ,wBAAwB,SAAS,aAAa,WAAW,WAAW,GACxE,YACA,UAAU,YAAY,UAAU,CACrC;;;;;;;;;;;;;;;;;AAoBH,SAAgB,gBAAgB,MAAc,WAA2B;AACvE,QAAO,GAAG,KAAK,GAAG,UAAU,QAAQ,OAAO,GAAG"}
@@ -1 +1,138 @@
1
- const e=require(`./cwd.cjs`),t=require(`./regex.cjs`),n=require(`./is-type.cjs`),r=require(`./slash.cjs`),i=require(`./append.cjs`);function a(e=``){return e&&r.slash(e).replace(t.DRIVE_LETTER_START_REGEX,e=>e.toUpperCase())}function o(e){if(!e||e.length===0)return`.`;e=a(e);let r=e.match(t.UNC_REGEX),i=n.isAbsolutePath(e),o=e.endsWith(`/`);return e=c(e,!i),e.length===0?i?`/`:o?`./`:`.`:(o&&(e+=`/`),t.DRIVE_LETTER_REGEX.test(e)&&(e+=`/`),r?i?`//${e}`:`//./${e}`:!e.startsWith(`/`)&&i&&!t.DRIVE_LETTER_REGEX.test(e)?`/${e}`:e)}function s(e){if(!e||e.length===0)return`.`;e=o(e);let t=!1;return`${e.startsWith(`/`)?`/`:``}${e.split(`/`).reduce((e,n)=>n?.trim()?t||n.includes(`*`)?(t=!0,e):e+(e?`/${n}`:n):e,``)}`}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}function l(t,a=e.cwd()){return n.isAbsolutePath(t)?t:r.slash(c(i.appendPath(t,a),!0))}exports.correctPath=o,exports.normalizeString=c,exports.normalizeWindowsPath=a,exports.stripStars=s,exports.toAbsolutePath=l;
1
+ const require_cwd = require('./cwd.cjs');
2
+ const require_regex = require('./regex.cjs');
3
+ const require_is_type = require('./is-type.cjs');
4
+ const require_slash = require('./slash.cjs');
5
+ const require_append = require('./append.cjs');
6
+
7
+ //#region ../path/src/correct-path.ts
8
+ function normalizeWindowsPath(input = "") {
9
+ if (!input) return input;
10
+ return require_slash.slash(input).replace(require_regex.DRIVE_LETTER_START_REGEX, (r) => r.toUpperCase());
11
+ }
12
+ /**
13
+ * Corrects/normalized a file path.
14
+ *
15
+ * @param path - The path to correct.
16
+ * @returns The corrected path.
17
+ */
18
+ function correctPath(path) {
19
+ if (!path || path.length === 0) return ".";
20
+ path = normalizeWindowsPath(path);
21
+ const isUNCPath = path.match(require_regex.UNC_REGEX);
22
+ const isPathAbsolute = require_is_type.isAbsolutePath(path);
23
+ const trailingSeparator = path.endsWith("/");
24
+ path = normalizeString(path, !isPathAbsolute);
25
+ if (path.length === 0) {
26
+ if (isPathAbsolute) return "/";
27
+ return trailingSeparator ? "./" : ".";
28
+ }
29
+ if (trailingSeparator) path += "/";
30
+ if (require_regex.DRIVE_LETTER_REGEX.test(path)) path += "/";
31
+ if (isUNCPath) {
32
+ if (!isPathAbsolute) return `//./${path}`;
33
+ return `//${path}`;
34
+ }
35
+ return !path.startsWith("/") && isPathAbsolute && !require_regex.DRIVE_LETTER_REGEX.test(path) ? `/${path}` : path;
36
+ }
37
+ /**
38
+ * Remove any star tokens (*) from the end of the file path
39
+ *
40
+ * @example
41
+ * stripStars("src/**") // returns "src"
42
+ * stripStars("src/*") // returns "src"
43
+ * stripStars("src/**\/*") // returns "src"
44
+ * stripStars("src/**\/*.txt") // returns "src"
45
+ * stripStars("src/**\/file.txt") // returns "src"
46
+ * stripStars("src/file.txt") // returns "src/file.txt"
47
+ * stripStars("") // returns "."
48
+ *
49
+ * @param path - The path to correct.
50
+ * @returns The corrected path.
51
+ */
52
+ function stripStars(path) {
53
+ if (!path || path.length === 0) return ".";
54
+ path = correctPath(path);
55
+ let found = false;
56
+ return `${path.startsWith("/") ? "/" : ""}${path.split("/").reduce((ret, segment) => {
57
+ if (!segment?.trim()) return ret;
58
+ if (found || segment.includes("*")) {
59
+ found = true;
60
+ return ret;
61
+ }
62
+ return ret + (ret ? `/${segment}` : segment);
63
+ }, "")}`;
64
+ }
65
+ /**
66
+ * Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.
67
+ *
68
+ * @param path - The path to normalize.
69
+ * @param allowAboveRoot - Whether to allow the resulting path to be above the root directory.
70
+ * @returns the normalize path string.
71
+ */
72
+ function normalizeString(path, allowAboveRoot) {
73
+ let res = "";
74
+ let lastSegmentLength = 0;
75
+ let lastSlash = -1;
76
+ let dots = 0;
77
+ let char = null;
78
+ for (let index = 0; index <= path.length; ++index) {
79
+ if (index < path.length) char = path[index];
80
+ else if (char === "/") break;
81
+ else char = "/";
82
+ if (char === "/") {
83
+ if (lastSlash === index - 1 || dots === 1) {} else if (dots === 2) {
84
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
85
+ if (res.length > 2) {
86
+ const lastSlashIndex = res.lastIndexOf("/");
87
+ if (lastSlashIndex === -1) {
88
+ res = "";
89
+ lastSegmentLength = 0;
90
+ } else {
91
+ res = res.slice(0, lastSlashIndex);
92
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
93
+ }
94
+ lastSlash = index;
95
+ dots = 0;
96
+ continue;
97
+ } else if (res.length > 0) {
98
+ res = "";
99
+ lastSegmentLength = 0;
100
+ lastSlash = index;
101
+ dots = 0;
102
+ continue;
103
+ }
104
+ }
105
+ if (allowAboveRoot) {
106
+ res += res.length > 0 ? "/.." : "..";
107
+ lastSegmentLength = 2;
108
+ }
109
+ } else {
110
+ if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
111
+ else res = path.slice(lastSlash + 1, index);
112
+ lastSegmentLength = index - lastSlash - 1;
113
+ }
114
+ lastSlash = index;
115
+ dots = 0;
116
+ } else if (char === "." && dots !== -1) ++dots;
117
+ else dots = -1;
118
+ }
119
+ return res;
120
+ }
121
+ /**
122
+ * Converts a given path to an absolute path based on the current working directory.
123
+ *
124
+ * @param path - The path to convert to an absolute path.
125
+ * @param cwd - The current working directory to use as the base path if the path is not absolute.
126
+ * @returns The absolute path.
127
+ */
128
+ function toAbsolutePath(path, cwd$1 = require_cwd.cwd()) {
129
+ if (require_is_type.isAbsolutePath(path)) return path;
130
+ return require_slash.slash(normalizeString(require_append.appendPath(path, cwd$1), true));
131
+ }
132
+
133
+ //#endregion
134
+ exports.correctPath = correctPath;
135
+ exports.normalizeString = normalizeString;
136
+ exports.normalizeWindowsPath = normalizeWindowsPath;
137
+ exports.stripStars = stripStars;
138
+ exports.toAbsolutePath = toAbsolutePath;
@@ -1,2 +1,135 @@
1
- import{cwd as e}from"./cwd.mjs";import{DRIVE_LETTER_REGEX as t,DRIVE_LETTER_START_REGEX as n,UNC_REGEX as r}from"./regex.mjs";import{isAbsolutePath as i}from"./is-type.mjs";import{slash as a}from"./slash.mjs";import{appendPath as o}from"./append.mjs";function s(e=``){return e&&a(e).replace(n,e=>e.toUpperCase())}function c(e){if(!e||e.length===0)return`.`;e=s(e);let n=e.match(r),a=i(e),o=e.endsWith(`/`);return e=u(e,!a),e.length===0?a?`/`:o?`./`:`.`:(o&&(e+=`/`),t.test(e)&&(e+=`/`),n?a?`//${e}`:`//./${e}`:!e.startsWith(`/`)&&a&&!t.test(e)?`/${e}`:e)}function l(e){if(!e||e.length===0)return`.`;e=c(e);let t=!1;return`${e.startsWith(`/`)?`/`:``}${e.split(`/`).reduce((e,n)=>n?.trim()?t||n.includes(`*`)?(t=!0,e):e+(e?`/${n}`:n):e,``)}`}function u(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}function d(t,n=e()){return i(t)?t:a(u(o(t,n),!0))}export{c as correctPath,u as normalizeString,s as normalizeWindowsPath,l as stripStars,d as toAbsolutePath};
1
+ import { cwd } from "./cwd.mjs";
2
+ import { DRIVE_LETTER_REGEX, DRIVE_LETTER_START_REGEX, UNC_REGEX } from "./regex.mjs";
3
+ import { isAbsolutePath } from "./is-type.mjs";
4
+ import { slash } from "./slash.mjs";
5
+ import { appendPath } from "./append.mjs";
6
+
7
+ //#region ../path/src/correct-path.ts
8
+ function normalizeWindowsPath(input = "") {
9
+ if (!input) return input;
10
+ return slash(input).replace(DRIVE_LETTER_START_REGEX, (r) => r.toUpperCase());
11
+ }
12
+ /**
13
+ * Corrects/normalized a file path.
14
+ *
15
+ * @param path - The path to correct.
16
+ * @returns The corrected path.
17
+ */
18
+ function correctPath(path) {
19
+ if (!path || path.length === 0) return ".";
20
+ path = normalizeWindowsPath(path);
21
+ const isUNCPath = path.match(UNC_REGEX);
22
+ const isPathAbsolute = isAbsolutePath(path);
23
+ const trailingSeparator = path.endsWith("/");
24
+ path = normalizeString(path, !isPathAbsolute);
25
+ if (path.length === 0) {
26
+ if (isPathAbsolute) return "/";
27
+ return trailingSeparator ? "./" : ".";
28
+ }
29
+ if (trailingSeparator) path += "/";
30
+ if (DRIVE_LETTER_REGEX.test(path)) path += "/";
31
+ if (isUNCPath) {
32
+ if (!isPathAbsolute) return `//./${path}`;
33
+ return `//${path}`;
34
+ }
35
+ return !path.startsWith("/") && isPathAbsolute && !DRIVE_LETTER_REGEX.test(path) ? `/${path}` : path;
36
+ }
37
+ /**
38
+ * Remove any star tokens (*) from the end of the file path
39
+ *
40
+ * @example
41
+ * stripStars("src/**") // returns "src"
42
+ * stripStars("src/*") // returns "src"
43
+ * stripStars("src/**\/*") // returns "src"
44
+ * stripStars("src/**\/*.txt") // returns "src"
45
+ * stripStars("src/**\/file.txt") // returns "src"
46
+ * stripStars("src/file.txt") // returns "src/file.txt"
47
+ * stripStars("") // returns "."
48
+ *
49
+ * @param path - The path to correct.
50
+ * @returns The corrected path.
51
+ */
52
+ function stripStars(path) {
53
+ if (!path || path.length === 0) return ".";
54
+ path = correctPath(path);
55
+ let found = false;
56
+ return `${path.startsWith("/") ? "/" : ""}${path.split("/").reduce((ret, segment) => {
57
+ if (!segment?.trim()) return ret;
58
+ if (found || segment.includes("*")) {
59
+ found = true;
60
+ return ret;
61
+ }
62
+ return ret + (ret ? `/${segment}` : segment);
63
+ }, "")}`;
64
+ }
65
+ /**
66
+ * Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.
67
+ *
68
+ * @param path - The path to normalize.
69
+ * @param allowAboveRoot - Whether to allow the resulting path to be above the root directory.
70
+ * @returns the normalize path string.
71
+ */
72
+ function normalizeString(path, allowAboveRoot) {
73
+ let res = "";
74
+ let lastSegmentLength = 0;
75
+ let lastSlash = -1;
76
+ let dots = 0;
77
+ let char = null;
78
+ for (let index = 0; index <= path.length; ++index) {
79
+ if (index < path.length) char = path[index];
80
+ else if (char === "/") break;
81
+ else char = "/";
82
+ if (char === "/") {
83
+ if (lastSlash === index - 1 || dots === 1) {} else if (dots === 2) {
84
+ if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
85
+ if (res.length > 2) {
86
+ const lastSlashIndex = res.lastIndexOf("/");
87
+ if (lastSlashIndex === -1) {
88
+ res = "";
89
+ lastSegmentLength = 0;
90
+ } else {
91
+ res = res.slice(0, lastSlashIndex);
92
+ lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
93
+ }
94
+ lastSlash = index;
95
+ dots = 0;
96
+ continue;
97
+ } else if (res.length > 0) {
98
+ res = "";
99
+ lastSegmentLength = 0;
100
+ lastSlash = index;
101
+ dots = 0;
102
+ continue;
103
+ }
104
+ }
105
+ if (allowAboveRoot) {
106
+ res += res.length > 0 ? "/.." : "..";
107
+ lastSegmentLength = 2;
108
+ }
109
+ } else {
110
+ if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
111
+ else res = path.slice(lastSlash + 1, index);
112
+ lastSegmentLength = index - lastSlash - 1;
113
+ }
114
+ lastSlash = index;
115
+ dots = 0;
116
+ } else if (char === "." && dots !== -1) ++dots;
117
+ else dots = -1;
118
+ }
119
+ return res;
120
+ }
121
+ /**
122
+ * Converts a given path to an absolute path based on the current working directory.
123
+ *
124
+ * @param path - The path to convert to an absolute path.
125
+ * @param cwd - The current working directory to use as the base path if the path is not absolute.
126
+ * @returns The absolute path.
127
+ */
128
+ function toAbsolutePath(path, cwd$1 = cwd()) {
129
+ if (isAbsolutePath(path)) return path;
130
+ return slash(normalizeString(appendPath(path, cwd$1), true));
131
+ }
132
+
133
+ //#endregion
134
+ export { correctPath, normalizeString, normalizeWindowsPath, stripStars, toAbsolutePath };
2
135
  //# sourceMappingURL=correct-path.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"correct-path.mjs","names":["char: string | null","currentDir","cwd"],"sources":["../../../../path/src/correct-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 { appendPath } from \"./append\";\nimport { cwd as currentDir } from \"./cwd\";\nimport { isAbsolutePath } from \"./is-type\";\nimport { joinPaths } from \"./join-paths\";\nimport {\n DRIVE_LETTER_REGEX,\n DRIVE_LETTER_START_REGEX,\n UNC_REGEX\n} from \"./regex\";\nimport { slash } from \"./slash\";\n\n// Util to normalize windows paths to posix\nexport function normalizeWindowsPath(input = \"\") {\n if (!input) {\n return input;\n }\n\n return slash(input).replace(DRIVE_LETTER_START_REGEX, r => r.toUpperCase());\n}\n\n/**\n * Corrects/normalized a file path.\n *\n * @param path - The path to correct.\n * @returns The corrected path.\n */\nexport function correctPath(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 = isAbsolutePath(path);\n const trailingSeparator = path.endsWith(\"/\");\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\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 !path.startsWith(\"/\") &&\n isPathAbsolute &&\n !DRIVE_LETTER_REGEX.test(path)\n ? `/${path}`\n : path;\n}\n\n/**\n * Remove any star tokens (*) from the end of the file path\n *\n * @example\n * stripStars(\"src/**\") // returns \"src\"\n * stripStars(\"src/*\") // returns \"src\"\n * stripStars(\"src/**\\/*\") // returns \"src\"\n * stripStars(\"src/**\\/*.txt\") // returns \"src\"\n * stripStars(\"src/**\\/file.txt\") // returns \"src\"\n * stripStars(\"src/file.txt\") // returns \"src/file.txt\"\n * stripStars(\"\") // returns \".\"\n *\n * @param path - The path to correct.\n * @returns The corrected path.\n */\nexport function stripStars(path?: string) {\n if (!path || path.length === 0) {\n return \".\";\n }\n\n path = correctPath(path);\n\n let found = false;\n\n return `${path.startsWith(\"/\") ? \"/\" : \"\"}${path\n .split(\"/\")\n .reduce((ret, segment) => {\n if (!segment?.trim()) {\n return ret;\n }\n\n if (found || segment.includes(\"*\")) {\n found = true;\n return ret;\n }\n\n return ret + (ret ? `/${segment}` : segment);\n }, \"\")}`;\n}\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 normalize path string.\n */\nexport function 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\n/**\n * Converts a given path to an absolute path based on the current working directory.\n *\n * @param path - The path to convert to an absolute path.\n * @param cwd - The current working directory to use as the base path if the path is not absolute.\n * @returns The absolute path.\n */\nexport function toAbsolutePath(path: string, cwd = currentDir()): string {\n if (isAbsolutePath(path)) {\n return path;\n }\n\n return slash(normalizeString(appendPath(path, cwd), true));\n}\n\n/**\n * Converts a given path to a relative path based on the current working directory.\n *\n * @param path - The path to convert to a relative path.\n * @param cwd - The current working directory to use as the base path if the path is not absolute.\n * @returns The relative path.\n */\nexport function toRelativePath(path: string, cwd = currentDir()): string {\n if (!path || path.length === 0) {\n return \".\";\n }\n\n if (isAbsolutePath(path)) {\n path = slash(normalizeString(path, true));\n } else {\n path = slash(normalizeString(joinPaths(cwd, path), true));\n }\n\n if (path.startsWith(\"./\")) {\n return path.slice(2);\n }\n\n return path;\n}\n\n/**\n * Adds a trailing slash to a path if it doesn't already have one.\n *\n * @param path - The path to modify.\n * @returns The modified path with a trailing slash.\n */\nexport function withTrailingSlash(path: string): string {\n const result = correctPath(path);\n\n return result.endsWith(\"/\") ? result : `${result}/`;\n}\n\n/**\n * Removes a trailing slash from a path if it has one.\n *\n * @param path - The path to modify.\n * @returns The modified path without a trailing slash.\n */\nexport function withoutTrailingSlash(path: string): string {\n const result = correctPath(path);\n\n return result.endsWith(\"/\") ? result.slice(0, -1) : result;\n}\n"],"mappings":"2PA8BA,SAAgB,EAAqB,EAAQ,GAAI,CAK/C,OAJK,GAIE,EAAM,EAAM,CAAC,QAAQ,EAA0B,GAAK,EAAE,aAAa,CAAC,CAS7E,SAAgB,EAAY,EAAe,CACzC,GAAI,CAAC,GAAQ,EAAK,SAAW,EAC3B,MAAO,IAIT,EAAO,EAAqB,EAAK,CAEjC,IAAM,EAAY,EAAK,MAAM,EAAU,CACjC,EAAiB,EAAe,EAAK,CACrC,EAAoB,EAAK,SAAS,IAAI,CA0B5C,MAvBA,GAAO,EAAgB,EAAM,CAAC,EAAe,CAEzC,EAAK,SAAW,EACd,EACK,IAEF,EAAoB,KAAO,KAGhC,IACF,GAAQ,KAEN,EAAmB,KAAK,EAAK,GAC/B,GAAQ,KAGN,EACG,EAGE,KAAK,IAFH,OAAO,IAKX,CAAC,EAAK,WAAW,IAAI,EAC1B,GACA,CAAC,EAAmB,KAAK,EAAK,CAC5B,IAAI,IACJ,GAkBN,SAAgB,EAAW,EAAe,CACxC,GAAI,CAAC,GAAQ,EAAK,SAAW,EAC3B,MAAO,IAGT,EAAO,EAAY,EAAK,CAExB,IAAI,EAAQ,GAEZ,MAAO,GAAG,EAAK,WAAW,IAAI,CAAG,IAAM,KAAK,EACzC,MAAM,IAAI,CACV,QAAQ,EAAK,IACP,GAAS,MAAM,CAIhB,GAAS,EAAQ,SAAS,IAAI,EAChC,EAAQ,GACD,GAGF,GAAO,EAAM,IAAI,IAAY,GAR3B,EASR,GAAG,GAUV,SAAgB,EAAgB,EAAc,EAAyB,CACrE,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,EAUT,SAAgB,EAAe,EAAc,EAAMC,GAAY,CAAU,CAKvE,OAJI,EAAe,EAAK,CACf,EAGF,EAAM,EAAgB,EAAW,EAAMC,EAAI,CAAE,GAAK,CAAC"}
1
+ {"version":3,"file":"correct-path.mjs","names":["char: string | null","currentDir","cwd"],"sources":["../../../../path/src/correct-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 { appendPath } from \"./append\";\nimport { cwd as currentDir } from \"./cwd\";\nimport { isAbsolutePath } from \"./is-type\";\nimport { joinPaths } from \"./join-paths\";\nimport {\n DRIVE_LETTER_REGEX,\n DRIVE_LETTER_START_REGEX,\n UNC_REGEX\n} from \"./regex\";\nimport { slash } from \"./slash\";\n\n// Util to normalize windows paths to posix\nexport function normalizeWindowsPath(input = \"\") {\n if (!input) {\n return input;\n }\n\n return slash(input).replace(DRIVE_LETTER_START_REGEX, r => r.toUpperCase());\n}\n\n/**\n * Corrects/normalized a file path.\n *\n * @param path - The path to correct.\n * @returns The corrected path.\n */\nexport function correctPath(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 = isAbsolutePath(path);\n const trailingSeparator = path.endsWith(\"/\");\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\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 !path.startsWith(\"/\") &&\n isPathAbsolute &&\n !DRIVE_LETTER_REGEX.test(path)\n ? `/${path}`\n : path;\n}\n\n/**\n * Remove any star tokens (*) from the end of the file path\n *\n * @example\n * stripStars(\"src/**\") // returns \"src\"\n * stripStars(\"src/*\") // returns \"src\"\n * stripStars(\"src/**\\/*\") // returns \"src\"\n * stripStars(\"src/**\\/*.txt\") // returns \"src\"\n * stripStars(\"src/**\\/file.txt\") // returns \"src\"\n * stripStars(\"src/file.txt\") // returns \"src/file.txt\"\n * stripStars(\"\") // returns \".\"\n *\n * @param path - The path to correct.\n * @returns The corrected path.\n */\nexport function stripStars(path?: string) {\n if (!path || path.length === 0) {\n return \".\";\n }\n\n path = correctPath(path);\n\n let found = false;\n\n return `${path.startsWith(\"/\") ? \"/\" : \"\"}${path\n .split(\"/\")\n .reduce((ret, segment) => {\n if (!segment?.trim()) {\n return ret;\n }\n\n if (found || segment.includes(\"*\")) {\n found = true;\n return ret;\n }\n\n return ret + (ret ? `/${segment}` : segment);\n }, \"\")}`;\n}\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 normalize path string.\n */\nexport function 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\n/**\n * Converts a given path to an absolute path based on the current working directory.\n *\n * @param path - The path to convert to an absolute path.\n * @param cwd - The current working directory to use as the base path if the path is not absolute.\n * @returns The absolute path.\n */\nexport function toAbsolutePath(path: string, cwd = currentDir()): string {\n if (isAbsolutePath(path)) {\n return path;\n }\n\n return slash(normalizeString(appendPath(path, cwd), true));\n}\n\n/**\n * Converts a given path to a relative path based on the current working directory.\n *\n * @param path - The path to convert to a relative path.\n * @param cwd - The current working directory to use as the base path if the path is not absolute.\n * @returns The relative path.\n */\nexport function toRelativePath(path: string, cwd = currentDir()): string {\n if (!path || path.length === 0) {\n return \".\";\n }\n\n if (isAbsolutePath(path)) {\n path = slash(normalizeString(path, true));\n } else {\n path = slash(normalizeString(joinPaths(cwd, path), true));\n }\n\n if (path.startsWith(\"./\")) {\n return path.slice(2);\n }\n\n return path;\n}\n\n/**\n * Adds a trailing slash to a path if it doesn't already have one.\n *\n * @param path - The path to modify.\n * @returns The modified path with a trailing slash.\n */\nexport function withTrailingSlash(path: string): string {\n const result = correctPath(path);\n\n return result.endsWith(\"/\") ? result : `${result}/`;\n}\n\n/**\n * Removes a trailing slash from a path if it has one.\n *\n * @param path - The path to modify.\n * @returns The modified path without a trailing slash.\n */\nexport function withoutTrailingSlash(path: string): string {\n const result = correctPath(path);\n\n return result.endsWith(\"/\") ? result.slice(0, -1) : result;\n}\n"],"mappings":";;;;;;;AA8BA,SAAgB,qBAAqB,QAAQ,IAAI;AAC/C,KAAI,CAAC,MACH,QAAO;AAGT,QAAO,MAAM,MAAM,CAAC,QAAQ,2BAA0B,MAAK,EAAE,aAAa,CAAC;;;;;;;;AAS7E,SAAgB,YAAY,MAAe;AACzC,KAAI,CAAC,QAAQ,KAAK,WAAW,EAC3B,QAAO;AAIT,QAAO,qBAAqB,KAAK;CAEjC,MAAM,YAAY,KAAK,MAAM,UAAU;CACvC,MAAM,iBAAiB,eAAe,KAAK;CAC3C,MAAM,oBAAoB,KAAK,SAAS,IAAI;AAG5C,QAAO,gBAAgB,MAAM,CAAC,eAAe;AAE7C,KAAI,KAAK,WAAW,GAAG;AACrB,MAAI,eACF,QAAO;AAET,SAAO,oBAAoB,OAAO;;AAGpC,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,CAAC,KAAK,WAAW,IAAI,IAC1B,kBACA,CAAC,mBAAmB,KAAK,KAAK,GAC5B,IAAI,SACJ;;;;;;;;;;;;;;;;;AAkBN,SAAgB,WAAW,MAAe;AACxC,KAAI,CAAC,QAAQ,KAAK,WAAW,EAC3B,QAAO;AAGT,QAAO,YAAY,KAAK;CAExB,IAAI,QAAQ;AAEZ,QAAO,GAAG,KAAK,WAAW,IAAI,GAAG,MAAM,KAAK,KACzC,MAAM,IAAI,CACV,QAAQ,KAAK,YAAY;AACxB,MAAI,CAAC,SAAS,MAAM,CAClB,QAAO;AAGT,MAAI,SAAS,QAAQ,SAAS,IAAI,EAAE;AAClC,WAAQ;AACR,UAAO;;AAGT,SAAO,OAAO,MAAM,IAAI,YAAY;IACnC,GAAG;;;;;;;;;AAUV,SAAgB,gBAAgB,MAAc,gBAAyB;CACrE,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;;;;;;;;;AAUT,SAAgB,eAAe,MAAc,QAAMC,KAAY,EAAU;AACvE,KAAI,eAAe,KAAK,CACtB,QAAO;AAGT,QAAO,MAAM,gBAAgB,WAAW,MAAMC,MAAI,EAAE,KAAK,CAAC"}
@@ -1 +1,17 @@
1
- function e(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}exports.cwd=e;
1
+
2
+ //#region ../path/src/cwd.ts
3
+ /**
4
+ * Get the current working directory.
5
+ *
6
+ * @remarks
7
+ * This function attempts to retrieve the current working directory using `process.cwd()`.
8
+ *
9
+ * @returns The current working directory or '/' if it cannot be determined
10
+ */
11
+ function cwd() {
12
+ if (typeof process !== "undefined" && typeof process.cwd === "function") return process.cwd().replace(/\\/g, "/");
13
+ return "/";
14
+ }
15
+
16
+ //#endregion
17
+ exports.cwd = cwd;
@@ -1,2 +1,17 @@
1
- function e(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}export{e as cwd};
1
+ //#region ../path/src/cwd.ts
2
+ /**
3
+ * Get the current working directory.
4
+ *
5
+ * @remarks
6
+ * This function attempts to retrieve the current working directory using `process.cwd()`.
7
+ *
8
+ * @returns The current working directory or '/' if it cannot be determined
9
+ */
10
+ function cwd() {
11
+ if (typeof process !== "undefined" && typeof process.cwd === "function") return process.cwd().replace(/\\/g, "/");
12
+ return "/";
13
+ }
14
+
15
+ //#endregion
16
+ export { cwd };
2
17
  //# sourceMappingURL=cwd.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"cwd.mjs","names":[],"sources":["../../../../path/src/cwd.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 * Get the current working directory.\n *\n * @remarks\n * This function attempts to retrieve the current working directory using `process.cwd()`.\n *\n * @returns The current working directory or '/' if it cannot be determined\n */\nexport function cwd() {\n if (typeof process !== \"undefined\" && typeof process.cwd === \"function\") {\n return process.cwd().replace(/\\\\/g, \"/\");\n }\n return \"/\";\n}\n"],"mappings":"AA0BA,SAAgB,GAAM,CAIpB,OAHI,OAAO,QAAY,KAAe,OAAO,QAAQ,KAAQ,WACpD,QAAQ,KAAK,CAAC,QAAQ,MAAO,IAAI,CAEnC"}
1
+ {"version":3,"file":"cwd.mjs","names":[],"sources":["../../../../path/src/cwd.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 * Get the current working directory.\n *\n * @remarks\n * This function attempts to retrieve the current working directory using `process.cwd()`.\n *\n * @returns The current working directory or '/' if it cannot be determined\n */\nexport function cwd() {\n if (typeof process !== \"undefined\" && typeof process.cwd === \"function\") {\n return process.cwd().replace(/\\\\/g, \"/\");\n }\n return \"/\";\n}\n"],"mappings":";;;;;;;;;AA0BA,SAAgB,MAAM;AACpB,KAAI,OAAO,YAAY,eAAe,OAAO,QAAQ,QAAQ,WAC3D,QAAO,QAAQ,KAAK,CAAC,QAAQ,OAAO,IAAI;AAE1C,QAAO"}
@@ -1 +1,169 @@
1
- const e=require(`./cwd.cjs`),t=require(`./regex.cjs`),n=require(`./is-type.cjs`),r=require(`./correct-path.cjs`),i=require(`../../type-checks/src/is-set-string.cjs`),a=require(`../../types/src/base.cjs`);function o(e,t={}){let{requireExtension:n=!1,withExtension:i=!0}=t,o=r.normalizeWindowsPath(e)?.split(e?.includes(`\\`)?`\\`:`/`)?.pop()??``;return n===!0&&!o.includes(`.`)?a.EMPTY_STRING:i===!1&&o.includes(`.`)?o.replace(`.${l(o)??``}`,``)||a.EMPTY_STRING:o}function s(e,t={}){let n=r.normalizeWindowsPath(e),i=n.replace(o(n,{requireExtension:!1,...t}),``);return i===`/`?i:i.replace(/\/$/,``)}function c(e,t){let n=s(e,t).split(`/`),r=``;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t){r=t;break}}return r??a.EMPTY_STRING}function l(e){if(e.endsWith(`.`)||e.endsWith(`/`))return;let n=t.FILE_EXTENSION_REGEX.exec(r.normalizeWindowsPath(e));return n&&n.length>0&&i.isSetString(n[0])?n[0].replace(`.`,``):void 0}function u(e){return!!l(e)}function d(...t){t=t.map(e=>r.normalizeWindowsPath(e));let i=``,a=!1;for(let r=t.length-1;r>=-1&&!a;r--){let o=r>=0?t[r]:e.cwd();!o||o.length===0||(i=`${o}/${i}`,a=n.isAbsolute(o))}return i=r.normalizeString(i,!a),a&&!n.isAbsolute(i)?`/${i}`:i.length>0?i:`.`}function f(e,n){let r=d(e).replace(t.ROOT_FOLDER_REGEX,`$1`).split(`/`),i=d(n).replace(t.ROOT_FOLDER_REGEX,`$1`).split(`/`);if(i[0][1]===`:`&&r[0][1]===`:`&&r[0]!==i[0])return i.join(`/`);let a=[...r];for(let e of a){if(i[0]!==e)break;r.shift(),i.shift()}return[...r.map(()=>`..`),...i].join(`/`)}function p(e,t,n=!1){return f(n===!0?e:e.replace(/\/$/,``),n===!0?t:t.replace(/\/$/,``))}exports.findFileExtension=l,exports.findFileName=o,exports.findFilePath=s,exports.findFolderName=c,exports.hasFileExtension=u,exports.relativePath=p;
1
+ const require_cwd = require('./cwd.cjs');
2
+ const require_regex = require('./regex.cjs');
3
+ const require_is_type = require('./is-type.cjs');
4
+ const require_correct_path = require('./correct-path.cjs');
5
+ const require_is_set_string = require('../../type-checks/src/is-set-string.cjs');
6
+ const require_base = require('../../types/src/base.cjs');
7
+
8
+ //#region ../path/src/file-path-fns.ts
9
+ /**
10
+ * Find the file name from a file path.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const fileName = findFileName("C:\\Users\\user\\Documents\\file.txt");
15
+ * // fileName = "file.txt"
16
+ * ```
17
+ *
18
+ * @param filePath - The file path to process
19
+ * @param options - Options to control the file name extraction
20
+ * @returns The file name
21
+ */
22
+ function findFileName(filePath, options = {}) {
23
+ const { requireExtension = false, withExtension = true } = options;
24
+ const result = require_correct_path.normalizeWindowsPath(filePath)?.split(filePath?.includes("\\") ? "\\" : "/")?.pop() ?? "";
25
+ if (requireExtension === true && !result.includes(".")) return require_base.EMPTY_STRING;
26
+ if (withExtension === false && result.includes(".")) return result.replace(`.${findFileExtension(result) ?? ""}`, "") || require_base.EMPTY_STRING;
27
+ return result;
28
+ }
29
+ /**
30
+ * Find the full file path's directories from a file path.
31
+ *
32
+ * @remarks
33
+ * The functionality of this method is similar to the {@link path.dirname} function in Node's path module.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * const folderPath = findFilePath("C:\\Users\\user\\Documents\\file.txt");
38
+ * // folderPath = "C:\\Users\\user\\Documents"
39
+ * ```
40
+ *
41
+ * @param filePath - The file path to process
42
+ * @param options - Options to control the file name extraction
43
+ * @returns The full file path's directories
44
+ */
45
+ function findFilePath(filePath, options = {}) {
46
+ const normalizedPath = require_correct_path.normalizeWindowsPath(filePath);
47
+ const result = normalizedPath.replace(findFileName(normalizedPath, {
48
+ requireExtension: false,
49
+ ...options
50
+ }), "");
51
+ return result === "/" ? result : result.replace(/\/$/, "");
52
+ }
53
+ /**
54
+ * Find the top most folder containing the file from a file path.
55
+ *
56
+ * @remarks
57
+ * The functionality of this method is similar to the {@link path.basename} function in Node's path module.
58
+ * If you're looking for the full path of the folder (for example: `C:\\Users\\user\\Documents` instead of just `Documents`) containing the file, use {@link findFilePath} instead.
59
+ *
60
+ * @example
61
+ * const folderPath = findFolderName("C:\\Users\\user\\Documents\\file.txt");
62
+ * // folderPath = "Documents"
63
+ *
64
+ * @param filePath - The file path to process
65
+ * @param options - Options to control the file name extraction
66
+ * @returns The folder containing the file
67
+ */
68
+ function findFolderName(filePath, options) {
69
+ const segments = findFilePath(filePath, options).split("/");
70
+ let lastSegment = "";
71
+ for (let i = segments.length - 1; i >= 0; i--) {
72
+ const val = segments[i];
73
+ if (val) {
74
+ lastSegment = val;
75
+ break;
76
+ }
77
+ }
78
+ return lastSegment ?? require_base.EMPTY_STRING;
79
+ }
80
+ /**
81
+ * Find the file extension from a file path.
82
+ *
83
+ * @remarks
84
+ * The functionality of this method is similar to the {@link path.extname} function in Node's path module.
85
+ * The file extension is the part of the file name that comes after the last dot (`.`) in the file name. If the file name does not contain a dot, or if it ends with a dot, this function will return `undefined`.
86
+ *
87
+ * The returned extension **will not** include the dot, for example `txt` or `js` instead of `.txt` or `.js`.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * findFileExtension("C:\\Users\\user\\Documents\\file.config.ts");
92
+ * // Returns "ts"
93
+ * ```
94
+ *
95
+ * @param filePath - The file path to process
96
+ * @returns The file extension or undefined if no extension is found
97
+ */
98
+ function findFileExtension(filePath) {
99
+ if (filePath.endsWith(".") || filePath.endsWith("/")) return;
100
+ const match = require_regex.FILE_EXTENSION_REGEX.exec(require_correct_path.normalizeWindowsPath(filePath));
101
+ return match && match.length > 0 && require_is_set_string.isSetString(match[0]) ? match[0].replace(".", "") : void 0;
102
+ }
103
+ /**
104
+ * Check if a file path has a file extension.
105
+ *
106
+ * @param filePath - The file path to process
107
+ * @returns An indicator specifying if the file path has a file extension
108
+ */
109
+ function hasFileExtension(filePath) {
110
+ return Boolean(findFileExtension(filePath));
111
+ }
112
+ function resolve(...paths) {
113
+ paths = paths.map((argument) => require_correct_path.normalizeWindowsPath(argument));
114
+ let resolvedPath = "";
115
+ let resolvedAbsolute = false;
116
+ for (let index = paths.length - 1; index >= -1 && !resolvedAbsolute; index--) {
117
+ const path = index >= 0 ? paths[index] : require_cwd.cwd();
118
+ if (!path || path.length === 0) continue;
119
+ resolvedPath = `${path}/${resolvedPath}`;
120
+ resolvedAbsolute = require_is_type.isAbsolute(path);
121
+ }
122
+ resolvedPath = require_correct_path.normalizeString(resolvedPath, !resolvedAbsolute);
123
+ if (resolvedAbsolute && !require_is_type.isAbsolute(resolvedPath)) return `/${resolvedPath}`;
124
+ return resolvedPath.length > 0 ? resolvedPath : ".";
125
+ }
126
+ /**
127
+ * Get the relative path from one file to another.
128
+ *
129
+ * @remarks
130
+ * This function is similar to the `path.relative` function in Node's path module.
131
+ *
132
+ * @param from - The base path to start from
133
+ * @param to - The target path to resolve relative to the base path
134
+ * @returns The relative path from the base path to the target path
135
+ */
136
+ function relative(from, to) {
137
+ const _from = resolve(from).replace(require_regex.ROOT_FOLDER_REGEX, "$1").split("/");
138
+ const _to = resolve(to).replace(require_regex.ROOT_FOLDER_REGEX, "$1").split("/");
139
+ if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) return _to.join("/");
140
+ const _fromCopy = [..._from];
141
+ for (const segment of _fromCopy) {
142
+ if (_to[0] !== segment) break;
143
+ _from.shift();
144
+ _to.shift();
145
+ }
146
+ return [..._from.map(() => ".."), ..._to].join("/");
147
+ }
148
+ /**
149
+ * Get the relative path from one file to another.
150
+ *
151
+ * @remarks
152
+ * This function wraps the `path.relative` function in Node's path module.
153
+ *
154
+ * @param from - The base path to start from
155
+ * @param to - The target path to resolve relative to the base path
156
+ * @param withEndSlash - Whether to include a trailing slash at the end of the path
157
+ * @returns The relative path from the base path to the target path
158
+ */
159
+ function relativePath(from, to, withEndSlash = false) {
160
+ return relative(withEndSlash !== true ? from.replace(/\/$/, "") : from, withEndSlash !== true ? to.replace(/\/$/, "") : to);
161
+ }
162
+
163
+ //#endregion
164
+ exports.findFileExtension = findFileExtension;
165
+ exports.findFileName = findFileName;
166
+ exports.findFilePath = findFilePath;
167
+ exports.findFolderName = findFolderName;
168
+ exports.hasFileExtension = hasFileExtension;
169
+ exports.relativePath = relativePath;