@stryke/path 0.25.3 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  # Changelog for Stryke - Path
4
4
 
5
+ ## [0.25.3](https://github.com/storm-software/stryke/releases/tag/path%400.25.3) (01/16/2026)
6
+
7
+ ### Bug Fixes
8
+
9
+ - **path:** Resolve issue checking previous character in `globToRegex` function
10
+ ([59d9e9ae](https://github.com/storm-software/stryke/commit/59d9e9ae))
11
+
5
12
  ## [0.25.2](https://github.com/storm-software/stryke/releases/tag/path%400.25.2) (01/16/2026)
6
13
 
7
14
  ### Bug Fixes
@@ -0,0 +1,29 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
@@ -1,3 +1,4 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
1
2
  const require_cwd = require('./cwd.cjs');
2
3
  const require_regex = require('./regex.cjs');
3
4
  const require_is_type = require('./is-type.cjs');
@@ -24,14 +25,14 @@ function findFileName(filePath, options = {}) {
24
25
  const { requireExtension = false, withExtension = true } = options;
25
26
  const result = require_correct_path.normalizeWindowsPath(filePath)?.split(filePath?.includes("\\") ? "\\" : "/")?.pop() ?? "";
26
27
  if (requireExtension === true && !result.includes(".")) return require_base.EMPTY_STRING;
27
- if (withExtension === false && result.includes(".")) return result.replace(`.${findFileExtension(result) ?? ""}`, "") || require_base.EMPTY_STRING;
28
+ if (withExtension === false && result.includes(".")) return result.replace(`.${findFileExtension(result, options) ?? ""}`, "") || require_base.EMPTY_STRING;
28
29
  return result;
29
30
  }
30
31
  /**
31
32
  * Find the full file path's directories from a file path.
32
33
  *
33
34
  * @remarks
34
- * The functionality of this method is similar to the {@link path.dirname} function in Node's path module.
35
+ * The functionality of this method is similar to the {@link _path.dirname} function in Node's path module.
35
36
  *
36
37
  * @example
37
38
  * ```ts
@@ -56,7 +57,7 @@ const dirname = findFilePath;
56
57
  * Find the top most folder containing the file from a file path.
57
58
  *
58
59
  * @remarks
59
- * The functionality of this method is similar to the {@link path.basename} function in Node's path module.
60
+ * The functionality of this method is similar to the {@link _path.basename} function in Node's path module.
60
61
  * 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.
61
62
  *
62
63
  * @example
@@ -91,16 +92,21 @@ const basename = findFolderName;
91
92
  *
92
93
  * @example
93
94
  * ```ts
94
- * findFileExtension("C:\\Users\\user\\Documents\\file.config.ts");
95
- * // Returns "ts"
95
+ * findFileExtension("C:\\Users\\user\\Documents\\file.config.ts"); // Returns "ts"
96
+ * findFileExtension("C:\\Users\\user\\Documents\\file.d.ts"); // Returns "ts"
97
+ * findFileExtension("C:\\Users\\user\\Documents\\file.d.ts", { fullExtension: true }); // Returns "d.ts"
98
+ * findFileExtension("C:\\Users\\user\\Documents\\file.ts.map"); // Returns "ts"
99
+ * findFileExtension("C:\\Users\\user\\Documents\\file.ts.map", { fullExtension: true }); // Returns "ts.map"
100
+ * findFileExtension("C:\\Users\\user\\Documents\\file"); // Returns undefined
96
101
  * ```
97
102
  *
98
103
  * @param filePath - The file path to process
104
+ * @param options - Options to control the file name extraction
99
105
  * @returns The file extension or undefined if no extension is found
100
106
  */
101
- function findFileExtension(filePath) {
107
+ function findFileExtension(filePath, options) {
102
108
  if (filePath.endsWith(".") || filePath.endsWith("/")) return;
103
- const match = require_regex.FILE_EXTENSION_REGEX.exec(require_correct_path.normalizeWindowsPath(filePath));
109
+ const match = (options?.fullExtension ? require_regex.FULL_FILE_EXTENSION_REGEX : require_regex.FILE_EXTENSION_REGEX).exec(require_correct_path.normalizeWindowsPath(filePath));
104
110
  return match && match.length > 0 && require_is_set_string.isSetString(match[0]) ? match[0].replace(".", "") : void 0;
105
111
  }
106
112
  const extname = findFileExtension;
@@ -113,10 +119,11 @@ const extname = findFileExtension;
113
119
  * The returned extension **will** include the dot, for example `.txt` or `.js` instead of `txt` or `js`.
114
120
  *
115
121
  * @param filePath - The file path to process
122
+ * @param options - Options to control the file name extraction
116
123
  * @returns The file extension (including the `"."` prefix) or undefined if no extension is found
117
124
  */
118
- function findFileDotExtension(filePath) {
119
- const ext = findFileExtension(filePath);
125
+ function findFileDotExtension(filePath, options) {
126
+ const ext = findFileExtension(filePath, options);
120
127
  return ext ? `.${ext}` : void 0;
121
128
  }
122
129
  /**
@@ -128,10 +135,11 @@ function findFileDotExtension(filePath) {
128
135
  * The returned extension **will not** include the dot, for example `txt` or `js` instead of `.txt` or `.js`.
129
136
  *
130
137
  * @param filePath - The file path to process
138
+ * @param options - Options to control the file name extraction
131
139
  * @returns The file extension or an empty string if no extension is found
132
140
  */
133
- function findFileExtensionSafe(filePath) {
134
- return findFileExtension(filePath) ?? require_base.EMPTY_STRING;
141
+ function findFileExtensionSafe(filePath, options) {
142
+ return findFileExtension(filePath, options) ?? require_base.EMPTY_STRING;
135
143
  }
136
144
  /**
137
145
  * Find the file extension including the `"."` character prefix from a file path or an empty string.
@@ -142,10 +150,11 @@ function findFileExtensionSafe(filePath) {
142
150
  * The returned extension **will** include the dot, for example `.txt` or `.js` instead of `txt` or `js`.
143
151
  *
144
152
  * @param filePath - The file path to process
153
+ * @param options - Options to control the file name extraction
145
154
  * @returns The file extension (including the `"."` prefix) or an empty string if no extension is found
146
155
  */
147
- function findFileDotExtensionSafe(filePath) {
148
- const ext = findFileExtension(filePath);
156
+ function findFileDotExtensionSafe(filePath, options) {
157
+ const ext = findFileExtension(filePath, options);
149
158
  return ext ? `.${ext}` : "";
150
159
  }
151
160
  /**
@@ -179,10 +188,11 @@ function hasFolderName(filePath) {
179
188
  * Check if a file path has a file extension.
180
189
  *
181
190
  * @param filePath - The file path to process
191
+ * @param options - Options to control the file name extraction
182
192
  * @returns An indicator specifying if the file path has a file extension
183
193
  */
184
- function hasFileExtension(filePath) {
185
- return Boolean(findFileExtension(filePath));
194
+ function hasFileExtension(filePath, options) {
195
+ return Boolean(findFileExtension(filePath, options));
186
196
  }
187
197
  /**
188
198
  * Resolve the file path to an absolute path.
@@ -279,14 +289,14 @@ function relativeToCurrentDir(filePath) {
279
289
  * @param path - The path to check
280
290
  * @returns An indicator specifying if the path is a relative path
281
291
  */
282
- function parsePath(path) {
292
+ function parsePath(path, options) {
283
293
  const root = /^[/\\]|^[a-z]:[/\\]/i.exec(path)?.[0]?.replace(/\\/g, "/") || "";
284
294
  const normalizedPath = require_correct_path.normalizeWindowsPath(path);
285
295
  const segments = normalizedPath.replace(/\/$/, "").split("/").slice(0, -1);
286
296
  if (segments.length === 1 && /^[A-Z]:$/i.test(segments[0])) segments[0] += "/";
287
- const base = findFolderName(normalizedPath);
297
+ const base = findFolderName(normalizedPath, options);
288
298
  const dir = segments.join("/") || (require_is_type.isAbsolutePath(path) ? "/" : ".");
289
- const ext = findFileExtensionSafe(path);
299
+ const ext = findFileExtensionSafe(path, options);
290
300
  return {
291
301
  root,
292
302
  dir,
@@ -300,10 +310,11 @@ function parsePath(path) {
300
310
  *
301
311
  * @param filePath - The current file path being processed
302
312
  * @param newFileName - The updated file name being processed
313
+ * @param options - Options to control the file name extraction
303
314
  * @returns The modified or unmodified file path.
304
315
  */
305
- function renameFile(filePath, newFileName) {
306
- const file = parsePath(filePath);
316
+ function renameFile(filePath, newFileName, options) {
317
+ const file = parsePath(filePath, options);
307
318
  return require_join_paths.joinPaths(file.dir, newFileName.includes(".") ? newFileName : newFileName + file.ext);
308
319
  }
309
320
 
@@ -1,5 +1,5 @@
1
1
  //#region src/file-path-fns.d.ts
2
- interface FindFileNameOptions {
2
+ interface FindFileNameOptions extends FindFileExtensionOptions {
3
3
  /**
4
4
  * Require the file extension to be present in the file name.
5
5
  *
@@ -31,7 +31,7 @@ declare function findFileName(filePath: string, options?: FindFileNameOptions):
31
31
  * Find the full file path's directories from a file path.
32
32
  *
33
33
  * @remarks
34
- * The functionality of this method is similar to the {@link path.dirname} function in Node's path module.
34
+ * The functionality of this method is similar to the {@link _path.dirname} function in Node's path module.
35
35
  *
36
36
  * @example
37
37
  * ```ts
@@ -49,7 +49,7 @@ declare const dirname: typeof findFilePath;
49
49
  * Find the top most folder containing the file from a file path.
50
50
  *
51
51
  * @remarks
52
- * The functionality of this method is similar to the {@link path.basename} function in Node's path module.
52
+ * The functionality of this method is similar to the {@link _path.basename} function in Node's path module.
53
53
  * 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.
54
54
  *
55
55
  * @example
@@ -62,6 +62,14 @@ declare const dirname: typeof findFilePath;
62
62
  */
63
63
  declare function findFolderName(filePath: string, options?: FindFileNameOptions): string;
64
64
  declare const basename: typeof findFolderName;
65
+ interface FindFileExtensionOptions {
66
+ /**
67
+ * Return the full file extension including `.d` and `.map` if present.
68
+ *
69
+ * @defaultValue false
70
+ */
71
+ fullExtension?: boolean;
72
+ }
65
73
  /**
66
74
  * Find the file extension from a file path.
67
75
  *
@@ -73,14 +81,19 @@ declare const basename: typeof findFolderName;
73
81
  *
74
82
  * @example
75
83
  * ```ts
76
- * findFileExtension("C:\\Users\\user\\Documents\\file.config.ts");
77
- * // Returns "ts"
84
+ * findFileExtension("C:\\Users\\user\\Documents\\file.config.ts"); // Returns "ts"
85
+ * findFileExtension("C:\\Users\\user\\Documents\\file.d.ts"); // Returns "ts"
86
+ * findFileExtension("C:\\Users\\user\\Documents\\file.d.ts", { fullExtension: true }); // Returns "d.ts"
87
+ * findFileExtension("C:\\Users\\user\\Documents\\file.ts.map"); // Returns "ts"
88
+ * findFileExtension("C:\\Users\\user\\Documents\\file.ts.map", { fullExtension: true }); // Returns "ts.map"
89
+ * findFileExtension("C:\\Users\\user\\Documents\\file"); // Returns undefined
78
90
  * ```
79
91
  *
80
92
  * @param filePath - The file path to process
93
+ * @param options - Options to control the file name extraction
81
94
  * @returns The file extension or undefined if no extension is found
82
95
  */
83
- declare function findFileExtension(filePath: string): string | undefined;
96
+ declare function findFileExtension(filePath: string, options?: FindFileExtensionOptions): string | undefined;
84
97
  declare const extname: typeof findFileExtension;
85
98
  /**
86
99
  * Find the file extension including the `"."` character prefix from a file path.
@@ -91,9 +104,10 @@ declare const extname: typeof findFileExtension;
91
104
  * The returned extension **will** include the dot, for example `.txt` or `.js` instead of `txt` or `js`.
92
105
  *
93
106
  * @param filePath - The file path to process
107
+ * @param options - Options to control the file name extraction
94
108
  * @returns The file extension (including the `"."` prefix) or undefined if no extension is found
95
109
  */
96
- declare function findFileDotExtension(filePath: string): string | undefined;
110
+ declare function findFileDotExtension(filePath: string, options?: FindFileExtensionOptions): string | undefined;
97
111
  /**
98
112
  * Find the file extension from a file path or an empty string.
99
113
  *
@@ -103,9 +117,10 @@ declare function findFileDotExtension(filePath: string): string | undefined;
103
117
  * The returned extension **will not** include the dot, for example `txt` or `js` instead of `.txt` or `.js`.
104
118
  *
105
119
  * @param filePath - The file path to process
120
+ * @param options - Options to control the file name extraction
106
121
  * @returns The file extension or an empty string if no extension is found
107
122
  */
108
- declare function findFileExtensionSafe(filePath: string): string;
123
+ declare function findFileExtensionSafe(filePath: string, options?: FindFileExtensionOptions): string;
109
124
  /**
110
125
  * Find the file extension including the `"."` character prefix from a file path or an empty string.
111
126
  *
@@ -115,9 +130,10 @@ declare function findFileExtensionSafe(filePath: string): string;
115
130
  * The returned extension **will** include the dot, for example `.txt` or `.js` instead of `txt` or `js`.
116
131
  *
117
132
  * @param filePath - The file path to process
133
+ * @param options - Options to control the file name extraction
118
134
  * @returns The file extension (including the `"."` prefix) or an empty string if no extension is found
119
135
  */
120
- declare function findFileDotExtensionSafe(filePath: string): string;
136
+ declare function findFileDotExtensionSafe(filePath: string, options?: FindFileExtensionOptions): string;
121
137
  /**
122
138
  * Check if a file path has a file name.
123
139
  *
@@ -143,9 +159,10 @@ declare function hasFolderName(filePath: string): boolean;
143
159
  * Check if a file path has a file extension.
144
160
  *
145
161
  * @param filePath - The file path to process
162
+ * @param options - Options to control the file name extraction
146
163
  * @returns An indicator specifying if the file path has a file extension
147
164
  */
148
- declare function hasFileExtension(filePath: string): boolean;
165
+ declare function hasFileExtension(filePath: string, options?: FindFileExtensionOptions): boolean;
149
166
  /**
150
167
  * Resolve the file path to an absolute path.
151
168
  *
@@ -198,7 +215,7 @@ declare function relativeToCurrentDir(filePath: string): string;
198
215
  * @param path - The path to check
199
216
  * @returns An indicator specifying if the path is a relative path
200
217
  */
201
- declare function parsePath(path: string): {
218
+ declare function parsePath(path: string, options?: FindFileNameOptions): {
202
219
  root: string;
203
220
  dir: string;
204
221
  base: string;
@@ -210,9 +227,10 @@ declare function parsePath(path: string): {
210
227
  *
211
228
  * @param filePath - The current file path being processed
212
229
  * @param newFileName - The updated file name being processed
230
+ * @param options - Options to control the file name extraction
213
231
  * @returns The modified or unmodified file path.
214
232
  */
215
- declare function renameFile(filePath: string, newFileName: string): string;
233
+ declare function renameFile(filePath: string, newFileName: string, options?: FindFileNameOptions): string;
216
234
  //#endregion
217
- export { FindFileNameOptions, basename, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, hasFileExtension, hasFileName, hasFilePath, hasFolderName, parsePath, relative, relativePath, relativeToCurrentDir, renameFile, resolve, resolvePath, resolvePaths };
235
+ export { FindFileExtensionOptions, FindFileNameOptions, basename, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, hasFileExtension, hasFileName, hasFilePath, hasFolderName, parsePath, relative, relativePath, relativeToCurrentDir, renameFile, resolve, resolvePath, resolvePaths };
218
236
  //# sourceMappingURL=file-path-fns.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"file-path-fns.d.cts","names":[],"sources":["../src/file-path-fns.ts"],"sourcesContent":[],"mappings":";UA0BiB,mBAAA;EAAA;AA6BjB;AAuCA;AAcA;AAiBA;EAyBa,gBAAyB,CAAA,EAAA,OAAjB;EAoBL;AAYhB;AAaA;AAiBA;AAeA;EAYgB,aAAA,CAAW,EAAA,OAAA;AAU3B;AAUA;AAUA;AAWA;AAoCA;AA0CA;AAgBA;AAsCA;AAaA;AAUA;AAgCA;;;;iBA5ZgB,YAAA,6BAEL;;;;;;;;;;;;;;;;;iBAqCK,YAAA,6BAEL;cAYE,gBAAO;;;;;;;;;;;;;;;;iBAiBJ,cAAA,6BAEJ;cAuBC,iBAAQ;;;;;;;;;;;;;;;;;;;iBAoBL,iBAAA;cAYH,gBAAO;;;;;;;;;;;;iBAaJ,oBAAA;;;;;;;;;;;;iBAiBA,qBAAA;;;;;;;;;;;;iBAeA,wBAAA;;;;;;;iBAYA,WAAA;;;;;;;iBAUA,WAAA;;;;;;;iBAUA,aAAA;;;;;;;iBAUA,gBAAA;;;;;;;;iBAWA,WAAA;iBAoCA,OAAA;;;;;;;iBA0CA,YAAA;;;;;;;;;;;iBAgBA,QAAA;;;;;;;;;;;;iBAsCA,YAAA;;;;;;;iBAaA,oBAAA;;;;;;;iBAUA,SAAA;;;;;;;;;;;;;;iBAgCA,UAAA"}
1
+ {"version":3,"file":"file-path-fns.d.cts","names":[],"sources":["../src/file-path-fns.ts"],"sourcesContent":[],"mappings":";UA+BiB,mBAAA,SAA4B;EAA5B;AA6BjB;AAwCA;AAcA;AAiBA;EAyBa,gBAAyB,CAAA,EAAA,OAAjB;EAEJ;AAgCjB;AAiBA;AAcA;AAqBA;EAmBgB,aAAA,CAAA,EAAA,OAAA;AAehB;AAUA;AAUA;AAWA;AAcA;AAoCA;AA0CA;AAgBA;AAsCA;AAaA;AAUA;AAiCA;;;iBAjcgB,YAAA,6BAEL;;;;;;;;;;;;;;;;;iBAsCK,YAAA,6BAEL;cAYE,gBAAO;;;;;;;;;;;;;;;;iBAiBJ,cAAA,6BAEJ;cAuBC,iBAAQ;UAEJ,wBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgCD,iBAAA,6BAEJ;cAeC,gBAAO;;;;;;;;;;;;;iBAcJ,oBAAA,6BAEJ;;;;;;;;;;;;;iBAmBI,qBAAA,6BAEJ;;;;;;;;;;;;;iBAiBI,wBAAA,6BAEJ;;;;;;;iBAaI,WAAA;;;;;;;iBAUA,WAAA;;;;;;;iBAUA,aAAA;;;;;;;;iBAWA,gBAAA,6BAEJ;;;;;;;;iBAYI,WAAA;iBAoCA,OAAA;;;;;;;iBA0CA,YAAA;;;;;;;;;;;iBAgBA,QAAA;;;;;;;;;;;;iBAsCA,YAAA;;;;;;;iBAaA,oBAAA;;;;;;;iBAUA,SAAA,yBAAkC;;;;;;;;;;;;;;;iBAiClC,UAAA,kDAGJ"}
@@ -1,5 +1,5 @@
1
1
  //#region src/file-path-fns.d.ts
2
- interface FindFileNameOptions {
2
+ interface FindFileNameOptions extends FindFileExtensionOptions {
3
3
  /**
4
4
  * Require the file extension to be present in the file name.
5
5
  *
@@ -31,7 +31,7 @@ declare function findFileName(filePath: string, options?: FindFileNameOptions):
31
31
  * Find the full file path's directories from a file path.
32
32
  *
33
33
  * @remarks
34
- * The functionality of this method is similar to the {@link path.dirname} function in Node's path module.
34
+ * The functionality of this method is similar to the {@link _path.dirname} function in Node's path module.
35
35
  *
36
36
  * @example
37
37
  * ```ts
@@ -49,7 +49,7 @@ declare const dirname: typeof findFilePath;
49
49
  * Find the top most folder containing the file from a file path.
50
50
  *
51
51
  * @remarks
52
- * The functionality of this method is similar to the {@link path.basename} function in Node's path module.
52
+ * The functionality of this method is similar to the {@link _path.basename} function in Node's path module.
53
53
  * 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.
54
54
  *
55
55
  * @example
@@ -62,6 +62,14 @@ declare const dirname: typeof findFilePath;
62
62
  */
63
63
  declare function findFolderName(filePath: string, options?: FindFileNameOptions): string;
64
64
  declare const basename: typeof findFolderName;
65
+ interface FindFileExtensionOptions {
66
+ /**
67
+ * Return the full file extension including `.d` and `.map` if present.
68
+ *
69
+ * @defaultValue false
70
+ */
71
+ fullExtension?: boolean;
72
+ }
65
73
  /**
66
74
  * Find the file extension from a file path.
67
75
  *
@@ -73,14 +81,19 @@ declare const basename: typeof findFolderName;
73
81
  *
74
82
  * @example
75
83
  * ```ts
76
- * findFileExtension("C:\\Users\\user\\Documents\\file.config.ts");
77
- * // Returns "ts"
84
+ * findFileExtension("C:\\Users\\user\\Documents\\file.config.ts"); // Returns "ts"
85
+ * findFileExtension("C:\\Users\\user\\Documents\\file.d.ts"); // Returns "ts"
86
+ * findFileExtension("C:\\Users\\user\\Documents\\file.d.ts", { fullExtension: true }); // Returns "d.ts"
87
+ * findFileExtension("C:\\Users\\user\\Documents\\file.ts.map"); // Returns "ts"
88
+ * findFileExtension("C:\\Users\\user\\Documents\\file.ts.map", { fullExtension: true }); // Returns "ts.map"
89
+ * findFileExtension("C:\\Users\\user\\Documents\\file"); // Returns undefined
78
90
  * ```
79
91
  *
80
92
  * @param filePath - The file path to process
93
+ * @param options - Options to control the file name extraction
81
94
  * @returns The file extension or undefined if no extension is found
82
95
  */
83
- declare function findFileExtension(filePath: string): string | undefined;
96
+ declare function findFileExtension(filePath: string, options?: FindFileExtensionOptions): string | undefined;
84
97
  declare const extname: typeof findFileExtension;
85
98
  /**
86
99
  * Find the file extension including the `"."` character prefix from a file path.
@@ -91,9 +104,10 @@ declare const extname: typeof findFileExtension;
91
104
  * The returned extension **will** include the dot, for example `.txt` or `.js` instead of `txt` or `js`.
92
105
  *
93
106
  * @param filePath - The file path to process
107
+ * @param options - Options to control the file name extraction
94
108
  * @returns The file extension (including the `"."` prefix) or undefined if no extension is found
95
109
  */
96
- declare function findFileDotExtension(filePath: string): string | undefined;
110
+ declare function findFileDotExtension(filePath: string, options?: FindFileExtensionOptions): string | undefined;
97
111
  /**
98
112
  * Find the file extension from a file path or an empty string.
99
113
  *
@@ -103,9 +117,10 @@ declare function findFileDotExtension(filePath: string): string | undefined;
103
117
  * The returned extension **will not** include the dot, for example `txt` or `js` instead of `.txt` or `.js`.
104
118
  *
105
119
  * @param filePath - The file path to process
120
+ * @param options - Options to control the file name extraction
106
121
  * @returns The file extension or an empty string if no extension is found
107
122
  */
108
- declare function findFileExtensionSafe(filePath: string): string;
123
+ declare function findFileExtensionSafe(filePath: string, options?: FindFileExtensionOptions): string;
109
124
  /**
110
125
  * Find the file extension including the `"."` character prefix from a file path or an empty string.
111
126
  *
@@ -115,9 +130,10 @@ declare function findFileExtensionSafe(filePath: string): string;
115
130
  * The returned extension **will** include the dot, for example `.txt` or `.js` instead of `txt` or `js`.
116
131
  *
117
132
  * @param filePath - The file path to process
133
+ * @param options - Options to control the file name extraction
118
134
  * @returns The file extension (including the `"."` prefix) or an empty string if no extension is found
119
135
  */
120
- declare function findFileDotExtensionSafe(filePath: string): string;
136
+ declare function findFileDotExtensionSafe(filePath: string, options?: FindFileExtensionOptions): string;
121
137
  /**
122
138
  * Check if a file path has a file name.
123
139
  *
@@ -143,9 +159,10 @@ declare function hasFolderName(filePath: string): boolean;
143
159
  * Check if a file path has a file extension.
144
160
  *
145
161
  * @param filePath - The file path to process
162
+ * @param options - Options to control the file name extraction
146
163
  * @returns An indicator specifying if the file path has a file extension
147
164
  */
148
- declare function hasFileExtension(filePath: string): boolean;
165
+ declare function hasFileExtension(filePath: string, options?: FindFileExtensionOptions): boolean;
149
166
  /**
150
167
  * Resolve the file path to an absolute path.
151
168
  *
@@ -198,7 +215,7 @@ declare function relativeToCurrentDir(filePath: string): string;
198
215
  * @param path - The path to check
199
216
  * @returns An indicator specifying if the path is a relative path
200
217
  */
201
- declare function parsePath(path: string): {
218
+ declare function parsePath(path: string, options?: FindFileNameOptions): {
202
219
  root: string;
203
220
  dir: string;
204
221
  base: string;
@@ -210,9 +227,10 @@ declare function parsePath(path: string): {
210
227
  *
211
228
  * @param filePath - The current file path being processed
212
229
  * @param newFileName - The updated file name being processed
230
+ * @param options - Options to control the file name extraction
213
231
  * @returns The modified or unmodified file path.
214
232
  */
215
- declare function renameFile(filePath: string, newFileName: string): string;
233
+ declare function renameFile(filePath: string, newFileName: string, options?: FindFileNameOptions): string;
216
234
  //#endregion
217
- export { FindFileNameOptions, basename, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, hasFileExtension, hasFileName, hasFilePath, hasFolderName, parsePath, relative, relativePath, relativeToCurrentDir, renameFile, resolve, resolvePath, resolvePaths };
235
+ export { FindFileExtensionOptions, FindFileNameOptions, basename, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, hasFileExtension, hasFileName, hasFilePath, hasFolderName, parsePath, relative, relativePath, relativeToCurrentDir, renameFile, resolve, resolvePath, resolvePaths };
218
236
  //# sourceMappingURL=file-path-fns.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"file-path-fns.d.mts","names":[],"sources":["../src/file-path-fns.ts"],"sourcesContent":[],"mappings":";UA0BiB,m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;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgCD,iBAAA,6BAEJ;cAeC,gBAAO;;;;;;;;;;;;;iBAcJ,oBAAA,6BAEJ;;;;;;;;;;;;;iBAmBI,qBAAA,6BAEJ;;;;;;;;;;;;;iBAiBI,wBAAA,6BAEJ;;;;;;;iBAaI,WAAA;;;;;;;iBAUA,WAAA;;;;;;;iBAUA,aAAA;;;;;;;;iBAWA,gBAAA,6BAEJ;;;;;;;;iBAYI,WAAA;iBAoCA,OAAA;;;;;;;iBA0CA,YAAA;;;;;;;;;;;iBAgBA,QAAA;;;;;;;;;;;;iBAsCA,YAAA;;;;;;;iBAaA,oBAAA;;;;;;;iBAUA,SAAA,yBAAkC;;;;;;;;;;;;;;;iBAiClC,UAAA,kDAGJ"}
@@ -1,5 +1,5 @@
1
1
  import { cwd } from "./cwd.mjs";
2
- import { FILE_EXTENSION_REGEX, ROOT_FOLDER_REGEX } from "./regex.mjs";
2
+ import { FILE_EXTENSION_REGEX, FULL_FILE_EXTENSION_REGEX, ROOT_FOLDER_REGEX } from "./regex.mjs";
3
3
  import { isAbsolute, isAbsolutePath } from "./is-type.mjs";
4
4
  import { joinPaths } from "./join-paths.mjs";
5
5
  import { normalizeString, normalizeWindowsPath } from "./correct-path.mjs";
@@ -24,14 +24,14 @@ function findFileName(filePath, options = {}) {
24
24
  const { requireExtension = false, withExtension = true } = options;
25
25
  const result = normalizeWindowsPath(filePath)?.split(filePath?.includes("\\") ? "\\" : "/")?.pop() ?? "";
26
26
  if (requireExtension === true && !result.includes(".")) return EMPTY_STRING;
27
- if (withExtension === false && result.includes(".")) return result.replace(`.${findFileExtension(result) ?? ""}`, "") || EMPTY_STRING;
27
+ if (withExtension === false && result.includes(".")) return result.replace(`.${findFileExtension(result, options) ?? ""}`, "") || EMPTY_STRING;
28
28
  return result;
29
29
  }
30
30
  /**
31
31
  * Find the full file path's directories from a file path.
32
32
  *
33
33
  * @remarks
34
- * The functionality of this method is similar to the {@link path.dirname} function in Node's path module.
34
+ * The functionality of this method is similar to the {@link _path.dirname} function in Node's path module.
35
35
  *
36
36
  * @example
37
37
  * ```ts
@@ -56,7 +56,7 @@ const dirname = findFilePath;
56
56
  * Find the top most folder containing the file from a file path.
57
57
  *
58
58
  * @remarks
59
- * The functionality of this method is similar to the {@link path.basename} function in Node's path module.
59
+ * The functionality of this method is similar to the {@link _path.basename} function in Node's path module.
60
60
  * 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.
61
61
  *
62
62
  * @example
@@ -91,16 +91,21 @@ const basename = findFolderName;
91
91
  *
92
92
  * @example
93
93
  * ```ts
94
- * findFileExtension("C:\\Users\\user\\Documents\\file.config.ts");
95
- * // Returns "ts"
94
+ * findFileExtension("C:\\Users\\user\\Documents\\file.config.ts"); // Returns "ts"
95
+ * findFileExtension("C:\\Users\\user\\Documents\\file.d.ts"); // Returns "ts"
96
+ * findFileExtension("C:\\Users\\user\\Documents\\file.d.ts", { fullExtension: true }); // Returns "d.ts"
97
+ * findFileExtension("C:\\Users\\user\\Documents\\file.ts.map"); // Returns "ts"
98
+ * findFileExtension("C:\\Users\\user\\Documents\\file.ts.map", { fullExtension: true }); // Returns "ts.map"
99
+ * findFileExtension("C:\\Users\\user\\Documents\\file"); // Returns undefined
96
100
  * ```
97
101
  *
98
102
  * @param filePath - The file path to process
103
+ * @param options - Options to control the file name extraction
99
104
  * @returns The file extension or undefined if no extension is found
100
105
  */
101
- function findFileExtension(filePath) {
106
+ function findFileExtension(filePath, options) {
102
107
  if (filePath.endsWith(".") || filePath.endsWith("/")) return;
103
- const match = FILE_EXTENSION_REGEX.exec(normalizeWindowsPath(filePath));
108
+ const match = (options?.fullExtension ? FULL_FILE_EXTENSION_REGEX : FILE_EXTENSION_REGEX).exec(normalizeWindowsPath(filePath));
104
109
  return match && match.length > 0 && isSetString(match[0]) ? match[0].replace(".", "") : void 0;
105
110
  }
106
111
  const extname = findFileExtension;
@@ -113,10 +118,11 @@ const extname = findFileExtension;
113
118
  * The returned extension **will** include the dot, for example `.txt` or `.js` instead of `txt` or `js`.
114
119
  *
115
120
  * @param filePath - The file path to process
121
+ * @param options - Options to control the file name extraction
116
122
  * @returns The file extension (including the `"."` prefix) or undefined if no extension is found
117
123
  */
118
- function findFileDotExtension(filePath) {
119
- const ext = findFileExtension(filePath);
124
+ function findFileDotExtension(filePath, options) {
125
+ const ext = findFileExtension(filePath, options);
120
126
  return ext ? `.${ext}` : void 0;
121
127
  }
122
128
  /**
@@ -128,10 +134,11 @@ function findFileDotExtension(filePath) {
128
134
  * The returned extension **will not** include the dot, for example `txt` or `js` instead of `.txt` or `.js`.
129
135
  *
130
136
  * @param filePath - The file path to process
137
+ * @param options - Options to control the file name extraction
131
138
  * @returns The file extension or an empty string if no extension is found
132
139
  */
133
- function findFileExtensionSafe(filePath) {
134
- return findFileExtension(filePath) ?? EMPTY_STRING;
140
+ function findFileExtensionSafe(filePath, options) {
141
+ return findFileExtension(filePath, options) ?? EMPTY_STRING;
135
142
  }
136
143
  /**
137
144
  * Find the file extension including the `"."` character prefix from a file path or an empty string.
@@ -142,10 +149,11 @@ function findFileExtensionSafe(filePath) {
142
149
  * The returned extension **will** include the dot, for example `.txt` or `.js` instead of `txt` or `js`.
143
150
  *
144
151
  * @param filePath - The file path to process
152
+ * @param options - Options to control the file name extraction
145
153
  * @returns The file extension (including the `"."` prefix) or an empty string if no extension is found
146
154
  */
147
- function findFileDotExtensionSafe(filePath) {
148
- const ext = findFileExtension(filePath);
155
+ function findFileDotExtensionSafe(filePath, options) {
156
+ const ext = findFileExtension(filePath, options);
149
157
  return ext ? `.${ext}` : "";
150
158
  }
151
159
  /**
@@ -179,10 +187,11 @@ function hasFolderName(filePath) {
179
187
  * Check if a file path has a file extension.
180
188
  *
181
189
  * @param filePath - The file path to process
190
+ * @param options - Options to control the file name extraction
182
191
  * @returns An indicator specifying if the file path has a file extension
183
192
  */
184
- function hasFileExtension(filePath) {
185
- return Boolean(findFileExtension(filePath));
193
+ function hasFileExtension(filePath, options) {
194
+ return Boolean(findFileExtension(filePath, options));
186
195
  }
187
196
  /**
188
197
  * Resolve the file path to an absolute path.
@@ -279,14 +288,14 @@ function relativeToCurrentDir(filePath) {
279
288
  * @param path - The path to check
280
289
  * @returns An indicator specifying if the path is a relative path
281
290
  */
282
- function parsePath(path) {
291
+ function parsePath(path, options) {
283
292
  const root = /^[/\\]|^[a-z]:[/\\]/i.exec(path)?.[0]?.replace(/\\/g, "/") || "";
284
293
  const normalizedPath = normalizeWindowsPath(path);
285
294
  const segments = normalizedPath.replace(/\/$/, "").split("/").slice(0, -1);
286
295
  if (segments.length === 1 && /^[A-Z]:$/i.test(segments[0])) segments[0] += "/";
287
- const base = findFolderName(normalizedPath);
296
+ const base = findFolderName(normalizedPath, options);
288
297
  const dir = segments.join("/") || (isAbsolutePath(path) ? "/" : ".");
289
- const ext = findFileExtensionSafe(path);
298
+ const ext = findFileExtensionSafe(path, options);
290
299
  return {
291
300
  root,
292
301
  dir,
@@ -300,10 +309,11 @@ function parsePath(path) {
300
309
  *
301
310
  * @param filePath - The current file path being processed
302
311
  * @param newFileName - The updated file name being processed
312
+ * @param options - Options to control the file name extraction
303
313
  * @returns The modified or unmodified file path.
304
314
  */
305
- function renameFile(filePath, newFileName) {
306
- const file = parsePath(filePath);
315
+ function renameFile(filePath, newFileName, options) {
316
+ const file = parsePath(filePath, options);
307
317
  return joinPaths(file.dir, newFileName.includes(".") ? newFileName : newFileName + file.ext);
308
318
  }
309
319
 
@@ -1 +1 @@
1
- {"version":3,"file":"file-path-fns.mjs","names":["currentDir","path","cwd"],"sources":["../src/file-path-fns.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 { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { EMPTY_STRING } from \"@stryke/types/base\";\nimport { normalizeString, normalizeWindowsPath } from \"./correct-path\";\nimport { cwd as currentDir } from \"./cwd\";\nimport { isAbsolute, isAbsolutePath } from \"./is-type\";\nimport { joinPaths } from \"./join-paths\";\nimport { FILE_EXTENSION_REGEX, ROOT_FOLDER_REGEX } from \"./regex\";\n\nexport interface FindFileNameOptions {\n /**\n * Require the file extension to be present in the file name.\n *\n * @defaultValue false\n */\n requireExtension?: boolean;\n\n /**\n * Return the file extension as part of the full file name result.\n *\n * @defaultValue true\n */\n withExtension?: boolean;\n}\n\n/**\n * Find the file name from a file path.\n *\n * @example\n * ```ts\n * const fileName = findFileName(\"C:\\\\Users\\\\user\\\\Documents\\\\file.txt\");\n * // fileName = \"file.txt\"\n * ```\n *\n * @param filePath - The file path to process\n * @param options - Options to control the file name extraction\n * @returns The file name\n */\nexport function findFileName(\n filePath: string,\n options: FindFileNameOptions = {}\n): string {\n const { requireExtension = false, withExtension = true } = options;\n const result =\n normalizeWindowsPath(filePath)\n ?.split(filePath?.includes(\"\\\\\") ? \"\\\\\" : \"/\")\n ?.pop() ?? \"\";\n\n if (requireExtension === true && !result.includes(\".\")) {\n return EMPTY_STRING;\n }\n\n if (withExtension === false && result.includes(\".\")) {\n return (\n result.replace(`.${findFileExtension(result) ?? \"\"}`, \"\") || EMPTY_STRING\n );\n }\n\n return result;\n}\n\n/**\n * Find the full file path's directories from a file path.\n *\n * @remarks\n * The functionality of this method is similar to the {@link path.dirname} function in Node's path module.\n *\n * @example\n * ```ts\n * const folderPath = findFilePath(\"C:\\\\Users\\\\user\\\\Documents\\\\file.txt\");\n * // folderPath = \"C:\\\\Users\\\\user\\\\Documents\"\n * ```\n *\n * @param filePath - The file path to process\n * @param options - Options to control the file name extraction\n * @returns The full file path's directories\n */\nexport function findFilePath(\n filePath: string,\n options: FindFileNameOptions = {}\n): string {\n const normalizedPath = normalizeWindowsPath(filePath);\n\n const result = normalizedPath.replace(\n findFileName(normalizedPath, { requireExtension: false, ...options }),\n \"\"\n );\n\n return result === \"/\" ? result : result.replace(/\\/$/, \"\");\n}\n\nexport const dirname = findFilePath;\n\n/**\n * Find the top most folder containing the file from a file path.\n *\n * @remarks\n * The functionality of this method is similar to the {@link path.basename} function in Node's path module.\n * 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.\n *\n * @example\n * const folderPath = findFolderName(\"C:\\\\Users\\\\user\\\\Documents\\\\file.txt\");\n * // folderPath = \"Documents\"\n *\n * @param filePath - The file path to process\n * @param options - Options to control the file name extraction\n * @returns The folder containing the file\n */\nexport function findFolderName(\n filePath: string,\n options?: FindFileNameOptions\n): string {\n const segments = findFilePath(filePath, options).split(\"/\");\n\n let lastSegment = \"\";\n for (let i = segments.length - 1; i >= 0; i--) {\n const val = segments[i];\n if (val) {\n lastSegment = val;\n break;\n }\n }\n\n // if (\n // folderPath.lastIndexOf(\"\\\\\") === folderPath.length - 1 ||\n // folderPath.lastIndexOf(\"/\") === folderPath.length - 1\n // ) {\n // folderPath = folderPath.slice(0, Math.max(0, folderPath.length - 1));\n // }\n\n return lastSegment ?? EMPTY_STRING;\n}\n\nexport const basename = findFolderName;\n\n/**\n * Find the file extension from a file path.\n *\n * @remarks\n * The functionality of this method is similar to the {@link path.extname} function in Node's path module.\n * 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`.\n *\n * The returned extension **will not** include the dot, for example `txt` or `js` instead of `.txt` or `.js`.\n *\n * @example\n * ```ts\n * findFileExtension(\"C:\\\\Users\\\\user\\\\Documents\\\\file.config.ts\");\n * // Returns \"ts\"\n * ```\n *\n * @param filePath - The file path to process\n * @returns The file extension or undefined if no extension is found\n */\nexport function findFileExtension(filePath: string): string | undefined {\n if (filePath.endsWith(\".\") || filePath.endsWith(\"/\")) {\n return undefined;\n }\n\n const match = FILE_EXTENSION_REGEX.exec(normalizeWindowsPath(filePath));\n\n return match && match.length > 0 && isSetString(match[0])\n ? match[0].replace(\".\", \"\")\n : undefined;\n}\n\nexport const extname = findFileExtension;\n\n/**\n * Find the file extension including the `\".\"` character prefix from a file path.\n *\n * @remarks\n * The file extension is the part of the file name that comes after (and including) 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`.\n *\n * The returned extension **will** include the dot, for example `.txt` or `.js` instead of `txt` or `js`.\n *\n * @param filePath - The file path to process\n * @returns The file extension (including the `\".\"` prefix) or undefined if no extension is found\n */\nexport function findFileDotExtension(filePath: string): string | undefined {\n const ext = findFileExtension(filePath);\n\n return ext ? `.${ext}` : undefined;\n}\n\n/**\n * Find the file extension from a file path or an empty string.\n *\n * @remarks\n * 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`.\n *\n * The returned extension **will not** include the dot, for example `txt` or `js` instead of `.txt` or `.js`.\n *\n * @param filePath - The file path to process\n * @returns The file extension or an empty string if no extension is found\n */\nexport function findFileExtensionSafe(filePath: string): string {\n return findFileExtension(filePath) ?? EMPTY_STRING;\n}\n\n/**\n * Find the file extension including the `\".\"` character prefix from a file path or an empty string.\n *\n * @remarks\n * The file extension is the part of the file name that comes after (and including) 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`.\n *\n * The returned extension **will** include the dot, for example `.txt` or `.js` instead of `txt` or `js`.\n *\n * @param filePath - The file path to process\n * @returns The file extension (including the `\".\"` prefix) or an empty string if no extension is found\n */\nexport function findFileDotExtensionSafe(filePath: string): string {\n const ext = findFileExtension(filePath);\n\n return ext ? `.${ext}` : \"\";\n}\n\n/**\n * Check if a file path has a file name.\n *\n * @param filePath - The file path to process\n * @returns An indicator specifying if the file path has a file name\n */\nexport function hasFileName(filePath: string): boolean {\n return Boolean(findFileName(filePath));\n}\n\n/**\n * Check if a file path has a file path.\n *\n * @param filePath - The file path to process\n * @returns An indicator specifying if the file path has a file path\n */\nexport function hasFilePath(filePath: string): boolean {\n return Boolean(findFilePath(filePath));\n}\n\n/**\n * Check if a file path has a folder name.\n *\n * @param filePath - The file path to process\n * @returns An indicator specifying if the file path has a folder name\n */\nexport function hasFolderName(filePath: string): boolean {\n return Boolean(findFolderName(filePath));\n}\n\n/**\n * Check if a file path has a file extension.\n *\n * @param filePath - The file path to process\n * @returns An indicator specifying if the file path has a file extension\n */\nexport function hasFileExtension(filePath: string): boolean {\n return Boolean(findFileExtension(filePath));\n}\n\n/**\n * Resolve the file path to an absolute path.\n *\n * @param path - The path to resolve\n * @param cwd - The current working directory\n * @returns The resolved path\n */\nexport function resolvePath(path: string, cwd = currentDir()) {\n // Normalize windows arguments\n const paths = normalizeWindowsPath(path).split(\"/\");\n\n let resolvedPath = \"\";\n let resolvedAbsolute = false;\n\n for (\n let index = paths.length - 1;\n index >= -1 && !resolvedAbsolute;\n index--\n ) {\n const path = index >= 0 ? paths[index] : cwd;\n\n // Skip empty entries\n if (!path || path.length === 0) {\n continue;\n }\n\n resolvedPath = joinPaths(path, resolvedPath);\n resolvedAbsolute = isAbsolutePath(path);\n }\n\n // At this point the path should be resolved to a full absolute path, but\n // handle relative paths to be safe (might happen when process.cwd() fails)\n\n // Normalize the path\n resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);\n\n if (resolvedAbsolute && !isAbsolutePath(resolvedPath)) {\n return `/${resolvedPath}`;\n }\n\n return resolvedPath.length > 0 ? resolvedPath : \".\";\n}\n\nexport function resolve(...paths: string[]) {\n // Normalize windows arguments\n paths = paths.map(argument => normalizeWindowsPath(argument));\n\n let resolvedPath = \"\";\n let resolvedAbsolute = false;\n\n for (\n let index = paths.length - 1;\n index >= -1 && !resolvedAbsolute;\n index--\n ) {\n const path = index >= 0 ? paths[index] : currentDir();\n\n // Skip empty entries\n if (!path || path.length === 0) {\n continue;\n }\n\n resolvedPath = `${path}/${resolvedPath}`;\n resolvedAbsolute = isAbsolute(path);\n }\n\n // At this point the path should be resolved to a full absolute path, but\n // handle relative paths to be safe (might happen when process.cwd() fails)\n\n // Normalize the path\n resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);\n\n if (resolvedAbsolute && !isAbsolute(resolvedPath)) {\n return `/${resolvedPath}`;\n }\n\n return resolvedPath.length > 0 ? resolvedPath : \".\";\n}\n\n/**\n * Resolve the file path to an absolute path.\n *\n * @param paths - The paths to resolve\n * @returns The resolved path\n */\nexport function resolvePaths(...paths: string[]) {\n return resolvePath(\n joinPaths(...paths.map(path => normalizeWindowsPath(path)))\n );\n}\n\n/**\n * Get the relative path from one file to another.\n *\n * @remarks\n * This function is similar to the `path.relative` function in Node's path module.\n *\n * @param from - The base path to start from\n * @param to - The target path to resolve relative to the base path\n * @returns The relative path from the base path to the target path\n */\nexport function relative(from: string, to: string) {\n // we cast these because `split` will always be at least one string\n const _from = resolve(from).replace(ROOT_FOLDER_REGEX, \"$1\").split(\"/\") as [\n string,\n ...string[]\n ];\n const _to = resolve(to).replace(ROOT_FOLDER_REGEX, \"$1\").split(\"/\") as [\n string,\n ...string[]\n ];\n\n // Different windows drive letters\n if (_to[0][1] === \":\" && _from[0][1] === \":\" && _from[0] !== _to[0]) {\n return _to.join(\"/\");\n }\n\n const _fromCopy = [..._from];\n for (const segment of _fromCopy) {\n if (_to[0] !== segment) {\n break;\n }\n _from.shift();\n _to.shift();\n }\n return [..._from.map(() => \"..\"), ..._to].join(\"/\");\n}\n\n/**\n * Get the relative path from one file to another.\n *\n * @remarks\n * This function wraps the `path.relative` function in Node's path module.\n *\n * @param from - The base path to start from\n * @param to - The target path to resolve relative to the base path\n * @param withEndSlash - Whether to include a trailing slash at the end of the path\n * @returns The relative path from the base path to the target path\n */\nexport function relativePath(from: string, to: string, withEndSlash = false) {\n return relative(\n withEndSlash !== true ? from.replace(/\\/$/, \"\") : from,\n withEndSlash !== true ? to.replace(/\\/$/, \"\") : to\n );\n}\n\n/**\n * Find the file path relative to the workspace root path.\n *\n * @param filePath - The file path to process\n * @returns The resolved file path\n */\nexport function relativeToCurrentDir(filePath: string) {\n return relativePath(filePath, currentDir());\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 parsePath(path: string) {\n // The root of the path such as '/' or 'c:\\'\n const root =\n /^[/\\\\]|^[a-z]:[/\\\\]/i.exec(path)?.[0]?.replace(/\\\\/g, \"/\") || \"\";\n\n const normalizedPath = normalizeWindowsPath(path);\n\n const segments = normalizedPath.replace(/\\/$/, \"\").split(\"/\").slice(0, -1);\n if (segments.length === 1 && /^[A-Z]:$/i.test(segments[0] as string)) {\n segments[0] += \"/\";\n }\n\n const base = findFolderName(normalizedPath);\n const dir = segments.join(\"/\") || (isAbsolutePath(path) ? \"/\" : \".\");\n const ext = findFileExtensionSafe(path);\n\n return {\n root,\n dir,\n base,\n ext,\n name: base.slice(0, base.length - ext.length)\n };\n}\n\n/**\n * Rename the file name with a new name.\n *\n * @param filePath - The current file path being processed\n * @param newFileName - The updated file name being processed\n * @returns The modified or unmodified file path.\n */\nexport function renameFile(filePath: string, newFileName: string): string {\n const file = parsePath(filePath);\n\n return joinPaths(\n file.dir,\n newFileName.includes(\".\") ? newFileName : newFileName + file.ext\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAuDA,SAAgB,aACd,UACA,UAA+B,EAAE,EACzB;CACR,MAAM,EAAE,mBAAmB,OAAO,gBAAgB,SAAS;CAC3D,MAAM,SACJ,qBAAqB,SAAS,EAC1B,MAAM,UAAU,SAAS,KAAK,GAAG,OAAO,IAAI,EAC5C,KAAK,IAAI;AAEf,KAAI,qBAAqB,QAAQ,CAAC,OAAO,SAAS,IAAI,CACpD,QAAO;AAGT,KAAI,kBAAk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AS,WAAW,KAAK,YAAY,KAAK,SAAS,GAAa,CAClE,UAAS,MAAM;CAGjB,MAAM,OAAO,eAAe,eAAe;CAC3C,MAAM,MAAM,SAAS,KAAK,IAAI,KAAK,eAAe,KAAK,GAAG,MAAM;CAChE,MAAM,MAAM,sBAAsB,KAAK;AAEvC,QAAO;EACL;EACA;EACA;EACA;EACA,MAAM,KAAK,MAAM,GAAG,KAAK,SAAS,IAAI,OAAO;EAC9C;;;;;;;;;AAUH,SAAgB,WAAW,UAAkB,aAA6B;CACxE,MAAM,OAAO,UAAU,SAAS;AAEhC,QAAO,UACL,KAAK,KACL,YAAY,SAAS,IAAI,GAAG,cAAc,cAAc,KAAK,IAC9D"}
1
+ {"version":3,"file":"file-path-fns.mjs","names":["currentDir","path","cwd"],"sources":["../src/file-path-fns.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 { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { EMPTY_STRING } from \"@stryke/types/base\";\nimport _path from \"node:path\";\nimport { normalizeString, normalizeWindowsPath } from \"./correct-path\";\nimport { cwd as currentDir } from \"./cwd\";\nimport { isAbsolute, isAbsolutePath } from \"./is-type\";\nimport { joinPaths } from \"./join-paths\";\nimport {\n FILE_EXTENSION_REGEX,\n FULL_FILE_EXTENSION_REGEX,\n ROOT_FOLDER_REGEX\n} from \"./regex\";\n\nexport interface FindFileNameOptions extends FindFileExtensionOptions {\n /**\n * Require the file extension to be present in the file name.\n *\n * @defaultValue false\n */\n requireExtension?: boolean;\n\n /**\n * Return the file extension as part of the full file name result.\n *\n * @defaultValue true\n */\n withExtension?: boolean;\n}\n\n/**\n * Find the file name from a file path.\n *\n * @example\n * ```ts\n * const fileName = findFileName(\"C:\\\\Users\\\\user\\\\Documents\\\\file.txt\");\n * // fileName = \"file.txt\"\n * ```\n *\n * @param filePath - The file path to process\n * @param options - Options to control the file name extraction\n * @returns The file name\n */\nexport function findFileName(\n filePath: string,\n options: FindFileNameOptions = {}\n): string {\n const { requireExtension = false, withExtension = true } = options;\n const result =\n normalizeWindowsPath(filePath)\n ?.split(filePath?.includes(\"\\\\\") ? \"\\\\\" : \"/\")\n ?.pop() ?? \"\";\n\n if (requireExtension === true && !result.includes(\".\")) {\n return EMPTY_STRING;\n }\n\n if (withExtension === false && result.includes(\".\")) {\n return (\n result.replace(`.${findFileExtension(result, options) ?? \"\"}`, \"\") ||\n EMPTY_STRING\n );\n }\n\n return result;\n}\n\n/**\n * Find the full file path's directories from a file path.\n *\n * @remarks\n * The functionality of this method is similar to the {@link _path.dirname} function in Node's path module.\n *\n * @example\n * ```ts\n * const folderPath = findFilePath(\"C:\\\\Users\\\\user\\\\Documents\\\\file.txt\");\n * // folderPath = \"C:\\\\Users\\\\user\\\\Documents\"\n * ```\n *\n * @param filePath - The file path to process\n * @param options - Options to control the file name extraction\n * @returns The full file path's directories\n */\nexport function findFilePath(\n filePath: string,\n options: FindFileNameOptions = {}\n): string {\n const normalizedPath = normalizeWindowsPath(filePath);\n\n const result = normalizedPath.replace(\n findFileName(normalizedPath, { requireExtension: false, ...options }),\n \"\"\n );\n\n return result === \"/\" ? result : result.replace(/\\/$/, \"\");\n}\n\nexport const dirname = findFilePath;\n\n/**\n * Find the top most folder containing the file from a file path.\n *\n * @remarks\n * The functionality of this method is similar to the {@link _path.basename} function in Node's path module.\n * 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.\n *\n * @example\n * const folderPath = findFolderName(\"C:\\\\Users\\\\user\\\\Documents\\\\file.txt\");\n * // folderPath = \"Documents\"\n *\n * @param filePath - The file path to process\n * @param options - Options to control the file name extraction\n * @returns The folder containing the file\n */\nexport function findFolderName(\n filePath: string,\n options?: FindFileNameOptions\n): string {\n const segments = findFilePath(filePath, options).split(\"/\");\n\n let lastSegment = \"\";\n for (let i = segments.length - 1; i >= 0; i--) {\n const val = segments[i];\n if (val) {\n lastSegment = val;\n break;\n }\n }\n\n // if (\n // folderPath.lastIndexOf(\"\\\\\") === folderPath.length - 1 ||\n // folderPath.lastIndexOf(\"/\") === folderPath.length - 1\n // ) {\n // folderPath = folderPath.slice(0, Math.max(0, folderPath.length - 1));\n // }\n\n return lastSegment ?? EMPTY_STRING;\n}\n\nexport const basename = findFolderName;\n\nexport interface FindFileExtensionOptions {\n /**\n * Return the full file extension including `.d` and `.map` if present.\n *\n * @defaultValue false\n */\n fullExtension?: boolean;\n}\n\n/**\n * Find the file extension from a file path.\n *\n * @remarks\n * The functionality of this method is similar to the {@link path.extname} function in Node's path module.\n * 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`.\n *\n * The returned extension **will not** include the dot, for example `txt` or `js` instead of `.txt` or `.js`.\n *\n * @example\n * ```ts\n * findFileExtension(\"C:\\\\Users\\\\user\\\\Documents\\\\file.config.ts\"); // Returns \"ts\"\n * findFileExtension(\"C:\\\\Users\\\\user\\\\Documents\\\\file.d.ts\"); // Returns \"ts\"\n * findFileExtension(\"C:\\\\Users\\\\user\\\\Documents\\\\file.d.ts\", { fullExtension: true }); // Returns \"d.ts\"\n * findFileExtension(\"C:\\\\Users\\\\user\\\\Documents\\\\file.ts.map\"); // Returns \"ts\"\n * findFileExtension(\"C:\\\\Users\\\\user\\\\Documents\\\\file.ts.map\", { fullExtension: true }); // Returns \"ts.map\"\n * findFileExtension(\"C:\\\\Users\\\\user\\\\Documents\\\\file\"); // Returns undefined\n * ```\n *\n * @param filePath - The file path to process\n * @param options - Options to control the file name extraction\n * @returns The file extension or undefined if no extension is found\n */\nexport function findFileExtension(\n filePath: string,\n options?: FindFileExtensionOptions\n): string | undefined {\n if (filePath.endsWith(\".\") || filePath.endsWith(\"/\")) {\n return undefined;\n }\n\n const match = (\n options?.fullExtension ? FULL_FILE_EXTENSION_REGEX : FILE_EXTENSION_REGEX\n ).exec(normalizeWindowsPath(filePath));\n\n return match && match.length > 0 && isSetString(match[0])\n ? match[0].replace(\".\", \"\")\n : undefined;\n}\n\nexport const extname = findFileExtension;\n\n/**\n * Find the file extension including the `\".\"` character prefix from a file path.\n *\n * @remarks\n * The file extension is the part of the file name that comes after (and including) 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`.\n *\n * The returned extension **will** include the dot, for example `.txt` or `.js` instead of `txt` or `js`.\n *\n * @param filePath - The file path to process\n * @param options - Options to control the file name extraction\n * @returns The file extension (including the `\".\"` prefix) or undefined if no extension is found\n */\nexport function findFileDotExtension(\n filePath: string,\n options?: FindFileExtensionOptions\n): string | undefined {\n const ext = findFileExtension(filePath, options);\n\n return ext ? `.${ext}` : undefined;\n}\n\n/**\n * Find the file extension from a file path or an empty string.\n *\n * @remarks\n * 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`.\n *\n * The returned extension **will not** include the dot, for example `txt` or `js` instead of `.txt` or `.js`.\n *\n * @param filePath - The file path to process\n * @param options - Options to control the file name extraction\n * @returns The file extension or an empty string if no extension is found\n */\nexport function findFileExtensionSafe(\n filePath: string,\n options?: FindFileExtensionOptions\n): string {\n return findFileExtension(filePath, options) ?? EMPTY_STRING;\n}\n\n/**\n * Find the file extension including the `\".\"` character prefix from a file path or an empty string.\n *\n * @remarks\n * The file extension is the part of the file name that comes after (and including) 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`.\n *\n * The returned extension **will** include the dot, for example `.txt` or `.js` instead of `txt` or `js`.\n *\n * @param filePath - The file path to process\n * @param options - Options to control the file name extraction\n * @returns The file extension (including the `\".\"` prefix) or an empty string if no extension is found\n */\nexport function findFileDotExtensionSafe(\n filePath: string,\n options?: FindFileExtensionOptions\n): string {\n const ext = findFileExtension(filePath, options);\n\n return ext ? `.${ext}` : \"\";\n}\n\n/**\n * Check if a file path has a file name.\n *\n * @param filePath - The file path to process\n * @returns An indicator specifying if the file path has a file name\n */\nexport function hasFileName(filePath: string): boolean {\n return Boolean(findFileName(filePath));\n}\n\n/**\n * Check if a file path has a file path.\n *\n * @param filePath - The file path to process\n * @returns An indicator specifying if the file path has a file path\n */\nexport function hasFilePath(filePath: string): boolean {\n return Boolean(findFilePath(filePath));\n}\n\n/**\n * Check if a file path has a folder name.\n *\n * @param filePath - The file path to process\n * @returns An indicator specifying if the file path has a folder name\n */\nexport function hasFolderName(filePath: string): boolean {\n return Boolean(findFolderName(filePath));\n}\n\n/**\n * Check if a file path has a file extension.\n *\n * @param filePath - The file path to process\n * @param options - Options to control the file name extraction\n * @returns An indicator specifying if the file path has a file extension\n */\nexport function hasFileExtension(\n filePath: string,\n options?: FindFileExtensionOptions\n): boolean {\n return Boolean(findFileExtension(filePath, options));\n}\n\n/**\n * Resolve the file path to an absolute path.\n *\n * @param path - The path to resolve\n * @param cwd - The current working directory\n * @returns The resolved path\n */\nexport function resolvePath(path: string, cwd = currentDir()) {\n // Normalize windows arguments\n const paths = normalizeWindowsPath(path).split(\"/\");\n\n let resolvedPath = \"\";\n let resolvedAbsolute = false;\n\n for (\n let index = paths.length - 1;\n index >= -1 && !resolvedAbsolute;\n index--\n ) {\n const path = index >= 0 ? paths[index] : cwd;\n\n // Skip empty entries\n if (!path || path.length === 0) {\n continue;\n }\n\n resolvedPath = joinPaths(path, resolvedPath);\n resolvedAbsolute = isAbsolutePath(path);\n }\n\n // At this point the path should be resolved to a full absolute path, but\n // handle relative paths to be safe (might happen when process.cwd() fails)\n\n // Normalize the path\n resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);\n\n if (resolvedAbsolute && !isAbsolutePath(resolvedPath)) {\n return `/${resolvedPath}`;\n }\n\n return resolvedPath.length > 0 ? resolvedPath : \".\";\n}\n\nexport function resolve(...paths: string[]) {\n // Normalize windows arguments\n paths = paths.map(argument => normalizeWindowsPath(argument));\n\n let resolvedPath = \"\";\n let resolvedAbsolute = false;\n\n for (\n let index = paths.length - 1;\n index >= -1 && !resolvedAbsolute;\n index--\n ) {\n const path = index >= 0 ? paths[index] : currentDir();\n\n // Skip empty entries\n if (!path || path.length === 0) {\n continue;\n }\n\n resolvedPath = `${path}/${resolvedPath}`;\n resolvedAbsolute = isAbsolute(path);\n }\n\n // At this point the path should be resolved to a full absolute path, but\n // handle relative paths to be safe (might happen when process.cwd() fails)\n\n // Normalize the path\n resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);\n\n if (resolvedAbsolute && !isAbsolute(resolvedPath)) {\n return `/${resolvedPath}`;\n }\n\n return resolvedPath.length > 0 ? resolvedPath : \".\";\n}\n\n/**\n * Resolve the file path to an absolute path.\n *\n * @param paths - The paths to resolve\n * @returns The resolved path\n */\nexport function resolvePaths(...paths: string[]) {\n return resolvePath(\n joinPaths(...paths.map(path => normalizeWindowsPath(path)))\n );\n}\n\n/**\n * Get the relative path from one file to another.\n *\n * @remarks\n * This function is similar to the `path.relative` function in Node's path module.\n *\n * @param from - The base path to start from\n * @param to - The target path to resolve relative to the base path\n * @returns The relative path from the base path to the target path\n */\nexport function relative(from: string, to: string) {\n // we cast these because `split` will always be at least one string\n const _from = resolve(from).replace(ROOT_FOLDER_REGEX, \"$1\").split(\"/\") as [\n string,\n ...string[]\n ];\n const _to = resolve(to).replace(ROOT_FOLDER_REGEX, \"$1\").split(\"/\") as [\n string,\n ...string[]\n ];\n\n // Different windows drive letters\n if (_to[0][1] === \":\" && _from[0][1] === \":\" && _from[0] !== _to[0]) {\n return _to.join(\"/\");\n }\n\n const _fromCopy = [..._from];\n for (const segment of _fromCopy) {\n if (_to[0] !== segment) {\n break;\n }\n _from.shift();\n _to.shift();\n }\n return [..._from.map(() => \"..\"), ..._to].join(\"/\");\n}\n\n/**\n * Get the relative path from one file to another.\n *\n * @remarks\n * This function wraps the `path.relative` function in Node's path module.\n *\n * @param from - The base path to start from\n * @param to - The target path to resolve relative to the base path\n * @param withEndSlash - Whether to include a trailing slash at the end of the path\n * @returns The relative path from the base path to the target path\n */\nexport function relativePath(from: string, to: string, withEndSlash = false) {\n return relative(\n withEndSlash !== true ? from.replace(/\\/$/, \"\") : from,\n withEndSlash !== true ? to.replace(/\\/$/, \"\") : to\n );\n}\n\n/**\n * Find the file path relative to the workspace root path.\n *\n * @param filePath - The file path to process\n * @returns The resolved file path\n */\nexport function relativeToCurrentDir(filePath: string) {\n return relativePath(filePath, currentDir());\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 parsePath(path: string, options?: FindFileNameOptions) {\n // The root of the path such as '/' or 'c:\\'\n const root =\n /^[/\\\\]|^[a-z]:[/\\\\]/i.exec(path)?.[0]?.replace(/\\\\/g, \"/\") || \"\";\n\n const normalizedPath = normalizeWindowsPath(path);\n\n const segments = normalizedPath.replace(/\\/$/, \"\").split(\"/\").slice(0, -1);\n if (segments.length === 1 && /^[A-Z]:$/i.test(segments[0] as string)) {\n segments[0] += \"/\";\n }\n\n const base = findFolderName(normalizedPath, options);\n const dir = segments.join(\"/\") || (isAbsolutePath(path) ? \"/\" : \".\");\n const ext = findFileExtensionSafe(path, options);\n\n return {\n root,\n dir,\n base,\n ext,\n name: base.slice(0, base.length - ext.length)\n };\n}\n\n/**\n * Rename the file name with a new name.\n *\n * @param filePath - The current file path being processed\n * @param newFileName - The updated file name being processed\n * @param options - Options to control the file name extraction\n * @returns The modified or unmodified file path.\n */\nexport function renameFile(\n filePath: string,\n newFileName: string,\n options?: FindFileNameOptions\n): string {\n const file = parsePath(filePath, options);\n\n return joinPaths(\n file.dir,\n newFileName.includes(\".\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AAQ,OAAO,GAAG,GAAG,MAClD,iBAAiB,OAAO,GAAG,QAAQ,OAAO,GAAG,GAAG,GACjD;;;;;;;;AASH,SAAgB,qBAAqB,UAAkB;AACrD,QAAO,aAAa,UAAUA,KAAY,CAAC;;;;;;;;AAS7C,SAAgB,UAAU,MAAc,SAA+B;CAErE,MAAM,OACJ,uBAAuB,KAAK,KAAK,GAAG,IAAI,QAAQ,OAAO,IAAI,IAAI;CAEjE,MAAM,iBAAiB,qBAAqB,KAAK;CAEjD,MAAM,WAAW,eAAe,QAAQ,OAAO,GAAG,CAAC,MAAM,IAAI,CAAC,MAAM,GAAG,GAAG;AAC1E,KAAI,SAAS,WAAW,KAAK,YAAY,KAAK,SAAS,GAAa,CAClE,UAAS,MAAM;CAGjB,MAAM,OAAO,eAAe,gBAAgB,QAAQ;CACpD,MAAM,MAAM,SAAS,KAAK,IAAI,KAAK,eAAe,KAAK,GAAG,MAAM;CAChE,MAAM,MAAM,sBAAsB,MAAM,QAAQ;AAEhD,QAAO;EACL;EACA;EACA;EACA;EACA,MAAM,KAAK,MAAM,GAAG,KAAK,SAAS,IAAI,OAAO;EAC9C;;;;;;;;;;AAWH,SAAgB,WACd,UACA,aACA,SACQ;CACR,MAAM,OAAO,UAAU,UAAU,QAAQ;AAEzC,QAAO,UACL,KAAK,KACL,YAAY,SAAS,IAAI,GAAG,cAAc,cAAc,KAAK,IAC9D"}
package/dist/find.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { FindFileNameOptions, basename, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, hasFileExtension, hasFileName, hasFilePath, hasFolderName, parsePath, relative, relativePath, relativeToCurrentDir, renameFile, resolve, resolvePath, resolvePaths } from "./file-path-fns.cjs";
2
- export { FindFileNameOptions, basename, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, hasFileExtension, hasFileName, hasFilePath, hasFolderName, parsePath, relative, relativePath, relativeToCurrentDir, renameFile, resolve, resolvePath, resolvePaths };
1
+ import { FindFileExtensionOptions, FindFileNameOptions, basename, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, hasFileExtension, hasFileName, hasFilePath, hasFolderName, parsePath, relative, relativePath, relativeToCurrentDir, renameFile, resolve, resolvePath, resolvePaths } from "./file-path-fns.cjs";
2
+ export { FindFileExtensionOptions, FindFileNameOptions, basename, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, hasFileExtension, hasFileName, hasFilePath, hasFolderName, parsePath, relative, relativePath, relativeToCurrentDir, renameFile, resolve, resolvePath, resolvePaths };
package/dist/find.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { FindFileNameOptions, basename, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, hasFileExtension, hasFileName, hasFilePath, hasFolderName, parsePath, relative, relativePath, relativeToCurrentDir, renameFile, resolve, resolvePath, resolvePaths } from "./file-path-fns.mjs";
2
- export { FindFileNameOptions, basename, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, hasFileExtension, hasFileName, hasFilePath, hasFolderName, parsePath, relative, relativePath, relativeToCurrentDir, renameFile, resolve, resolvePath, resolvePaths };
1
+ import { FindFileExtensionOptions, FindFileNameOptions, basename, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, hasFileExtension, hasFileName, hasFilePath, hasFolderName, parsePath, relative, relativePath, relativeToCurrentDir, renameFile, resolve, resolvePath, resolvePaths } from "./file-path-fns.mjs";
2
+ export { FindFileExtensionOptions, FindFileNameOptions, basename, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, hasFileExtension, hasFileName, hasFilePath, hasFolderName, parsePath, relative, relativePath, relativeToCurrentDir, renameFile, resolve, resolvePath, resolvePaths };
package/dist/index.cjs CHANGED
@@ -19,6 +19,7 @@ exports.DEFAULT_ASSET_EXTS = require_asset_extensions.DEFAULT_ASSET_EXTS;
19
19
  exports.DRIVE_LETTER_REGEX = require_regex.DRIVE_LETTER_REGEX;
20
20
  exports.DRIVE_LETTER_START_REGEX = require_regex.DRIVE_LETTER_START_REGEX;
21
21
  exports.FILE_EXTENSION_REGEX = require_regex.FILE_EXTENSION_REGEX;
22
+ exports.FULL_FILE_EXTENSION_REGEX = require_regex.FULL_FILE_EXTENSION_REGEX;
22
23
  exports.NPM_SCOPED_PACKAGE_REGEX = require_regex.NPM_SCOPED_PACKAGE_REGEX;
23
24
  exports.PACKAGE_PATH_REGEX = require_regex.PACKAGE_PATH_REGEX;
24
25
  exports.ROOT_FOLDER_REGEX = require_regex.ROOT_FOLDER_REGEX;
package/dist/index.d.cts CHANGED
@@ -4,13 +4,13 @@ import { commonPath } from "./common.cjs";
4
4
  import { correctPath, normalizeString, normalizeWindowsPath, stripStars, toAbsolutePath, toRelativePath, withTrailingSlash, withoutTrailingSlash } from "./correct-path.cjs";
5
5
  import { cwd } from "./cwd.cjs";
6
6
  import { delimiter, posix, win32 } from "./delimiter.cjs";
7
- import { FindFileNameOptions, basename, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, hasFileExtension, hasFileName, hasFilePath, hasFolderName, parsePath, relative, relativePath, relativeToCurrentDir, renameFile, resolve, resolvePath, resolvePaths } from "./file-path-fns.cjs";
7
+ import { FindFileExtensionOptions, FindFileNameOptions, basename, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, hasFileExtension, hasFileName, hasFilePath, hasFolderName, parsePath, relative, relativePath, relativeToCurrentDir, renameFile, resolve, resolvePath, resolvePaths } from "./file-path-fns.cjs";
8
8
  import { GlobToRegexOptions, globToRegex } from "./glob-to-regex.cjs";
9
9
  import { isParentPath } from "./is-parent-path.cjs";
10
10
  import { isSystemRoot } from "./is-root-dir.cjs";
11
11
  import { join, joinPaths } from "./join-paths.cjs";
12
- import { 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 } from "./regex.cjs";
12
+ import { ABSOLUTE_PATH_REGEX, DRIVE_LETTER_REGEX, DRIVE_LETTER_START_REGEX, FILE_EXTENSION_REGEX, FULL_FILE_EXTENSION_REGEX, NPM_SCOPED_PACKAGE_REGEX, PACKAGE_PATH_REGEX, ROOT_FOLDER_REGEX, UNC_REGEX } from "./regex.cjs";
13
13
  import { replaceExtension, replacePath } from "./replace.cjs";
14
14
  import { resolveParentPath } from "./resolve-parent-path.cjs";
15
15
  import { formatSlash, slash } from "./slash.cjs";
16
- export { ABSOLUTE_PATH_REGEX, AppendPathOptions, DEFAULT_ASSET_EXTS, DRIVE_LETTER_REGEX, DRIVE_LETTER_START_REGEX, FILE_EXTENSION_REGEX, FindFileNameOptions, GlobToRegexOptions, NPM_SCOPED_PACKAGE_REGEX, PACKAGE_PATH_REGEX, ROOT_FOLDER_REGEX, UNC_REGEX, append, appendExtension, appendPath, basename, commonPath, correctPath, cwd, delimiter, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, formatSlash, globToRegex, hasFileExtension, hasFileName, hasFilePath, hasFolderName, isParentPath, isSystemRoot, join, joinPaths, normalizeString, normalizeWindowsPath, parsePath, posix, relative, relativePath, relativeToCurrentDir, renameFile, replaceExtension, replacePath, resolve, resolveParentPath, resolvePath, resolvePaths, slash, stripStars, toAbsolutePath, toRelativePath, win32, withTrailingSlash, withoutTrailingSlash };
16
+ export { ABSOLUTE_PATH_REGEX, AppendPathOptions, DEFAULT_ASSET_EXTS, DRIVE_LETTER_REGEX, DRIVE_LETTER_START_REGEX, FILE_EXTENSION_REGEX, FULL_FILE_EXTENSION_REGEX, FindFileExtensionOptions, FindFileNameOptions, GlobToRegexOptions, NPM_SCOPED_PACKAGE_REGEX, PACKAGE_PATH_REGEX, ROOT_FOLDER_REGEX, UNC_REGEX, append, appendExtension, appendPath, basename, commonPath, correctPath, cwd, delimiter, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, formatSlash, globToRegex, hasFileExtension, hasFileName, hasFilePath, hasFolderName, isParentPath, isSystemRoot, join, joinPaths, normalizeString, normalizeWindowsPath, parsePath, posix, relative, relativePath, relativeToCurrentDir, renameFile, replaceExtension, replacePath, resolve, resolveParentPath, resolvePath, resolvePaths, slash, stripStars, toAbsolutePath, toRelativePath, win32, withTrailingSlash, withoutTrailingSlash };
package/dist/index.d.mts CHANGED
@@ -4,13 +4,13 @@ import { commonPath } from "./common.mjs";
4
4
  import { correctPath, normalizeString, normalizeWindowsPath, stripStars, toAbsolutePath, toRelativePath, withTrailingSlash, withoutTrailingSlash } from "./correct-path.mjs";
5
5
  import { cwd } from "./cwd.mjs";
6
6
  import { delimiter, posix, win32 } from "./delimiter.mjs";
7
- import { FindFileNameOptions, basename, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, hasFileExtension, hasFileName, hasFilePath, hasFolderName, parsePath, relative, relativePath, relativeToCurrentDir, renameFile, resolve, resolvePath, resolvePaths } from "./file-path-fns.mjs";
7
+ import { FindFileExtensionOptions, FindFileNameOptions, basename, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, hasFileExtension, hasFileName, hasFilePath, hasFolderName, parsePath, relative, relativePath, relativeToCurrentDir, renameFile, resolve, resolvePath, resolvePaths } from "./file-path-fns.mjs";
8
8
  import { GlobToRegexOptions, globToRegex } from "./glob-to-regex.mjs";
9
9
  import { isParentPath } from "./is-parent-path.mjs";
10
10
  import { isSystemRoot } from "./is-root-dir.mjs";
11
11
  import { join, joinPaths } from "./join-paths.mjs";
12
- import { 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 } from "./regex.mjs";
12
+ import { ABSOLUTE_PATH_REGEX, DRIVE_LETTER_REGEX, DRIVE_LETTER_START_REGEX, FILE_EXTENSION_REGEX, FULL_FILE_EXTENSION_REGEX, NPM_SCOPED_PACKAGE_REGEX, PACKAGE_PATH_REGEX, ROOT_FOLDER_REGEX, UNC_REGEX } from "./regex.mjs";
13
13
  import { replaceExtension, replacePath } from "./replace.mjs";
14
14
  import { resolveParentPath } from "./resolve-parent-path.mjs";
15
15
  import { formatSlash, slash } from "./slash.mjs";
16
- export { ABSOLUTE_PATH_REGEX, AppendPathOptions, DEFAULT_ASSET_EXTS, DRIVE_LETTER_REGEX, DRIVE_LETTER_START_REGEX, FILE_EXTENSION_REGEX, FindFileNameOptions, GlobToRegexOptions, NPM_SCOPED_PACKAGE_REGEX, PACKAGE_PATH_REGEX, ROOT_FOLDER_REGEX, UNC_REGEX, append, appendExtension, appendPath, basename, commonPath, correctPath, cwd, delimiter, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, formatSlash, globToRegex, hasFileExtension, hasFileName, hasFilePath, hasFolderName, isParentPath, isSystemRoot, join, joinPaths, normalizeString, normalizeWindowsPath, parsePath, posix, relative, relativePath, relativeToCurrentDir, renameFile, replaceExtension, replacePath, resolve, resolveParentPath, resolvePath, resolvePaths, slash, stripStars, toAbsolutePath, toRelativePath, win32, withTrailingSlash, withoutTrailingSlash };
16
+ export { ABSOLUTE_PATH_REGEX, AppendPathOptions, DEFAULT_ASSET_EXTS, DRIVE_LETTER_REGEX, DRIVE_LETTER_START_REGEX, FILE_EXTENSION_REGEX, FULL_FILE_EXTENSION_REGEX, FindFileExtensionOptions, FindFileNameOptions, GlobToRegexOptions, NPM_SCOPED_PACKAGE_REGEX, PACKAGE_PATH_REGEX, ROOT_FOLDER_REGEX, UNC_REGEX, append, appendExtension, appendPath, basename, commonPath, correctPath, cwd, delimiter, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, formatSlash, globToRegex, hasFileExtension, hasFileName, hasFilePath, hasFolderName, isParentPath, isSystemRoot, join, joinPaths, normalizeString, normalizeWindowsPath, parsePath, posix, relative, relativePath, relativeToCurrentDir, renameFile, replaceExtension, replacePath, resolve, resolveParentPath, resolvePath, resolvePaths, slash, stripStars, toAbsolutePath, toRelativePath, win32, withTrailingSlash, withoutTrailingSlash };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { cwd } from "./cwd.mjs";
2
- import { 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 } from "./regex.mjs";
2
+ import { ABSOLUTE_PATH_REGEX, DRIVE_LETTER_REGEX, DRIVE_LETTER_START_REGEX, FILE_EXTENSION_REGEX, FULL_FILE_EXTENSION_REGEX, NPM_SCOPED_PACKAGE_REGEX, PACKAGE_PATH_REGEX, ROOT_FOLDER_REGEX, UNC_REGEX } from "./regex.mjs";
3
3
  import { formatSlash, slash } from "./slash.mjs";
4
4
  import { isParentPath } from "./is-parent-path.mjs";
5
5
  import { join, joinPaths } from "./join-paths.mjs";
@@ -14,4 +14,4 @@ import { isSystemRoot } from "./is-root-dir.mjs";
14
14
  import { replaceExtension, replacePath } from "./replace.mjs";
15
15
  import { resolveParentPath } from "./resolve-parent-path.mjs";
16
16
 
17
- export { ABSOLUTE_PATH_REGEX, DEFAULT_ASSET_EXTS, DRIVE_LETTER_REGEX, DRIVE_LETTER_START_REGEX, FILE_EXTENSION_REGEX, NPM_SCOPED_PACKAGE_REGEX, PACKAGE_PATH_REGEX, ROOT_FOLDER_REGEX, UNC_REGEX, append, appendExtension, appendPath, basename, commonPath, correctPath, cwd, delimiter, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, formatSlash, globToRegex, hasFileExtension, hasFileName, hasFilePath, hasFolderName, isParentPath, isSystemRoot, join, joinPaths, normalizeString, normalizeWindowsPath, parsePath, posix, relative, relativePath, relativeToCurrentDir, renameFile, replaceExtension, replacePath, resolve, resolveParentPath, resolvePath, resolvePaths, slash, stripStars, toAbsolutePath, toRelativePath, win32, withTrailingSlash, withoutTrailingSlash };
17
+ export { ABSOLUTE_PATH_REGEX, DEFAULT_ASSET_EXTS, DRIVE_LETTER_REGEX, DRIVE_LETTER_START_REGEX, FILE_EXTENSION_REGEX, FULL_FILE_EXTENSION_REGEX, NPM_SCOPED_PACKAGE_REGEX, PACKAGE_PATH_REGEX, ROOT_FOLDER_REGEX, UNC_REGEX, append, appendExtension, appendPath, basename, commonPath, correctPath, cwd, delimiter, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, formatSlash, globToRegex, hasFileExtension, hasFileName, hasFilePath, hasFolderName, isParentPath, isSystemRoot, join, joinPaths, normalizeString, normalizeWindowsPath, parsePath, posix, relative, relativePath, relativeToCurrentDir, renameFile, replaceExtension, replacePath, resolve, resolveParentPath, resolvePath, resolvePaths, slash, stripStars, toAbsolutePath, toRelativePath, win32, withTrailingSlash, withoutTrailingSlash };
package/dist/regex.cjs CHANGED
@@ -6,6 +6,7 @@ const UNC_REGEX = /^[/\\]{2}/;
6
6
  const ABSOLUTE_PATH_REGEX = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i;
7
7
  const ROOT_FOLDER_REGEX = /^\/([A-Z]:)?$/i;
8
8
  const FILE_EXTENSION_REGEX = /\.[0-9a-z]+$/i;
9
+ const FULL_FILE_EXTENSION_REGEX = /(\.d)?\.[0-9a-z]+(\.map)?$/i;
9
10
  const PACKAGE_PATH_REGEX = /^@\w+\/.*$/;
10
11
  const NPM_SCOPED_PACKAGE_REGEX = /^(?:@[\w-]+\/)?[\w-]+$/;
11
12
 
@@ -14,6 +15,7 @@ exports.ABSOLUTE_PATH_REGEX = ABSOLUTE_PATH_REGEX;
14
15
  exports.DRIVE_LETTER_REGEX = DRIVE_LETTER_REGEX;
15
16
  exports.DRIVE_LETTER_START_REGEX = DRIVE_LETTER_START_REGEX;
16
17
  exports.FILE_EXTENSION_REGEX = FILE_EXTENSION_REGEX;
18
+ exports.FULL_FILE_EXTENSION_REGEX = FULL_FILE_EXTENSION_REGEX;
17
19
  exports.NPM_SCOPED_PACKAGE_REGEX = NPM_SCOPED_PACKAGE_REGEX;
18
20
  exports.PACKAGE_PATH_REGEX = PACKAGE_PATH_REGEX;
19
21
  exports.ROOT_FOLDER_REGEX = ROOT_FOLDER_REGEX;
package/dist/regex.d.cts CHANGED
@@ -5,8 +5,9 @@ declare const UNC_REGEX: RegExp;
5
5
  declare const ABSOLUTE_PATH_REGEX: RegExp;
6
6
  declare const ROOT_FOLDER_REGEX: RegExp;
7
7
  declare const FILE_EXTENSION_REGEX: RegExp;
8
+ declare const FULL_FILE_EXTENSION_REGEX: RegExp;
8
9
  declare const PACKAGE_PATH_REGEX: RegExp;
9
10
  declare const NPM_SCOPED_PACKAGE_REGEX: RegExp;
10
11
  //#endregion
11
- 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 };
12
+ export { ABSOLUTE_PATH_REGEX, DRIVE_LETTER_REGEX, DRIVE_LETTER_START_REGEX, FILE_EXTENSION_REGEX, FULL_FILE_EXTENSION_REGEX, NPM_SCOPED_PACKAGE_REGEX, PACKAGE_PATH_REGEX, ROOT_FOLDER_REGEX, UNC_REGEX };
12
13
  //# sourceMappingURL=regex.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"regex.d.cts","names":[],"sources":["../src/regex.ts"],"sourcesContent":[],"mappings":";cAkBa,0BAAwB;AAAxB,cACA,kBADuC,EACrB,MADM;AACxB,cAEA,SAFgC,EAEvB,MAFS;AAElB,cAEA,mBAFuB,EAEJ,MAFI;AAEvB,cAGA,iBAHmB,EAGF,MAF2B;AAE5C,cAEA,oBAFiB,EAEG,MAFgB;AAEpC,cAEA,kBAFoB,EAEF,MAFoB;AAEtC,cACA,wBADiC,EACT,MADS"}
1
+ {"version":3,"file":"regex.d.cts","names":[],"sources":["../src/regex.ts"],"sourcesContent":[],"mappings":";cAkBa,0BAAwB;AAAxB,cACA,kBADuC,EACrB,MADM;AACxB,cAEA,SAFgC,EAEvB,MAFS;AAElB,cAEA,mBAFuB,EAEJ,MAFI;AAEvB,cAGA,iBAHmB,EAGF,MAF2B;AAE5C,cAEA,oBAFiB,EAEG,MAFgB;AAEpC,cACA,yBADsC,EACb,MADa;AACtC,cAEA,kBAFyD,EAEvC,MAFO;AAEzB,cACA,wBADiC,EACT,MADS"}
package/dist/regex.d.mts CHANGED
@@ -5,8 +5,9 @@ declare const UNC_REGEX: RegExp;
5
5
  declare const ABSOLUTE_PATH_REGEX: RegExp;
6
6
  declare const ROOT_FOLDER_REGEX: RegExp;
7
7
  declare const FILE_EXTENSION_REGEX: RegExp;
8
+ declare const FULL_FILE_EXTENSION_REGEX: RegExp;
8
9
  declare const PACKAGE_PATH_REGEX: RegExp;
9
10
  declare const NPM_SCOPED_PACKAGE_REGEX: RegExp;
10
11
  //#endregion
11
- 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 };
12
+ export { ABSOLUTE_PATH_REGEX, DRIVE_LETTER_REGEX, DRIVE_LETTER_START_REGEX, FILE_EXTENSION_REGEX, FULL_FILE_EXTENSION_REGEX, NPM_SCOPED_PACKAGE_REGEX, PACKAGE_PATH_REGEX, ROOT_FOLDER_REGEX, UNC_REGEX };
12
13
  //# sourceMappingURL=regex.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"regex.d.mts","names":[],"sources":["../src/regex.ts"],"sourcesContent":[],"mappings":";cAkBa,0BAAwB;AAAxB,cACA,kBADuC,EACrB,MADM;AACxB,cAEA,SAFgC,EAEvB,MAFS;AAElB,cAEA,mBAFuB,EAEJ,MAFI;AAEvB,cAGA,iBAHmB,EAGF,MAF2B;AAE5C,cAEA,oBAFiB,EAEG,MAFgB;AAEpC,cAEA,kBAFoB,EAEF,MAFoB;AAEtC,cACA,wBADiC,EACT,MADS"}
1
+ {"version":3,"file":"regex.d.mts","names":[],"sources":["../src/regex.ts"],"sourcesContent":[],"mappings":";cAkBa,0BAAwB;AAAxB,cACA,kBADuC,EACrB,MADM;AACxB,cAEA,SAFgC,EAEvB,MAFS;AAElB,cAEA,mBAFuB,EAEJ,MAFI;AAEvB,cAGA,iBAHmB,EAGF,MAF2B;AAE5C,cAEA,oBAFiB,EAEG,MAFgB;AAEpC,cACA,yBADsC,EACb,MADa;AACtC,cAEA,kBAFyD,EAEvC,MAFO;AAEzB,cACA,wBADiC,EACT,MADS"}
package/dist/regex.mjs CHANGED
@@ -5,9 +5,10 @@ const UNC_REGEX = /^[/\\]{2}/;
5
5
  const ABSOLUTE_PATH_REGEX = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i;
6
6
  const ROOT_FOLDER_REGEX = /^\/([A-Z]:)?$/i;
7
7
  const FILE_EXTENSION_REGEX = /\.[0-9a-z]+$/i;
8
+ const FULL_FILE_EXTENSION_REGEX = /(\.d)?\.[0-9a-z]+(\.map)?$/i;
8
9
  const PACKAGE_PATH_REGEX = /^@\w+\/.*$/;
9
10
  const NPM_SCOPED_PACKAGE_REGEX = /^(?:@[\w-]+\/)?[\w-]+$/;
10
11
 
11
12
  //#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 };
13
+ export { ABSOLUTE_PATH_REGEX, DRIVE_LETTER_REGEX, DRIVE_LETTER_START_REGEX, FILE_EXTENSION_REGEX, FULL_FILE_EXTENSION_REGEX, NPM_SCOPED_PACKAGE_REGEX, PACKAGE_PATH_REGEX, ROOT_FOLDER_REGEX, UNC_REGEX };
13
14
  //# sourceMappingURL=regex.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"regex.mjs","names":[],"sources":["../src/regex.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nexport const DRIVE_LETTER_START_REGEX = /^[A-Z]:\\//i;\nexport const DRIVE_LETTER_REGEX = /^[A-Z]:$/i;\n\nexport const UNC_REGEX = /^[/\\\\]{2}/;\n\nexport const ABSOLUTE_PATH_REGEX =\n /^[/\\\\](?![/\\\\])|^[/\\\\]{2}(?!\\.)|^~[/\\\\]|^[A-Z]:[/\\\\]/i;\n\nexport const ROOT_FOLDER_REGEX = /^\\/([A-Z]:)?$/i;\n\nexport const FILE_EXTENSION_REGEX = /\\.[0-9a-z]+$/i;\n\nexport const PACKAGE_PATH_REGEX = /^@\\w+\\/.*$/;\nexport const NPM_SCOPED_PACKAGE_REGEX = /^(?:@[\\w-]+\\/)?[\\w-]+$/;\n"],"mappings":";AAkBA,MAAa,2BAA2B;AACxC,MAAa,qBAAqB;AAElC,MAAa,YAAY;AAEzB,MAAa,sBACX;AAEF,MAAa,oBAAoB;AAEjC,MAAa,uBAAuB;AAEpC,MAAa,qBAAqB;AAClC,MAAa,2BAA2B"}
1
+ {"version":3,"file":"regex.mjs","names":[],"sources":["../src/regex.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nexport const DRIVE_LETTER_START_REGEX = /^[A-Z]:\\//i;\nexport const DRIVE_LETTER_REGEX = /^[A-Z]:$/i;\n\nexport const UNC_REGEX = /^[/\\\\]{2}/;\n\nexport const ABSOLUTE_PATH_REGEX =\n /^[/\\\\](?![/\\\\])|^[/\\\\]{2}(?!\\.)|^~[/\\\\]|^[A-Z]:[/\\\\]/i;\n\nexport const ROOT_FOLDER_REGEX = /^\\/([A-Z]:)?$/i;\n\nexport const FILE_EXTENSION_REGEX = /\\.[0-9a-z]+$/i;\nexport const FULL_FILE_EXTENSION_REGEX = /(\\.d)?\\.[0-9a-z]+(\\.map)?$/i;\n\nexport const PACKAGE_PATH_REGEX = /^@\\w+\\/.*$/;\nexport const NPM_SCOPED_PACKAGE_REGEX = /^(?:@[\\w-]+\\/)?[\\w-]+$/;\n"],"mappings":";AAkBA,MAAa,2BAA2B;AACxC,MAAa,qBAAqB;AAElC,MAAa,YAAY;AAEzB,MAAa,sBACX;AAEF,MAAa,oBAAoB;AAEjC,MAAa,uBAAuB;AACpC,MAAa,4BAA4B;AAEzC,MAAa,qBAAqB;AAClC,MAAa,2BAA2B"}
package/dist/replace.cjs CHANGED
@@ -35,8 +35,8 @@ function replacePath(childPath, parentPath = require_cwd.cwd()) {
35
35
  * @param replacement - The value (or an empty string) to replace the current extension with
36
36
  * @returns The path with the replaced extension
37
37
  */
38
- function replaceExtension(path, replacement = "") {
39
- return path.replace(!replacement || replacement.includes(".") ? require_file_path_fns.findFileDotExtensionSafe(path) : require_file_path_fns.findFileExtensionSafe(path), replacement);
38
+ function replaceExtension(path, replacement = "", options) {
39
+ return path.replace(!replacement || replacement.includes(".") ? require_file_path_fns.findFileDotExtensionSafe(path, options) : require_file_path_fns.findFileExtensionSafe(path, options), replacement);
40
40
  }
41
41
 
42
42
  //#endregion
@@ -1,4 +1,7 @@
1
+ import { FindFileExtensionOptions } from "./file-path-fns.cjs";
2
+
1
3
  //#region src/replace.d.ts
4
+
2
5
  /**
3
6
  * Replace the base path from the beginning of the given path.
4
7
  *
@@ -28,7 +31,7 @@ declare function replacePath(childPath: string, parentPath?: string): string;
28
31
  * @param replacement - The value (or an empty string) to replace the current extension with
29
32
  * @returns The path with the replaced extension
30
33
  */
31
- declare function replaceExtension(path: string, replacement?: string): string;
34
+ declare function replaceExtension(path: string, replacement?: string, options?: FindFileExtensionOptions): string;
32
35
  //#endregion
33
36
  export { replaceExtension, replacePath };
34
37
  //# sourceMappingURL=replace.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"replace.d.cts","names":[],"sources":["../src/replace.ts"],"sourcesContent":[],"mappings":";;AAuCA;AAwBA;;;;;;;;;;;iBAxBgB,WAAA;;;;;;;;;;;;;;;;iBAwBA,gBAAA"}
1
+ {"version":3,"file":"replace.d.cts","names":[],"sources":["../src/replace.ts"],"sourcesContent":[],"mappings":";;;;;;AAwCA;AAwBA;;;;;;;;;;iBAxBgB,WAAA;;;;;;;;;;;;;;;;iBAwBA,gBAAA,+CAGJ"}
@@ -1,4 +1,7 @@
1
+ import { FindFileExtensionOptions } from "./file-path-fns.mjs";
2
+
1
3
  //#region src/replace.d.ts
4
+
2
5
  /**
3
6
  * Replace the base path from the beginning of the given path.
4
7
  *
@@ -28,7 +31,7 @@ declare function replacePath(childPath: string, parentPath?: string): string;
28
31
  * @param replacement - The value (or an empty string) to replace the current extension with
29
32
  * @returns The path with the replaced extension
30
33
  */
31
- declare function replaceExtension(path: string, replacement?: string): string;
34
+ declare function replaceExtension(path: string, replacement?: string, options?: FindFileExtensionOptions): string;
32
35
  //#endregion
33
36
  export { replaceExtension, replacePath };
34
37
  //# sourceMappingURL=replace.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"replace.d.mts","names":[],"sources":["../src/replace.ts"],"sourcesContent":[],"mappings":";;AAuCA;AAwBA;;;;;;;;;;;iBAxBgB,WAAA;;;;;;;;;;;;;;;;iBAwBA,gBAAA"}
1
+ {"version":3,"file":"replace.d.mts","names":[],"sources":["../src/replace.ts"],"sourcesContent":[],"mappings":";;;;;;AAwCA;AAwBA;;;;;;;;;;iBAxBgB,WAAA;;;;;;;;;;;;;;;;iBAwBA,gBAAA,+CAGJ"}
package/dist/replace.mjs CHANGED
@@ -35,8 +35,8 @@ function replacePath(childPath, parentPath = cwd()) {
35
35
  * @param replacement - The value (or an empty string) to replace the current extension with
36
36
  * @returns The path with the replaced extension
37
37
  */
38
- function replaceExtension(path, replacement = "") {
39
- return path.replace(!replacement || replacement.includes(".") ? findFileDotExtensionSafe(path) : findFileExtensionSafe(path), replacement);
38
+ function replaceExtension(path, replacement = "", options) {
39
+ return path.replace(!replacement || replacement.includes(".") ? findFileDotExtensionSafe(path, options) : findFileExtensionSafe(path, options), replacement);
40
40
  }
41
41
 
42
42
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"replace.mjs","names":[],"sources":["../src/replace.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { cwd } from \"./cwd\";\nimport {\n findFileDotExtensionSafe,\n findFileExtensionSafe\n} from \"./file-path-fns\";\nimport { isParentPath } from \"./is-parent-path\";\nimport { slash } from \"./slash\";\n\n/**\n * Replace the base path from the beginning of the given path.\n *\n * @example\n * ```ts\n * replacePath(\"/home/user/project/src/index.ts\", \"/home/user/project\");\n * // returns \"src/index.ts\"\n * ```\n *\n * @param childPath - The child path to replace the {@link parentPath} substring from\n * @param parentPath - The parent path to remove from the {@link childPath} parameter\n * @returns The {@link childPath} with the {@link parentPath} path removed\n */\nexport function replacePath(\n childPath: string,\n parentPath: string = cwd()\n): string {\n return isParentPath(childPath, parentPath)\n ? slash(childPath).replace(slash(parentPath), \"\").replace(/^\\//, \"\")\n : childPath;\n}\n\n/**\n * Replace the extension of a given path with the provided value.\n *\n * @example\n * ```ts\n * replaceExtension(\"/home/user/project/src/index.ts\", \".js\");\n * // returns \"/home/user/project/src/index.js\"\n * replaceExtension(\"/home/user/project/src/index.ts\");\n * // returns \"/home/user/project/src/index\"\n * ```\n *\n * @param path - The path that will have its current extension replaced\n * @param replacement - The value (or an empty string) to replace the current extension with\n * @returns The path with the replaced extension\n */\nexport function replaceExtension(path: string, replacement = \"\"): string {\n return path.replace(\n !replacement || replacement.includes(\".\")\n ? findFileDotExtensionSafe(path)\n : findFileExtensionSafe(path),\n replacement\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,YACd,WACA,aAAqB,KAAK,EAClB;AACR,QAAO,aAAa,WAAW,WAAW,GACtC,MAAM,UAAU,CAAC,QAAQ,MAAM,WAAW,EAAE,GAAG,CAAC,QAAQ,OAAO,GAAG,GAClE;;;;;;;;;;;;;;;;;AAkBN,SAAgB,iBAAiB,MAAc,cAAc,IAAY;AACvE,QAAO,KAAK,QACV,CAAC,eAAe,YAAY,SAAS,IAAI,GACrC,yBAAyB,KAAK,GAC9B,sBAAsB,KAAK,EAC/B,YACD"}
1
+ {"version":3,"file":"replace.mjs","names":[],"sources":["../src/replace.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { cwd } from \"./cwd\";\nimport type { FindFileExtensionOptions } from \"./file-path-fns\";\nimport {\n findFileDotExtensionSafe,\n findFileExtensionSafe\n} from \"./file-path-fns\";\nimport { isParentPath } from \"./is-parent-path\";\nimport { slash } from \"./slash\";\n\n/**\n * Replace the base path from the beginning of the given path.\n *\n * @example\n * ```ts\n * replacePath(\"/home/user/project/src/index.ts\", \"/home/user/project\");\n * // returns \"src/index.ts\"\n * ```\n *\n * @param childPath - The child path to replace the {@link parentPath} substring from\n * @param parentPath - The parent path to remove from the {@link childPath} parameter\n * @returns The {@link childPath} with the {@link parentPath} path removed\n */\nexport function replacePath(\n childPath: string,\n parentPath: string = cwd()\n): string {\n return isParentPath(childPath, parentPath)\n ? slash(childPath).replace(slash(parentPath), \"\").replace(/^\\//, \"\")\n : childPath;\n}\n\n/**\n * Replace the extension of a given path with the provided value.\n *\n * @example\n * ```ts\n * replaceExtension(\"/home/user/project/src/index.ts\", \".js\");\n * // returns \"/home/user/project/src/index.js\"\n * replaceExtension(\"/home/user/project/src/index.ts\");\n * // returns \"/home/user/project/src/index\"\n * ```\n *\n * @param path - The path that will have its current extension replaced\n * @param replacement - The value (or an empty string) to replace the current extension with\n * @returns The path with the replaced extension\n */\nexport function replaceExtension(\n path: string,\n replacement = \"\",\n options?: FindFileExtensionOptions\n): string {\n return path.replace(\n !replacement || replacement.includes(\".\")\n ? findFileDotExtensionSafe(path, options)\n : findFileExtensionSafe(path, options),\n replacement\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,YACd,WACA,aAAqB,KAAK,EAClB;AACR,QAAO,aAAa,WAAW,WAAW,GACtC,MAAM,UAAU,CAAC,QAAQ,MAAM,WAAW,EAAE,GAAG,CAAC,QAAQ,OAAO,GAAG,GAClE;;;;;;;;;;;;;;;;;AAkBN,SAAgB,iBACd,MACA,cAAc,IACd,SACQ;AACR,QAAO,KAAK,QACV,CAAC,eAAe,YAAY,SAAS,IAAI,GACrC,yBAAyB,MAAM,QAAQ,GACvC,sBAAsB,MAAM,QAAQ,EACxC,YACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.25.3",
3
+ "version": "0.26.0",
4
4
  "type": "module",
5
5
  "description": "A package containing various utilities that expand the functionality of NodeJs's built-in `path` module",
6
6
  "repository": {
@@ -79,11 +79,11 @@
79
79
  "types": "./dist/index.d.cts",
80
80
  "devDependencies": {
81
81
  "@storm-software/testing-tools": "^1.119.74",
82
- "@stryke/convert": "^0.6.34",
83
- "@stryke/type-checks": "^0.5.19",
84
- "@stryke/types": "^0.10.33",
82
+ "@stryke/convert": "^0.6.35",
83
+ "@stryke/type-checks": "^0.5.20",
84
+ "@stryke/types": "^0.10.34",
85
85
  "tsdown": "^0.17.2"
86
86
  },
87
87
  "publishConfig": { "access": "public" },
88
- "gitHead": "e0cedae14a70843b0d60ab6d8d36ec368d230310"
88
+ "gitHead": "e56e13fe0b09b8e53917efa1aab3877bc96383f7"
89
89
  }