@stryke/path 0.25.0 → 0.25.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/append.cjs +59 -1
  3. package/dist/append.mjs +57 -1
  4. package/dist/append.mjs.map +1 -1
  5. package/dist/asset-extensions.cjs +40 -1
  6. package/dist/asset-extensions.mjs +39 -1
  7. package/dist/asset-extensions.mjs.map +1 -1
  8. package/dist/common.cjs +34 -1
  9. package/dist/common.mjs +34 -1
  10. package/dist/common.mjs.map +1 -1
  11. package/dist/correct-path.cjs +176 -1
  12. package/dist/correct-path.mjs +169 -1
  13. package/dist/correct-path.mjs.map +1 -1
  14. package/dist/cwd.cjs +17 -1
  15. package/dist/cwd.mjs +16 -1
  16. package/dist/cwd.mjs.map +1 -1
  17. package/dist/delimiter.cjs +27 -1
  18. package/dist/delimiter.mjs +24 -1
  19. package/dist/delimiter.mjs.map +1 -1
  20. package/dist/file-path-fns.cjs +332 -1
  21. package/dist/file-path-fns.mjs +311 -1
  22. package/dist/file-path-fns.mjs.map +1 -1
  23. package/dist/find.cjs +24 -1
  24. package/dist/find.mjs +3 -1
  25. package/dist/glob-to-regex.cjs +92 -1
  26. package/dist/glob-to-regex.mjs +92 -1
  27. package/dist/glob-to-regex.mjs.map +1 -1
  28. package/dist/index.cjs +73 -1
  29. package/dist/index.mjs +17 -1
  30. package/dist/is-parent-path.cjs +32 -1
  31. package/dist/is-parent-path.mjs +32 -1
  32. package/dist/is-parent-path.mjs.map +1 -1
  33. package/dist/is-root-dir.cjs +14 -1
  34. package/dist/is-root-dir.mjs +13 -1
  35. package/dist/is-root-dir.mjs.map +1 -1
  36. package/dist/is-type.cjs +92 -1
  37. package/dist/is-type.mjs +87 -1
  38. package/dist/is-type.mjs.map +1 -1
  39. package/dist/join-paths.cjs +108 -1
  40. package/dist/join-paths.mjs +107 -1
  41. package/dist/join-paths.mjs.map +1 -1
  42. package/dist/join.cjs +4 -1
  43. package/dist/join.mjs +3 -1
  44. package/dist/normalize.cjs +10 -1
  45. package/dist/normalize.mjs +3 -1
  46. package/dist/regex.cjs +20 -1
  47. package/dist/regex.mjs +12 -1
  48. package/dist/regex.mjs.map +1 -1
  49. package/dist/replace.cjs +44 -1
  50. package/dist/replace.mjs +43 -1
  51. package/dist/replace.mjs.map +1 -1
  52. package/dist/resolve-parent-path.cjs +18 -1
  53. package/dist/resolve-parent-path.mjs +18 -1
  54. package/dist/resolve-parent-path.mjs.map +1 -1
  55. package/dist/slash.cjs +27 -1
  56. package/dist/slash.mjs +26 -1
  57. package/dist/slash.mjs.map +1 -1
  58. package/dist/type-checks/src/is-empty.cjs +20 -1
  59. package/dist/type-checks/src/is-empty.mjs +20 -1
  60. package/dist/type-checks/src/is-empty.mjs.map +1 -1
  61. package/dist/type-checks/src/is-null.cjs +12 -1
  62. package/dist/type-checks/src/is-null.mjs +11 -1
  63. package/dist/type-checks/src/is-null.mjs.map +1 -1
  64. package/dist/type-checks/src/is-set-string.cjs +20 -1
  65. package/dist/type-checks/src/is-set-string.mjs +20 -1
  66. package/dist/type-checks/src/is-set-string.mjs.map +1 -1
  67. package/dist/type-checks/src/is-set.cjs +19 -1
  68. package/dist/type-checks/src/is-set.mjs +19 -1
  69. package/dist/type-checks/src/is-set.mjs.map +1 -1
  70. package/dist/type-checks/src/is-string.cjs +12 -1
  71. package/dist/type-checks/src/is-string.mjs +11 -1
  72. package/dist/type-checks/src/is-string.mjs.map +1 -1
  73. package/dist/type-checks/src/is-undefined.cjs +8 -1
  74. package/dist/type-checks/src/is-undefined.mjs +7 -1
  75. package/dist/type-checks/src/is-undefined.mjs.map +1 -1
  76. package/dist/types/src/base.cjs +6 -1
  77. package/dist/types/src/base.mjs +5 -1
  78. package/dist/types/src/base.mjs.map +1 -1
  79. package/package.json +5 -5
