@stryke/fs 0.33.34 → 0.33.36
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 +12 -0
- package/dist/command-exists.cjs +1 -1
- package/dist/command-exists.mjs +1 -1
- package/dist/path/src/file-path-fns.cjs +18 -9
- package/dist/path/src/file-path-fns.mjs +16 -10
- package/dist/path/src/file-path-fns.mjs.map +1 -1
- package/dist/path/src/regex.cjs +2 -0
- package/dist/path/src/regex.mjs +2 -1
- package/dist/path/src/regex.mjs.map +1 -1
- package/dist/path/src/replace.mjs.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog for Stryke - Fs
|
|
4
4
|
|
|
5
|
+
## [0.33.35](https://github.com/storm-software/stryke/releases/tag/fs%400.33.35) (01/16/2026)
|
|
6
|
+
|
|
7
|
+
### Updated Dependencies
|
|
8
|
+
|
|
9
|
+
- Updated **path** to **v0.25.3**
|
|
10
|
+
|
|
11
|
+
## [0.33.34](https://github.com/storm-software/stryke/releases/tag/fs%400.33.34) (01/16/2026)
|
|
12
|
+
|
|
13
|
+
### Updated Dependencies
|
|
14
|
+
|
|
15
|
+
- Updated **path** to **v0.25.2**
|
|
16
|
+
|
|
5
17
|
## [0.33.33](https://github.com/storm-software/stryke/releases/tag/fs%400.33.33) (01/16/2026)
|
|
6
18
|
|
|
7
19
|
### Updated Dependencies
|
package/dist/command-exists.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_path = require("node:path");
|
|
2
3
|
let node_fs = require("node:fs");
|
|
3
4
|
let node_fs_promises = require("node:fs/promises");
|
|
4
5
|
let node_child_process = require("node:child_process");
|
|
5
|
-
let node_path = require("node:path");
|
|
6
6
|
|
|
7
7
|
//#region src/command-exists.ts
|
|
8
8
|
const isUsingWindows = process.platform == "win32";
|
package/dist/command-exists.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { basename, dirname } from "node:path";
|
|
1
2
|
import { accessSync } from "node:fs";
|
|
2
3
|
import { access, constants as constants$1 } from "node:fs/promises";
|
|
3
4
|
import { exec, execSync } from "node:child_process";
|
|
4
|
-
import { basename, dirname } from "node:path";
|
|
5
5
|
|
|
6
6
|
//#region src/command-exists.ts
|
|
7
7
|
const isUsingWindows = process.platform == "win32";
|
|
@@ -1,9 +1,12 @@
|
|
|
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');
|
|
4
5
|
const require_correct_path = require('./correct-path.cjs');
|
|
5
6
|
const require_is_set_string = require('../../type-checks/src/is-set-string.cjs');
|
|
6
7
|
const require_base = require('../../types/src/base.cjs');
|
|
8
|
+
let node_path = require("node:path");
|
|
9
|
+
node_path = require_rolldown_runtime.__toESM(node_path);
|
|
7
10
|
|
|
8
11
|
//#region ../path/src/file-path-fns.ts
|
|
9
12
|
/**
|
|
@@ -23,14 +26,14 @@ function findFileName(filePath, options = {}) {
|
|
|
23
26
|
const { requireExtension = false, withExtension = true } = options;
|
|
24
27
|
const result = require_correct_path.normalizeWindowsPath(filePath)?.split(filePath?.includes("\\") ? "\\" : "/")?.pop() ?? "";
|
|
25
28
|
if (requireExtension === true && !result.includes(".")) return require_base.EMPTY_STRING;
|
|
26
|
-
if (withExtension === false && result.includes(".")) return result.replace(`.${findFileExtension(result) ?? ""}`, "") || require_base.EMPTY_STRING;
|
|
29
|
+
if (withExtension === false && result.includes(".")) return result.replace(`.${findFileExtension(result, options) ?? ""}`, "") || require_base.EMPTY_STRING;
|
|
27
30
|
return result;
|
|
28
31
|
}
|
|
29
32
|
/**
|
|
30
33
|
* Find the full file path's directories from a file path.
|
|
31
34
|
*
|
|
32
35
|
* @remarks
|
|
33
|
-
* The functionality of this method is similar to the {@link
|
|
36
|
+
* The functionality of this method is similar to the {@link _path.dirname} function in Node's path module.
|
|
34
37
|
*
|
|
35
38
|
* @example
|
|
36
39
|
* ```ts
|
|
@@ -54,7 +57,7 @@ function findFilePath(filePath, options = {}) {
|
|
|
54
57
|
* Find the top most folder containing the file from a file path.
|
|
55
58
|
*
|
|
56
59
|
* @remarks
|
|
57
|
-
* The functionality of this method is similar to the {@link
|
|
60
|
+
* The functionality of this method is similar to the {@link _path.basename} function in Node's path module.
|
|
58
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.
|
|
59
62
|
*
|
|
60
63
|
* @example
|
|
@@ -88,26 +91,32 @@ function findFolderName(filePath, options) {
|
|
|
88
91
|
*
|
|
89
92
|
* @example
|
|
90
93
|
* ```ts
|
|
91
|
-
* findFileExtension("C:\\Users\\user\\Documents\\file.config.ts");
|
|
92
|
-
* // 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
|
|
93
100
|
* ```
|
|
94
101
|
*
|
|
95
102
|
* @param filePath - The file path to process
|
|
103
|
+
* @param options - Options to control the file name extraction
|
|
96
104
|
* @returns The file extension or undefined if no extension is found
|
|
97
105
|
*/
|
|
98
|
-
function findFileExtension(filePath) {
|
|
106
|
+
function findFileExtension(filePath, options) {
|
|
99
107
|
if (filePath.endsWith(".") || filePath.endsWith("/")) return;
|
|
100
|
-
const match = require_regex.FILE_EXTENSION_REGEX.exec(require_correct_path.normalizeWindowsPath(filePath));
|
|
108
|
+
const match = (options?.fullExtension ? require_regex.FULL_FILE_EXTENSION_REGEX : require_regex.FILE_EXTENSION_REGEX).exec(require_correct_path.normalizeWindowsPath(filePath));
|
|
101
109
|
return match && match.length > 0 && require_is_set_string.isSetString(match[0]) ? match[0].replace(".", "") : void 0;
|
|
102
110
|
}
|
|
103
111
|
/**
|
|
104
112
|
* Check if a file path has a file extension.
|
|
105
113
|
*
|
|
106
114
|
* @param filePath - The file path to process
|
|
115
|
+
* @param options - Options to control the file name extraction
|
|
107
116
|
* @returns An indicator specifying if the file path has a file extension
|
|
108
117
|
*/
|
|
109
|
-
function hasFileExtension(filePath) {
|
|
110
|
-
return Boolean(findFileExtension(filePath));
|
|
118
|
+
function hasFileExtension(filePath, options) {
|
|
119
|
+
return Boolean(findFileExtension(filePath, options));
|
|
111
120
|
}
|
|
112
121
|
function resolve(...paths) {
|
|
113
122
|
paths = paths.map((argument) => require_correct_path.normalizeWindowsPath(argument));
|
|
@@ -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 } from "./is-type.mjs";
|
|
4
4
|
import { normalizeString, normalizeWindowsPath } from "./correct-path.mjs";
|
|
5
5
|
import { isSetString } from "../../type-checks/src/is-set-string.mjs";
|
|
@@ -23,14 +23,14 @@ function findFileName(filePath, options = {}) {
|
|
|
23
23
|
const { requireExtension = false, withExtension = true } = options;
|
|
24
24
|
const result = normalizeWindowsPath(filePath)?.split(filePath?.includes("\\") ? "\\" : "/")?.pop() ?? "";
|
|
25
25
|
if (requireExtension === true && !result.includes(".")) return EMPTY_STRING;
|
|
26
|
-
if (withExtension === false && result.includes(".")) return result.replace(`.${findFileExtension(result) ?? ""}`, "") || EMPTY_STRING;
|
|
26
|
+
if (withExtension === false && result.includes(".")) return result.replace(`.${findFileExtension(result, options) ?? ""}`, "") || EMPTY_STRING;
|
|
27
27
|
return result;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Find the full file path's directories from a file path.
|
|
31
31
|
*
|
|
32
32
|
* @remarks
|
|
33
|
-
* The functionality of this method is similar to the {@link
|
|
33
|
+
* The functionality of this method is similar to the {@link _path.dirname} function in Node's path module.
|
|
34
34
|
*
|
|
35
35
|
* @example
|
|
36
36
|
* ```ts
|
|
@@ -54,7 +54,7 @@ function findFilePath(filePath, options = {}) {
|
|
|
54
54
|
* Find the top most folder containing the file from a file path.
|
|
55
55
|
*
|
|
56
56
|
* @remarks
|
|
57
|
-
* The functionality of this method is similar to the {@link
|
|
57
|
+
* The functionality of this method is similar to the {@link _path.basename} function in Node's path module.
|
|
58
58
|
* If you're looking for the full path of the folder (for example: `C:\\Users\\user\\Documents` instead of just `Documents`) containing the file, use {@link findFilePath} instead.
|
|
59
59
|
*
|
|
60
60
|
* @example
|
|
@@ -88,26 +88,32 @@ function findFolderName(filePath, options) {
|
|
|
88
88
|
*
|
|
89
89
|
* @example
|
|
90
90
|
* ```ts
|
|
91
|
-
* findFileExtension("C:\\Users\\user\\Documents\\file.config.ts");
|
|
92
|
-
* // Returns "ts"
|
|
91
|
+
* findFileExtension("C:\\Users\\user\\Documents\\file.config.ts"); // Returns "ts"
|
|
92
|
+
* findFileExtension("C:\\Users\\user\\Documents\\file.d.ts"); // Returns "ts"
|
|
93
|
+
* findFileExtension("C:\\Users\\user\\Documents\\file.d.ts", { fullExtension: true }); // Returns "d.ts"
|
|
94
|
+
* findFileExtension("C:\\Users\\user\\Documents\\file.ts.map"); // Returns "ts"
|
|
95
|
+
* findFileExtension("C:\\Users\\user\\Documents\\file.ts.map", { fullExtension: true }); // Returns "ts.map"
|
|
96
|
+
* findFileExtension("C:\\Users\\user\\Documents\\file"); // Returns undefined
|
|
93
97
|
* ```
|
|
94
98
|
*
|
|
95
99
|
* @param filePath - The file path to process
|
|
100
|
+
* @param options - Options to control the file name extraction
|
|
96
101
|
* @returns The file extension or undefined if no extension is found
|
|
97
102
|
*/
|
|
98
|
-
function findFileExtension(filePath) {
|
|
103
|
+
function findFileExtension(filePath, options) {
|
|
99
104
|
if (filePath.endsWith(".") || filePath.endsWith("/")) return;
|
|
100
|
-
const match = FILE_EXTENSION_REGEX.exec(normalizeWindowsPath(filePath));
|
|
105
|
+
const match = (options?.fullExtension ? FULL_FILE_EXTENSION_REGEX : FILE_EXTENSION_REGEX).exec(normalizeWindowsPath(filePath));
|
|
101
106
|
return match && match.length > 0 && isSetString(match[0]) ? match[0].replace(".", "") : void 0;
|
|
102
107
|
}
|
|
103
108
|
/**
|
|
104
109
|
* Check if a file path has a file extension.
|
|
105
110
|
*
|
|
106
111
|
* @param filePath - The file path to process
|
|
112
|
+
* @param options - Options to control the file name extraction
|
|
107
113
|
* @returns An indicator specifying if the file path has a file extension
|
|
108
114
|
*/
|
|
109
|
-
function hasFileExtension(filePath) {
|
|
110
|
-
return Boolean(findFileExtension(filePath));
|
|
115
|
+
function hasFileExtension(filePath, options) {
|
|
116
|
+
return Boolean(findFileExtension(filePath, options));
|
|
111
117
|
}
|
|
112
118
|
function resolve(...paths) {
|
|
113
119
|
paths = paths.map((argument) => normalizeWindowsPath(argument));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-path-fns.mjs","names":["currentDir"],"sources":["../../../../path/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":"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"}
|
|
1
|
+
{"version":3,"file":"file-path-fns.mjs","names":["currentDir"],"sources":["../../../../path/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(\".\") ? newFileName : newFileName + file.ext\n );\n}\n"],"mappings":"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"}
|
package/dist/path/src/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 NPM_SCOPED_PACKAGE_REGEX = /^(?:@[\w-]+\/)?[\w-]+$/;
|
|
10
11
|
|
|
11
12
|
//#endregion
|
|
@@ -13,6 +14,7 @@ exports.ABSOLUTE_PATH_REGEX = ABSOLUTE_PATH_REGEX;
|
|
|
13
14
|
exports.DRIVE_LETTER_REGEX = DRIVE_LETTER_REGEX;
|
|
14
15
|
exports.DRIVE_LETTER_START_REGEX = DRIVE_LETTER_START_REGEX;
|
|
15
16
|
exports.FILE_EXTENSION_REGEX = FILE_EXTENSION_REGEX;
|
|
17
|
+
exports.FULL_FILE_EXTENSION_REGEX = FULL_FILE_EXTENSION_REGEX;
|
|
16
18
|
exports.NPM_SCOPED_PACKAGE_REGEX = NPM_SCOPED_PACKAGE_REGEX;
|
|
17
19
|
exports.ROOT_FOLDER_REGEX = ROOT_FOLDER_REGEX;
|
|
18
20
|
exports.UNC_REGEX = UNC_REGEX;
|
package/dist/path/src/regex.mjs
CHANGED
|
@@ -5,8 +5,9 @@ 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 NPM_SCOPED_PACKAGE_REGEX = /^(?:@[\w-]+\/)?[\w-]+$/;
|
|
9
10
|
|
|
10
11
|
//#endregion
|
|
11
|
-
export { ABSOLUTE_PATH_REGEX, DRIVE_LETTER_REGEX, DRIVE_LETTER_START_REGEX, FILE_EXTENSION_REGEX, NPM_SCOPED_PACKAGE_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, ROOT_FOLDER_REGEX, UNC_REGEX };
|
|
12
13
|
//# sourceMappingURL=regex.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regex.mjs","names":[],"sources":["../../../../path/src/regex.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nexport const DRIVE_LETTER_START_REGEX = /^[A-Z]:\\//i;\nexport const DRIVE_LETTER_REGEX = /^[A-Z]:$/i;\n\nexport const UNC_REGEX = /^[/\\\\]{2}/;\n\nexport const ABSOLUTE_PATH_REGEX =\n /^[/\\\\](?![/\\\\])|^[/\\\\]{2}(?!\\.)|^~[/\\\\]|^[A-Z]:[/\\\\]/i;\n\nexport const ROOT_FOLDER_REGEX = /^\\/([A-Z]:)?$/i;\n\nexport const FILE_EXTENSION_REGEX = /\\.[0-9a-z]+$/i;\n\nexport const PACKAGE_PATH_REGEX = /^@\\w+\\/.*$/;\nexport const NPM_SCOPED_PACKAGE_REGEX = /^(?:@[\\w-]+\\/)?[\\w-]+$/;\n"],"mappings":";AAkBA,MAAa,2BAA2B;AACxC,MAAa,qBAAqB;AAElC,MAAa,YAAY;AAEzB,MAAa,sBACX;AAEF,MAAa,oBAAoB;AAEjC,MAAa,uBAAuB;
|
|
1
|
+
{"version":3,"file":"regex.mjs","names":[],"sources":["../../../../path/src/regex.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nexport const DRIVE_LETTER_START_REGEX = /^[A-Z]:\\//i;\nexport const DRIVE_LETTER_REGEX = /^[A-Z]:$/i;\n\nexport const UNC_REGEX = /^[/\\\\]{2}/;\n\nexport const ABSOLUTE_PATH_REGEX =\n /^[/\\\\](?![/\\\\])|^[/\\\\]{2}(?!\\.)|^~[/\\\\]|^[A-Z]:[/\\\\]/i;\n\nexport const ROOT_FOLDER_REGEX = /^\\/([A-Z]:)?$/i;\n\nexport const FILE_EXTENSION_REGEX = /\\.[0-9a-z]+$/i;\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;AAGzC,MAAa,2BAA2B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replace.mjs","names":[],"sources":["../../../../path/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
|
|
1
|
+
{"version":3,"file":"replace.mjs","names":[],"sources":["../../../../path/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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/fs",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.36",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.",
|
|
6
6
|
"repository": {
|
|
@@ -109,10 +109,10 @@
|
|
|
109
109
|
"@antfu/install-pkg": "^1.1.0",
|
|
110
110
|
"@ltd/j-toml": "^1.38.0",
|
|
111
111
|
"@storm-software/config-tools": "^1.188.80",
|
|
112
|
-
"@stryke/convert": "^0.6.
|
|
113
|
-
"@stryke/helpers": "^0.9.
|
|
114
|
-
"@stryke/path": "^0.
|
|
115
|
-
"@stryke/string-format": "^0.13.
|
|
112
|
+
"@stryke/convert": "^0.6.35",
|
|
113
|
+
"@stryke/helpers": "^0.9.37",
|
|
114
|
+
"@stryke/path": "^0.26.0",
|
|
115
|
+
"@stryke/string-format": "^0.13.4",
|
|
116
116
|
"chalk": "^5.6.2",
|
|
117
117
|
"defu": "^6.1.4",
|
|
118
118
|
"glob": "^11.1.0",
|
|
@@ -129,5 +129,5 @@
|
|
|
129
129
|
"tsdown": "^0.17.2"
|
|
130
130
|
},
|
|
131
131
|
"publishConfig": { "access": "public" },
|
|
132
|
-
"gitHead": "
|
|
132
|
+
"gitHead": "e56e13fe0b09b8e53917efa1aab3877bc96383f7"
|
|
133
133
|
}
|