@@ -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":"2ZAuDA,SAAgB,EACd,EACA,EAA+B,EAAE,CACzB,CACR,GAAM,CAAE,mBAAmB,GAAO,gBAAgB,IAAS,E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,MAAM,EAAG,EAAK,OAAS,EAAI,OAAO,CAC9C,CAUH,SAAgB,EAAW,EAAkB,EAA6B,CACxE,IAAM,EAAO,EAAU,EAAS,CAEhC,OAAO,EACL,EAAK,IACL,EAAY,SAAS,IAAI,CAAG,EAAc,EAAc,EAAK,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 { 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,kBAAkB,SAAS,OAAO,SAAS,IAAI,CACjD,QACE,OAAO,QAAQ,IAAI,kBAAkB,OAAO,IAAI,MAAM,GAAG,IAAI;AAIjE,QAAO;;;;;;;;;;;;;;;;;;AAmBT,SAAgB,aACd,UACA,UAA+B,EAAE,EACzB;CACR,MAAM,iBAAiB,qBAAqB,SAAS;CAErD,MAAM,SAAS,eAAe,QAC5B,aAAa,gBAAgB;EAAE,kBAAkB;EAAO,GAAG;EAAS,CAAC,EACrE,GACD;AAED,QAAO,WAAW,MAAM,SAAS,OAAO,QAAQ,OAAO,GAAG;;AAG5D,MAAa,UAAU;;;;;;;;;;;;;;;;AAiBvB,SAAgB,eACd,UACA,SACQ;CACR,MAAM,WAAW,aAAa,UAAU,QAAQ,CAAC,MAAM,IAAI;CAE3D,IAAI,cAAc;AAClB,MAAK,IAAI,IAAI,SAAS,SAAS,GAAG,KAAK,GAAG,KAAK;EAC7C,MAAM,MAAM,SAAS;AACrB,MAAI,KAAK;AACP,iBAAc;AACd;;;AAWJ,QAAO,eAAe;;AAGxB,MAAa,WAAW;;;;;;;;;;;;;;;;;;;AAoBxB,SAAgB,kBAAkB,UAAsC;AACtE,KAAI,SAAS,SAAS,IAAI,IAAI,SAAS,SAAS,IAAI,CAClD;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,eAAe,OAAO;AAC3E,QAAO,SACL,iBAAiB,OAAO,KAAK,QAAQ,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;CAEtC,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,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"}
package/dist/find.cjs CHANGED
@@ -1 +1,24 @@
1
- const e=require(`./file-path-fns.cjs`);exports.basename=e.basename,exports.dirname=e.dirname,exports.extname=e.extname,exports.findFileDotExtension=e.findFileDotExtension,exports.findFileDotExtensionSafe=e.findFileDotExtensionSafe,exports.findFileExtension=e.findFileExtension,exports.findFileExtensionSafe=e.findFileExtensionSafe,exports.findFileName=e.findFileName,exports.findFilePath=e.findFilePath,exports.findFolderName=e.findFolderName,exports.hasFileExtension=e.hasFileExtension,exports.hasFileName=e.hasFileName,exports.hasFilePath=e.hasFilePath,exports.hasFolderName=e.hasFolderName,exports.parsePath=e.parsePath,exports.relative=e.relative,exports.relativePath=e.relativePath,exports.relativeToCurrentDir=e.relativeToCurrentDir,exports.renameFile=e.renameFile,exports.resolve=e.resolve,exports.resolvePath=e.resolvePath,exports.resolvePaths=e.resolvePaths;
1
+ const require_file_path_fns = require('./file-path-fns.cjs');
2
+
3
+ exports.basename = require_file_path_fns.basename;
4
+ exports.dirname = require_file_path_fns.dirname;
5
+ exports.extname = require_file_path_fns.extname;
6
+ exports.findFileDotExtension = require_file_path_fns.findFileDotExtension;
7
+ exports.findFileDotExtensionSafe = require_file_path_fns.findFileDotExtensionSafe;
8
+ exports.findFileExtension = require_file_path_fns.findFileExtension;
9
+ exports.findFileExtensionSafe = require_file_path_fns.findFileExtensionSafe;
10
+ exports.findFileName = require_file_path_fns.findFileName;
11
+ exports.findFilePath = require_file_path_fns.findFilePath;
12
+ exports.findFolderName = require_file_path_fns.findFolderName;
13
+ exports.hasFileExtension = require_file_path_fns.hasFileExtension;
14
+ exports.hasFileName = require_file_path_fns.hasFileName;
15
+ exports.hasFilePath = require_file_path_fns.hasFilePath;
16
+ exports.hasFolderName = require_file_path_fns.hasFolderName;
17
+ exports.parsePath = require_file_path_fns.parsePath;
18
+ exports.relative = require_file_path_fns.relative;
19
+ exports.relativePath = require_file_path_fns.relativePath;
20
+ exports.relativeToCurrentDir = require_file_path_fns.relativeToCurrentDir;
21
+ exports.renameFile = require_file_path_fns.renameFile;
22
+ exports.resolve = require_file_path_fns.resolve;
23
+ exports.resolvePath = require_file_path_fns.resolvePath;
24
+ exports.resolvePaths = require_file_path_fns.resolvePaths;
package/dist/find.mjs CHANGED
@@ -1 +1,3 @@
1
- import{basename as e,dirname as t,extname as n,findFileDotExtension as r,findFileDotExtensionSafe as i,findFileExtension as a,findFileExtensionSafe as o,findFileName as s,findFilePath as c,findFolderName as l,hasFileExtension as u,hasFileName as d,hasFilePath as f,hasFolderName as p,parsePath as m,relative as h,relativePath as g,relativeToCurrentDir as _,renameFile as v,resolve as y,resolvePath as b,resolvePaths as x}from"./file-path-fns.mjs";export{e as basename,t as dirname,n as extname,r as findFileDotExtension,i as findFileDotExtensionSafe,a as findFileExtension,o as findFileExtensionSafe,s as findFileName,c as findFilePath,l as findFolderName,u as hasFileExtension,d as hasFileName,f as hasFilePath,p as hasFolderName,m as parsePath,h as relative,g as relativePath,_ as relativeToCurrentDir,v as renameFile,y as resolve,b as resolvePath,x as resolvePaths};
1
+ import { 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
+
3
+ export { basename, dirname, extname, findFileDotExtension, findFileDotExtensionSafe, findFileExtension, findFileExtensionSafe, findFileName, findFilePath, findFolderName, hasFileExtension, hasFileName, hasFilePath, hasFolderName, parsePath, relative, relativePath, relativeToCurrentDir, renameFile, resolve, resolvePath, resolvePaths };
@@ -1 +1,92 @@
1
- const e=require(`./type-checks/src/is-set-string.cjs`);function t(t,n={}){if(!e.isSetString(t))throw TypeError(`A string was not provided as a glob pattern.`);let r=String(t),i=``,a=!1,o;for(let e=0,t=r.length;e<t;e++){o=r[e];let t=r[e-1],s=r[e+1],c=1;switch(o){case`/`:case`$`:case`^`:case`+`:case`.`:case`(`:case`)`:case`=`:case`!`:case`|`:i+=`\\${o}`;break;case`?`:n.extended!==!1&&(i+=`.`);break;case`[`:case`]`:n.extended!==!1&&(i+=o);break;case`{`:n.extended!==!1&&(a=!0,i+=`(`);break;case`}`:n.extended!==!1&&(a=!1,i+=`)`);break;case`,`:a&&(i+=`|`),i+=`\\${o}`;break;case`*`:for(c=1;r[e+1]===`*`;)c++,e++;n.globstar===!1?i+=`.*`:c>1&&(t===`/`||t===void 0)&&(s===`/`||s===void 0)?(i+=`((?:[^/]*(?:/|$))*)?`,e++):i+=`([^/]*)`;break;case void 0:default:i+=o}}let s=e.isSetString(n.flags)?n.flags:``;return(!s||!~s.indexOf(`g`))&&(i=`^${i}$`),new RegExp(i,s)}exports.globToRegex=t;
1
+ const require_is_set_string = require('./type-checks/src/is-set-string.cjs');
2
+
3
+ //#region src/glob-to-regex.ts
4
+ /**
5
+ * Converts a glob pattern to a regular expression.
6
+ *
7
+ * @see https://mergify.com/blog/origin-and-evolution-of-the-globstar
8
+ * @see https://en.wikipedia.org/wiki/Glob_(programming)
9
+ *
10
+ * @remarks
11
+ * This function converts a glob pattern (like `*.{js,ts}` or `**\/src/**`) into a regular expression
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { globToRegex } from "@stryke/path/glob-to-regex";
16
+ *
17
+ * const test1 = globToRegex("*.{js,ts}");
18
+ * console.log(test1); // Output: /^([^/]*)\.(js|ts)$/
19
+ *
20
+ * const test2 = globToRegex("**\/src/**");
21
+ * console.log(test2); // Output: /^((?:[^/]*(?:\/|$))*)?\/src\/((?:[^/]*(?:\/|$))*)?$/
22
+ * ```
23
+ *
24
+ * @param glob - The glob pattern to convert.
25
+ * @param options - The options for the conversion.
26
+ * @returns The converted regular expression.
27
+ */
28
+ function globToRegex(glob, options = {}) {
29
+ if (!require_is_set_string.isSetString(glob)) throw new TypeError("A string was not provided as a glob pattern.");
30
+ let regex = "";
31
+ let inGroup = false;
32
+ for (let i = 0; i < glob.length; i++) {
33
+ let starCount = 1;
34
+ switch (glob[i]) {
35
+ case "/":
36
+ case "$":
37
+ case "^":
38
+ case "+":
39
+ case ".":
40
+ case "(":
41
+ case ")":
42
+ case "=":
43
+ case "!":
44
+ case "|":
45
+ regex += `\\${glob[i]}`;
46
+ break;
47
+ case "?":
48
+ if (options.extended !== false) regex += ".";
49
+ break;
50
+ case "[":
51
+ case "]":
52
+ if (options.extended !== false) regex += glob[i];
53
+ break;
54
+ case "{":
55
+ if (options.extended !== false) {
56
+ inGroup = true;
57
+ regex += "(";
58
+ }
59
+ break;
60
+ case "}":
61
+ if (options.extended !== false) {
62
+ inGroup = false;
63
+ regex += ")";
64
+ }
65
+ break;
66
+ case ",":
67
+ if (inGroup) regex += "|";
68
+ regex += `\\${glob[i]}`;
69
+ break;
70
+ case "*":
71
+ starCount = 1;
72
+ while (glob[i + 1] === "*") {
73
+ starCount++;
74
+ i++;
75
+ }
76
+ if (options.globstar === false) regex += ".*";
77
+ else if (starCount > 1 && (glob[i - 1] === "/" || glob[i - 1] === void 0) && (glob[i + 1] === "/" || glob[i + 1] === void 0)) {
78
+ regex += "((?:[^/]*(?:/|$))*)";
79
+ i++;
80
+ } else regex += "([^/]*)";
81
+ break;
82
+ case void 0:
83
+ default: regex += glob[i];
84
+ }
85
+ }
86
+ const flags = require_is_set_string.isSetString(options.flags) ? options.flags : "";
87
+ if (!flags || !~flags.indexOf("g")) regex = `^${regex}$`;
88
+ return new RegExp(regex, flags);
89
+ }
90
+
91
+ //#endregion
92
+ exports.globToRegex = globToRegex;
@@ -1,2 +1,93 @@
1
- import{isSetString as e}from"./type-checks/src/is-set-string.mjs";function t(t,n={}){if(!e(t))throw TypeError(`A string was not provided as a glob pattern.`);let r=String(t),i=``,a=!1,o;for(let e=0,t=r.length;e<t;e++){o=r[e];let t=r[e-1],s=r[e+1],c=1;switch(o){case`/`:case`$`:case`^`:case`+`:case`.`:case`(`:case`)`:case`=`:case`!`:case`|`:i+=`\\${o}`;break;case`?`:n.extended!==!1&&(i+=`.`);break;case`[`:case`]`:n.extended!==!1&&(i+=o);break;case`{`:n.extended!==!1&&(a=!0,i+=`(`);break;case`}`:n.extended!==!1&&(a=!1,i+=`)`);break;case`,`:a&&(i+=`|`),i+=`\\${o}`;break;case`*`:for(c=1;r[e+1]===`*`;)c++,e++;n.globstar===!1?i+=`.*`:c>1&&(t===`/`||t===void 0)&&(s===`/`||s===void 0)?(i+=`((?:[^/]*(?:/|$))*)?`,e++):i+=`([^/]*)`;break;case void 0:default:i+=o}}let s=e(n.flags)?n.flags:``;return(!s||!~s.indexOf(`g`))&&(i=`^${i}$`),new RegExp(i,s)}export{t as globToRegex};
1
+ import { isSetString } from "./type-checks/src/is-set-string.mjs";
2
+
3
+ //#region src/glob-to-regex.ts
4
+ /**
5
+ * Converts a glob pattern to a regular expression.
6
+ *
7
+ * @see https://mergify.com/blog/origin-and-evolution-of-the-globstar
8
+ * @see https://en.wikipedia.org/wiki/Glob_(programming)
9
+ *
10
+ * @remarks
11
+ * This function converts a glob pattern (like `*.{js,ts}` or `**\/src/**`) into a regular expression
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { globToRegex } from "@stryke/path/glob-to-regex";
16
+ *
17
+ * const test1 = globToRegex("*.{js,ts}");
18
+ * console.log(test1); // Output: /^([^/]*)\.(js|ts)$/
19
+ *
20
+ * const test2 = globToRegex("**\/src/**");
21
+ * console.log(test2); // Output: /^((?:[^/]*(?:\/|$))*)?\/src\/((?:[^/]*(?:\/|$))*)?$/
22
+ * ```
23
+ *
24
+ * @param glob - The glob pattern to convert.
25
+ * @param options - The options for the conversion.
26
+ * @returns The converted regular expression.
27
+ */
28
+ function globToRegex(glob, options = {}) {
29
+ if (!isSetString(glob)) throw new TypeError("A string was not provided as a glob pattern.");
30
+ let regex = "";
31
+ let inGroup = false;
32
+ for (let i = 0; i < glob.length; i++) {
33
+ let starCount = 1;
34
+ switch (glob[i]) {
35
+ case "/":
36
+ case "$":
37
+ case "^":
38
+ case "+":
39
+ case ".":
40
+ case "(":
41
+ case ")":
42
+ case "=":
43
+ case "!":
44
+ case "|":
45
+ regex += `\\${glob[i]}`;
46
+ break;
47
+ case "?":
48
+ if (options.extended !== false) regex += ".";
49
+ break;
50
+ case "[":
51
+ case "]":
52
+ if (options.extended !== false) regex += glob[i];
53
+ break;
54
+ case "{":
55
+ if (options.extended !== false) {
56
+ inGroup = true;
57
+ regex += "(";
58
+ }
59
+ break;
60
+ case "}":
61
+ if (options.extended !== false) {
62
+ inGroup = false;
63
+ regex += ")";
64
+ }
65
+ break;
66
+ case ",":
67
+ if (inGroup) regex += "|";
68
+ regex += `\\${glob[i]}`;
69
+ break;
70
+ case "*":
71
+ starCount = 1;
72
+ while (glob[i + 1] === "*") {
73
+ starCount++;
74
+ i++;
75
+ }
76
+ if (options.globstar === false) regex += ".*";
77
+ else if (starCount > 1 && (glob[i - 1] === "/" || glob[i - 1] === void 0) && (glob[i + 1] === "/" || glob[i + 1] === void 0)) {
78
+ regex += "((?:[^/]*(?:/|$))*)";
79
+ i++;
80
+ } else regex += "([^/]*)";
81
+ break;
82
+ case void 0:
83
+ default: regex += glob[i];
84
+ }
85
+ }
86
+ const flags = isSetString(options.flags) ? options.flags : "";
87
+ if (!flags || !~flags.indexOf("g")) regex = `^${regex}$`;
88
+ return new RegExp(regex, flags);
89
+ }
90
+
91
+ //#endregion
92
+ export { globToRegex };
2
93
  //# sourceMappingURL=glob-to-regex.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"glob-to-regex.mjs","names":["char: string | undefined"],"sources":["../src/glob-to-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\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\n\n/**\n * Options for the `globToRegex` function.\n */\nexport interface GlobToRegexOptions {\n /**\n * Enables extended globbing features such as `?`, `+`, `@`, and `!`.\n *\n * @defaultValue true\n */\n extended?: boolean;\n\n /**\n * Enables globstar support (`**`).\n *\n * @defaultValue true\n */\n globstar?: boolean;\n\n /**\n * Flags to use for the generated regular expression.\n */\n flags?: string;\n}\n\n/**\n * Converts a glob pattern to a regular expression.\n *\n * @see https://mergify.com/blog/origin-and-evolution-of-the-globstar\n * @see https://en.wikipedia.org/wiki/Glob_(programming)\n *\n * @remarks\n * This function converts a glob pattern (like `*.{js,ts}` or `**\\/src/**`) into a regular expression\n *\n * @example\n * ```ts\n * import { globToRegex } from \"@stryke/path/glob-to-regex\";\n *\n * const test1 = globToRegex(\"*.{js,ts}\");\n * console.log(test1); // Output: /^([^/]*)\\.(js|ts)$/\n *\n * const test2 = globToRegex(\"**\\/src/**\");\n * console.log(test2); // Output: /^((?:[^/]*(?:\\/|$))*)?\\/src\\/((?:[^/]*(?:\\/|$))*)?$/\n * ```\n *\n * @param glob - The glob pattern to convert.\n * @param options - The options for the conversion.\n * @returns The converted regular expression.\n */\nexport function globToRegex(\n glob: string,\n options: GlobToRegexOptions = {}\n): RegExp {\n if (!isSetString(glob)) {\n throw new TypeError(\"A string was not provided as a glob pattern.\");\n }\n\n const str = String(glob);\n let regex = \"\";\n\n let inGroup = false;\n let char: string | undefined;\n for (let i = 0, len = str.length; i < len; i++) {\n char = str[i];\n\n const prevChar = str[i - 1];\n const nextChar = str[i + 1];\n let starCount = 1;\n\n switch (char) {\n case \"/\":\n case \"$\":\n case \"^\":\n case \"+\":\n case \".\":\n case \"(\":\n case \")\":\n case \"=\":\n case \"!\":\n case \"|\":\n regex += `\\\\${char}`;\n break;\n\n case \"?\":\n if (options.extended !== false) {\n regex += \".\";\n }\n break;\n\n case \"[\":\n case \"]\":\n if (options.extended !== false) {\n regex += char;\n }\n break;\n\n case \"{\":\n if (options.extended !== false) {\n inGroup = true;\n regex += \"(\";\n }\n break;\n\n case \"}\":\n if (options.extended !== false) {\n inGroup = false;\n regex += \")\";\n }\n break;\n\n case \",\":\n if (inGroup) {\n regex += \"|\";\n }\n regex += `\\\\${char}`;\n break;\n\n case \"*\":\n starCount = 1;\n while (str[i + 1] === \"*\") {\n starCount++;\n i++;\n }\n\n if (options.globstar === false) {\n regex += \".*\";\n } else {\n const isGlobstar =\n starCount > 1 &&\n (prevChar === \"/\" || prevChar === undefined) &&\n (nextChar === \"/\" || nextChar === undefined);\n\n if (isGlobstar) {\n regex += \"((?:[^/]*(?:\\/|$))*)?\";\n i++;\n } else {\n regex += \"([^/]*)\";\n }\n }\n break;\n\n case undefined:\n default:\n regex += char;\n }\n }\n\n const flags = isSetString(options.flags) ? options.flags : \"\";\n if (!flags || !~flags.indexOf(\"g\")) {\n regex = `^${regex}$`;\n }\n\n return new RegExp(regex, flags);\n}\n"],"mappings":"kEAoEA,SAAgB,EACd,EACA,EAA8B,EAAE,CACxB,CACR,GAAI,CAAC,EAAY,EAAK,CACpB,MAAU,UAAU,+CAA+C,CAGrE,IAAM,EAAM,OAAO,EAAK,CACpB,EAAQ,GAER,EAAU,GACVA,EACJ,IAAK,IAAI,EAAI,EAAG,EAAM,EAAI,OAAQ,EAAI,EAAK,IAAK,CAC9C,EAAO,EAAI,GAEX,IAAM,EAAW,EAAI,EAAI,GACnB,EAAW,EAAI,EAAI,GACrB,EAAY,EAEhB,OAAQ,EAAR,CACE,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACL,IAAK,IACH,GAAS,KAAK,IACd,MAEF,IAAK,IACC,EAAQ,WAAa,KACvB,GAAS,KAEX,MAEF,IAAK,IACL,IAAK,IACC,EAAQ,WAAa,KACvB,GAAS,GAEX,MAEF,IAAK,IACC,EAAQ,WAAa,KACvB,EAAU,GACV,GAAS,KAEX,MAEF,IAAK,IACC,EAAQ,WAAa,KACvB,EAAU,GACV,GAAS,KAEX,MAEF,IAAK,IACC,IACF,GAAS,KAEX,GAAS,KAAK,IACd,MAEF,IAAK,IAEH,IADA,EAAY,EACL,EAAI,EAAI,KAAO,KACpB,IACA,IAGE,EAAQ,WAAa,GACvB,GAAS,KAGP,EAAY,IACX,IAAa,KAAO,IAAa,IAAA,MACjC,IAAa,KAAO,IAAa,IAAA,KAGlC,GAAS,uBACT,KAEA,GAAS,UAGb,MAEF,KAAK,IAAA,GACL,QACE,GAAS,GAIf,IAAM,EAAQ,EAAY,EAAQ,MAAM,CAAG,EAAQ,MAAQ,GAK3D,OAJI,CAAC,GAAS,CAAC,CAAC,EAAM,QAAQ,IAAI,IAChC,EAAQ,IAAI,EAAM,IAGb,IAAI,OAAO,EAAO,EAAM"}
1
+ {"version":3,"file":"glob-to-regex.mjs","names":[],"sources":["../src/glob-to-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\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\n\n/**\n * Options for the `globToRegex` function.\n */\nexport interface GlobToRegexOptions {\n /**\n * Enables extended globbing features such as `?`, `+`, `@`, and `!`.\n *\n * @defaultValue true\n */\n extended?: boolean;\n\n /**\n * Enables globstar support (`**`).\n *\n * @defaultValue true\n */\n globstar?: boolean;\n\n /**\n * Flags to use for the generated regular expression.\n */\n flags?: string;\n}\n\n/**\n * Converts a glob pattern to a regular expression.\n *\n * @see https://mergify.com/blog/origin-and-evolution-of-the-globstar\n * @see https://en.wikipedia.org/wiki/Glob_(programming)\n *\n * @remarks\n * This function converts a glob pattern (like `*.{js,ts}` or `**\\/src/**`) into a regular expression\n *\n * @example\n * ```ts\n * import { globToRegex } from \"@stryke/path/glob-to-regex\";\n *\n * const test1 = globToRegex(\"*.{js,ts}\");\n * console.log(test1); // Output: /^([^/]*)\\.(js|ts)$/\n *\n * const test2 = globToRegex(\"**\\/src/**\");\n * console.log(test2); // Output: /^((?:[^/]*(?:\\/|$))*)?\\/src\\/((?:[^/]*(?:\\/|$))*)?$/\n * ```\n *\n * @param glob - The glob pattern to convert.\n * @param options - The options for the conversion.\n * @returns The converted regular expression.\n */\nexport function globToRegex(\n glob: string,\n options: GlobToRegexOptions = {}\n): RegExp {\n if (!isSetString(glob)) {\n throw new TypeError(\"A string was not provided as a glob pattern.\");\n }\n\n let regex = \"\";\n let inGroup = false;\n for (let i = 0; i < glob.length; i++) {\n let starCount = 1;\n switch (glob[i]) {\n case \"/\":\n case \"$\":\n case \"^\":\n case \"+\":\n case \".\":\n case \"(\":\n case \")\":\n case \"=\":\n case \"!\":\n case \"|\":\n regex += `\\\\${glob[i]}`;\n break;\n\n case \"?\":\n if (options.extended !== false) {\n regex += \".\";\n }\n break;\n\n case \"[\":\n case \"]\":\n if (options.extended !== false) {\n regex += glob[i];\n }\n break;\n\n case \"{\":\n if (options.extended !== false) {\n inGroup = true;\n regex += \"(\";\n }\n break;\n\n case \"}\":\n if (options.extended !== false) {\n inGroup = false;\n regex += \")\";\n }\n break;\n\n case \",\":\n if (inGroup) {\n regex += \"|\";\n }\n regex += `\\\\${glob[i]}`;\n break;\n\n case \"*\":\n starCount = 1;\n while (glob[i + 1] === \"*\") {\n starCount++;\n i++;\n }\n\n if (options.globstar === false) {\n regex += \".*\";\n } else {\n const isGlobstar =\n starCount > 1 &&\n (glob[i - 1] === \"/\" || glob[i - 1] === undefined) &&\n (glob[i + 1] === \"/\" || glob[i + 1] === undefined);\n\n if (isGlobstar) {\n regex += \"((?:[^\\/]*(?:\\/|$))*)\";\n i++;\n } else {\n regex += \"([^\\/]*)\";\n }\n }\n break;\n\n case undefined:\n default:\n regex += glob[i];\n }\n }\n\n const flags = isSetString(options.flags) ? options.flags : \"\";\n if (!flags || !~flags.indexOf(\"g\")) {\n regex = `^${regex}$`;\n }\n\n return new RegExp(regex, flags);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,YACd,MACA,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./regex.cjs`),n=require(`./slash.cjs`),r=require(`./is-parent-path.cjs`),i=require(`./join-paths.cjs`),a=require(`./append.cjs`),o=require(`./asset-extensions.cjs`),s=require(`./correct-path.cjs`),c=require(`./common.cjs`),l=require(`./delimiter.cjs`),u=require(`./file-path-fns.cjs`),d=require(`./glob-to-regex.cjs`),f=require(`./is-root-dir.cjs`),p=require(`./replace.cjs`),m=require(`./resolve-parent-path.cjs`);exports.ABSOLUTE_PATH_REGEX=t.ABSOLUTE_PATH_REGEX,exports.DEFAULT_ASSET_EXTS=o.DEFAULT_ASSET_EXTS,exports.DRIVE_LETTER_REGEX=t.DRIVE_LETTER_REGEX,exports.DRIVE_LETTER_START_REGEX=t.DRIVE_LETTER_START_REGEX,exports.FILE_EXTENSION_REGEX=t.FILE_EXTENSION_REGEX,exports.NPM_SCOPED_PACKAGE_REGEX=t.NPM_SCOPED_PACKAGE_REGEX,exports.PACKAGE_PATH_REGEX=t.PACKAGE_PATH_REGEX,exports.ROOT_FOLDER_REGEX=t.ROOT_FOLDER_REGEX,exports.UNC_REGEX=t.UNC_REGEX,exports.append=a.append,exports.appendExtension=a.appendExtension,exports.appendPath=a.appendPath,exports.basename=u.basename,exports.commonPath=c.commonPath,exports.correctPath=s.correctPath,exports.cwd=e.cwd,exports.delimiter=l.delimiter,exports.dirname=u.dirname,exports.extname=u.extname,exports.findFileDotExtension=u.findFileDotExtension,exports.findFileDotExtensionSafe=u.findFileDotExtensionSafe,exports.findFileExtension=u.findFileExtension,exports.findFileExtensionSafe=u.findFileExtensionSafe,exports.findFileName=u.findFileName,exports.findFilePath=u.findFilePath,exports.findFolderName=u.findFolderName,exports.formatSlash=n.formatSlash,exports.globToRegex=d.globToRegex,exports.hasFileExtension=u.hasFileExtension,exports.hasFileName=u.hasFileName,exports.hasFilePath=u.hasFilePath,exports.hasFolderName=u.hasFolderName,exports.isParentPath=r.isParentPath,exports.isSystemRoot=f.isSystemRoot,exports.join=i.join,exports.joinPaths=i.joinPaths,exports.normalizeString=s.normalizeString,exports.normalizeWindowsPath=s.normalizeWindowsPath,exports.parsePath=u.parsePath,exports.posix=l.posix,exports.relative=u.relative,exports.relativePath=u.relativePath,exports.relativeToCurrentDir=u.relativeToCurrentDir,exports.renameFile=u.renameFile,exports.replaceExtension=p.replaceExtension,exports.replacePath=p.replacePath,exports.resolve=u.resolve,exports.resolveParentPath=m.resolveParentPath,exports.resolvePath=u.resolvePath,exports.resolvePaths=u.resolvePaths,exports.slash=n.slash,exports.stripStars=s.stripStars,exports.toAbsolutePath=s.toAbsolutePath,exports.toRelativePath=s.toRelativePath,exports.win32=l.win32,exports.withTrailingSlash=s.withTrailingSlash,exports.withoutTrailingSlash=s.withoutTrailingSlash;
1
+ const require_cwd = require('./cwd.cjs');
2
+ const require_regex = require('./regex.cjs');
3
+ const require_slash = require('./slash.cjs');
4
+ const require_is_parent_path = require('./is-parent-path.cjs');
5
+ const require_join_paths = require('./join-paths.cjs');
6
+ const require_append = require('./append.cjs');
7
+ const require_asset_extensions = require('./asset-extensions.cjs');
8
+ const require_correct_path = require('./correct-path.cjs');
9
+ const require_common = require('./common.cjs');
10
+ const require_delimiter = require('./delimiter.cjs');
11
+ const require_file_path_fns = require('./file-path-fns.cjs');
12
+ const require_glob_to_regex = require('./glob-to-regex.cjs');
13
+ const require_is_root_dir = require('./is-root-dir.cjs');
14
+ const require_replace = require('./replace.cjs');
15
+ const require_resolve_parent_path = require('./resolve-parent-path.cjs');
16
+
17
+ exports.ABSOLUTE_PATH_REGEX = require_regex.ABSOLUTE_PATH_REGEX;
18
+ exports.DEFAULT_ASSET_EXTS = require_asset_extensions.DEFAULT_ASSET_EXTS;
19
+ exports.DRIVE_LETTER_REGEX = require_regex.DRIVE_LETTER_REGEX;
20
+ exports.DRIVE_LETTER_START_REGEX = require_regex.DRIVE_LETTER_START_REGEX;
21
+ exports.FILE_EXTENSION_REGEX = require_regex.FILE_EXTENSION_REGEX;
22
+ exports.NPM_SCOPED_PACKAGE_REGEX = require_regex.NPM_SCOPED_PACKAGE_REGEX;
23
+ exports.PACKAGE_PATH_REGEX = require_regex.PACKAGE_PATH_REGEX;
24
+ exports.ROOT_FOLDER_REGEX = require_regex.ROOT_FOLDER_REGEX;
25
+ exports.UNC_REGEX = require_regex.UNC_REGEX;
26
+ exports.append = require_append.append;
27
+ exports.appendExtension = require_append.appendExtension;
28
+ exports.appendPath = require_append.appendPath;
29
+ exports.basename = require_file_path_fns.basename;
30
+ exports.commonPath = require_common.commonPath;
31
+ exports.correctPath = require_correct_path.correctPath;
32
+ exports.cwd = require_cwd.cwd;
33
+ exports.delimiter = require_delimiter.delimiter;
34
+ exports.dirname = require_file_path_fns.dirname;
35
+ exports.extname = require_file_path_fns.extname;
36
+ exports.findFileDotExtension = require_file_path_fns.findFileDotExtension;
37
+ exports.findFileDotExtensionSafe = require_file_path_fns.findFileDotExtensionSafe;
38
+ exports.findFileExtension = require_file_path_fns.findFileExtension;
39
+ exports.findFileExtensionSafe = require_file_path_fns.findFileExtensionSafe;
40
+ exports.findFileName = require_file_path_fns.findFileName;
41
+ exports.findFilePath = require_file_path_fns.findFilePath;
42
+ exports.findFolderName = require_file_path_fns.findFolderName;
43
+ exports.formatSlash = require_slash.formatSlash;
44
+ exports.globToRegex = require_glob_to_regex.globToRegex;
45
+ exports.hasFileExtension = require_file_path_fns.hasFileExtension;
46
+ exports.hasFileName = require_file_path_fns.hasFileName;
47
+ exports.hasFilePath = require_file_path_fns.hasFilePath;
48
+ exports.hasFolderName = require_file_path_fns.hasFolderName;
49
+ exports.isParentPath = require_is_parent_path.isParentPath;
50
+ exports.isSystemRoot = require_is_root_dir.isSystemRoot;
51
+ exports.join = require_join_paths.join;
52
+ exports.joinPaths = require_join_paths.joinPaths;
53
+ exports.normalizeString = require_correct_path.normalizeString;
54
+ exports.normalizeWindowsPath = require_correct_path.normalizeWindowsPath;
55
+ exports.parsePath = require_file_path_fns.parsePath;
56
+ exports.posix = require_delimiter.posix;
57
+ exports.relative = require_file_path_fns.relative;
58
+ exports.relativePath = require_file_path_fns.relativePath;
59
+ exports.relativeToCurrentDir = require_file_path_fns.relativeToCurrentDir;
60
+ exports.renameFile = require_file_path_fns.renameFile;
61
+ exports.replaceExtension = require_replace.replaceExtension;
62
+ exports.replacePath = require_replace.replacePath;
63
+ exports.resolve = require_file_path_fns.resolve;
64
+ exports.resolveParentPath = require_resolve_parent_path.resolveParentPath;
65
+ exports.resolvePath = require_file_path_fns.resolvePath;
66
+ exports.resolvePaths = require_file_path_fns.resolvePaths;
67
+ exports.slash = require_slash.slash;
68
+ exports.stripStars = require_correct_path.stripStars;
69
+ exports.toAbsolutePath = require_correct_path.toAbsolutePath;
70
+ exports.toRelativePath = require_correct_path.toRelativePath;
71
+ exports.win32 = require_delimiter.win32;
72
+ exports.withTrailingSlash = require_correct_path.withTrailingSlash;
73
+ exports.withoutTrailingSlash = require_correct_path.withoutTrailingSlash;
package/dist/index.mjs CHANGED
@@ -1 +1,17 @@
1
- import{cwd as e}from"./cwd.mjs";import{ABSOLUTE_PATH_REGEX as t,DRIVE_LETTER_REGEX as n,DRIVE_LETTER_START_REGEX as r,FILE_EXTENSION_REGEX as i,NPM_SCOPED_PACKAGE_REGEX as a,PACKAGE_PATH_REGEX as o,ROOT_FOLDER_REGEX as s,UNC_REGEX as c}from"./regex.mjs";import{formatSlash as l,slash as u}from"./slash.mjs";import{isParentPath as d}from"./is-parent-path.mjs";import{join as f,joinPaths as p}from"./join-paths.mjs";import{append as m,appendExtension as h,appendPath as g}from"./append.mjs";import{DEFAULT_ASSET_EXTS as _}from"./asset-extensions.mjs";import{correctPath as v,normalizeString as y,normalizeWindowsPath as b,stripStars as x,toAbsolutePath as S,toRelativePath as C,withTrailingSlash as w,withoutTrailingSlash as T}from"./correct-path.mjs";import{commonPath as E}from"./common.mjs";import{delimiter as D,posix as O,win32 as k}from"./delimiter.mjs";import{basename as A,dirname as j,extname as M,findFileDotExtension as N,findFileDotExtensionSafe as P,findFileExtension as F,findFileExtensionSafe as I,findFileName as L,findFilePath as R,findFolderName as z,hasFileExtension as B,hasFileName as V,hasFilePath as H,hasFolderName as U,parsePath as W,relative as G,relativePath as K,relativeToCurrentDir as q,renameFile as J,resolve as Y,resolvePath as X,resolvePaths as Z}from"./file-path-fns.mjs";import{globToRegex as Q}from"./glob-to-regex.mjs";import{isSystemRoot as $}from"./is-root-dir.mjs";import{replaceExtension as ee,replacePath as te}from"./replace.mjs";import{resolveParentPath as ne}from"./resolve-parent-path.mjs";export{t as ABSOLUTE_PATH_REGEX,_ as DEFAULT_ASSET_EXTS,n as DRIVE_LETTER_REGEX,r as DRIVE_LETTER_START_REGEX,i as FILE_EXTENSION_REGEX,a as NPM_SCOPED_PACKAGE_REGEX,o as PACKAGE_PATH_REGEX,s as ROOT_FOLDER_REGEX,c as UNC_REGEX,m as append,h as appendExtension,g as appendPath,A as basename,E as commonPath,v as correctPath,e as cwd,D as delimiter,j as dirname,M as extname,N as findFileDotExtension,P as findFileDotExtensionSafe,F as findFileExtension,I as findFileExtensionSafe,L as findFileName,R as findFilePath,z as findFolderName,l as formatSlash,Q as globToRegex,B as hasFileExtension,V as hasFileName,H as hasFilePath,U as hasFolderName,d as isParentPath,$ as isSystemRoot,f as join,p as joinPaths,y as normalizeString,b as normalizeWindowsPath,W as parsePath,O as posix,G as relative,K as relativePath,q as relativeToCurrentDir,J as renameFile,ee as replaceExtension,te as replacePath,Y as resolve,ne as resolveParentPath,X as resolvePath,Z as resolvePaths,u as slash,x as stripStars,S as toAbsolutePath,C as toRelativePath,k as win32,w as withTrailingSlash,T as withoutTrailingSlash};
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";
3
+ import { formatSlash, slash } from "./slash.mjs";
4
+ import { isParentPath } from "./is-parent-path.mjs";
5
+ import { join, joinPaths } from "./join-paths.mjs";
6
+ import { append, appendExtension, appendPath } from "./append.mjs";
7
+ import { DEFAULT_ASSET_EXTS } from "./asset-extensions.mjs";
8
+ import { correctPath, normalizeString, normalizeWindowsPath, stripStars, toAbsolutePath, toRelativePath, withTrailingSlash, withoutTrailingSlash } from "./correct-path.mjs";
9
+ import { commonPath } from "./common.mjs";
10
+ import { delimiter, posix, win32 } from "./delimiter.mjs";
11
+ import { 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";
12
+ import { globToRegex } from "./glob-to-regex.mjs";
13
+ import { isSystemRoot } from "./is-root-dir.mjs";
14
+ import { replaceExtension, replacePath } from "./replace.mjs";
15
+ import { resolveParentPath } from "./resolve-parent-path.mjs";
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 };
@@ -1 +1,32 @@
1
- const e=require(`./slash.cjs`);function t(t,n){let r=e.slash(t.replaceAll(/\\/g,`/`).replace(/\/*$/,``))?.toLowerCase(),i=e.slash(n.replaceAll(/\\/g,`/`).replace(/\/*$/,``))?.toLowerCase();return t!==n&&r!==i&&r.startsWith(`${i}/`)}exports.isParentPath=t;
1
+ const require_slash = require('./slash.cjs');
2
+
3
+ //#region src/is-parent-path.ts
4
+ /**
5
+ * Check if a given path is a parent of another path.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * isParentPath("/home/user/project/src/index.ts", "/home/user/project/src");
10
+ * // returns true
11
+ * isParentPath("/home/user/project/src/index.ts", "/home/user/project");
12
+ * // returns true
13
+ * isParentPath("/home/user/project/src/index.ts", "/home/user/project/src/other");
14
+ * // returns false
15
+ * isParentPath("/home/user/project/src/index.ts", "/home/user/other");
16
+ * // returns false
17
+ * isParentPath("/home/user/project/src/index.ts", "/home/user/project/src/index.ts");
18
+ * // returns false
19
+ * ```
20
+ *
21
+ * @param childPath - The path to check if it is a child of the parent path.
22
+ * @param parentPath - The path to check if it is a parent of the child path.
23
+ * @returns `true` if `childPath` is a child of `parentPath`, otherwise `false`.
24
+ */
25
+ function isParentPath(childPath, parentPath) {
26
+ const normalizedChild = require_slash.slash(childPath.replaceAll(/\\/g, "/").replace(/\/*$/, ""))?.toLowerCase();
27
+ const normalizedParent = require_slash.slash(parentPath.replaceAll(/\\/g, "/").replace(/\/*$/, ""))?.toLowerCase();
28
+ return childPath !== parentPath && normalizedChild !== normalizedParent && normalizedChild.startsWith(`${normalizedParent}/`);
29
+ }
30
+
31
+ //#endregion
32
+ exports.isParentPath = isParentPath;
@@ -1,2 +1,33 @@
1
- import{slash as e}from"./slash.mjs";function t(t,n){let r=e(t.replaceAll(/\\/g,`/`).replace(/\/*$/,``))?.toLowerCase(),i=e(n.replaceAll(/\\/g,`/`).replace(/\/*$/,``))?.toLowerCase();return t!==n&&r!==i&&r.startsWith(`${i}/`)}export{t as isParentPath};
1
+ import { slash } from "./slash.mjs";
2
+
3
+ //#region src/is-parent-path.ts
4
+ /**
5
+ * Check if a given path is a parent of another path.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * isParentPath("/home/user/project/src/index.ts", "/home/user/project/src");
10
+ * // returns true
11
+ * isParentPath("/home/user/project/src/index.ts", "/home/user/project");
12
+ * // returns true
13
+ * isParentPath("/home/user/project/src/index.ts", "/home/user/project/src/other");
14
+ * // returns false
15
+ * isParentPath("/home/user/project/src/index.ts", "/home/user/other");
16
+ * // returns false
17
+ * isParentPath("/home/user/project/src/index.ts", "/home/user/project/src/index.ts");
18
+ * // returns false
19
+ * ```
20
+ *
21
+ * @param childPath - The path to check if it is a child of the parent path.
22
+ * @param parentPath - The path to check if it is a parent of the child path.
23
+ * @returns `true` if `childPath` is a child of `parentPath`, otherwise `false`.
24
+ */
25
+ function isParentPath(childPath, parentPath) {
26
+ const normalizedChild = slash(childPath.replaceAll(/\\/g, "/").replace(/\/*$/, ""))?.toLowerCase();
27
+ const normalizedParent = slash(parentPath.replaceAll(/\\/g, "/").replace(/\/*$/, ""))?.toLowerCase();
28
+ return childPath !== parentPath && normalizedChild !== normalizedParent && normalizedChild.startsWith(`${normalizedParent}/`);
29
+ }
30
+
31
+ //#endregion
32
+ export { isParentPath };
2
33
  //# sourceMappingURL=is-parent-path.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-parent-path.mjs","names":[],"sources":["../src/is-parent-path.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { slash } from \"./slash\";\n\n/**\n * Check if a given path is a parent of another path.\n *\n * @example\n * ```ts\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/project/src\");\n * // returns true\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/project\");\n * // returns true\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/project/src/other\");\n * // returns false\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/other\");\n * // returns false\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/project/src/index.ts\");\n * // returns false\n * ```\n *\n * @param childPath - The path to check if it is a child of the parent path.\n * @param parentPath - The path to check if it is a parent of the child path.\n * @returns `true` if `childPath` is a child of `parentPath`, otherwise `false`.\n */\nexport function isParentPath(childPath: string, parentPath: string): boolean {\n const normalizedChild = slash(\n childPath.replaceAll(/\\\\/g, \"/\").replace(/\\/*$/, \"\")\n )?.toLowerCase();\n const normalizedParent = slash(\n parentPath.replaceAll(/\\\\/g, \"/\").replace(/\\/*$/, \"\")\n )?.toLowerCase();\n\n return (\n childPath !== parentPath &&\n normalizedChild !== normalizedParent &&\n normalizedChild.startsWith(`${normalizedParent}/`)\n );\n}\n"],"mappings":"oCAyCA,SAAgB,EAAa,EAAmB,EAA6B,CAC3E,IAAM,EAAkB,EACtB,EAAU,WAAW,MAAO,IAAI,CAAC,QAAQ,OAAQ,GAAG,CACrD,EAAE,aAAa,CACV,EAAmB,EACvB,EAAW,WAAW,MAAO,IAAI,CAAC,QAAQ,OAAQ,GAAG,CACtD,EAAE,aAAa,CAEhB,OACE,IAAc,GACd,IAAoB,GACpB,EAAgB,WAAW,GAAG,EAAiB,GAAG"}
1
+ {"version":3,"file":"is-parent-path.mjs","names":[],"sources":["../src/is-parent-path.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { slash } from \"./slash\";\n\n/**\n * Check if a given path is a parent of another path.\n *\n * @example\n * ```ts\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/project/src\");\n * // returns true\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/project\");\n * // returns true\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/project/src/other\");\n * // returns false\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/other\");\n * // returns false\n * isParentPath(\"/home/user/project/src/index.ts\", \"/home/user/project/src/index.ts\");\n * // returns false\n * ```\n *\n * @param childPath - The path to check if it is a child of the parent path.\n * @param parentPath - The path to check if it is a parent of the child path.\n * @returns `true` if `childPath` is a child of `parentPath`, otherwise `false`.\n */\nexport function isParentPath(childPath: string, parentPath: string): boolean {\n const normalizedChild = slash(\n childPath.replaceAll(/\\\\/g, \"/\").replace(/\\/*$/, \"\")\n )?.toLowerCase();\n const normalizedParent = slash(\n parentPath.replaceAll(/\\\\/g, \"/\").replace(/\\/*$/, \"\")\n )?.toLowerCase();\n\n return (\n childPath !== parentPath &&\n normalizedChild !== normalizedParent &&\n normalizedChild.startsWith(`${normalizedParent}/`)\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,aAAa,WAAmB,YAA6B;CAC3E,MAAM,kBAAkB,MACtB,UAAU,WAAW,OAAO,IAAI,CAAC,QAAQ,QAAQ,GAAG,CACrD,EAAE,aAAa;CAChB,MAAM,mBAAmB,MACvB,WAAW,WAAW,OAAO,IAAI,CAAC,QAAQ,QAAQ,GAAG,CACtD,EAAE,aAAa;AAEhB,QACE,cAAc,cACd,oBAAoB,oBACpB,gBAAgB,WAAW,GAAG,iBAAiB,GAAG"}
@@ -1 +1,14 @@
1
- function e(e){return e===`/`||e===`c:\\`||e===`C:\\`}exports.isSystemRoot=e;
1
+
2
+ //#region src/is-root-dir.ts
3
+ /**
4
+ * Check if the directory is the current system's root directory.
5
+ *
6
+ * @param dir - The directory to check.
7
+ * @returns Returns true if the directory is the root directory.
8
+ */
9
+ function isSystemRoot(dir) {
10
+ return Boolean(dir === "/" || dir === "c:\\" || dir === "C:\\");
11
+ }
12
+
13
+ //#endregion
14
+ exports.isSystemRoot = isSystemRoot;
@@ -1,2 +1,14 @@
1
- function e(e){return e===`/`||e===`c:\\`||e===`C:\\`}export{e as isSystemRoot};
1
+ //#region src/is-root-dir.ts
2
+ /**
3
+ * Check if the directory is the current system's root directory.
4
+ *
5
+ * @param dir - The directory to check.
6
+ * @returns Returns true if the directory is the root directory.
7
+ */
8
+ function isSystemRoot(dir) {
9
+ return Boolean(dir === "/" || dir === "c:\\" || dir === "C:\\");
10
+ }
11
+
12
+ //#endregion
13
+ export { isSystemRoot };
2
14
  //# sourceMappingURL=is-root-dir.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-root-dir.mjs","names":[],"sources":["../src/is-root-dir.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Check if the directory is the current system's root directory.\n *\n * @param dir - The directory to check.\n * @returns Returns true if the directory is the root directory.\n */\nexport function isSystemRoot(dir: string): boolean {\n return Boolean(dir === \"/\" || dir === \"c:\\\\\" || dir === \"C:\\\\\");\n}\n"],"mappings":"AAwBA,SAAgB,EAAa,EAAsB,CACjD,OAAe,IAAQ,KAAO,IAAQ,QAAU,IAAQ"}
1
+ {"version":3,"file":"is-root-dir.mjs","names":[],"sources":["../src/is-root-dir.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Check if the directory is the current system's root directory.\n *\n * @param dir - The directory to check.\n * @returns Returns true if the directory is the root directory.\n */\nexport function isSystemRoot(dir: string): boolean {\n return Boolean(dir === \"/\" || dir === \"c:\\\\\" || dir === \"C:\\\\\");\n}\n"],"mappings":";;;;;;;AAwBA,SAAgB,aAAa,KAAsB;AACjD,QAAO,QAAQ,QAAQ,OAAO,QAAQ,UAAU,QAAQ,OAAO"}