@stryke/path 0.14.1 → 0.14.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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.dirname = exports.basename = void 0;
6
+ exports.extname = exports.dirname = exports.basename = void 0;
7
7
  exports.findFileExtension = findFileExtension;
8
8
  exports.findFileExtensionSafe = findFileExtensionSafe;
9
9
  exports.findFileName = findFileName;
@@ -21,6 +21,7 @@ exports.renameFile = renameFile;
21
21
  exports.resolve = resolve;
22
22
  exports.resolvePath = resolvePath;
23
23
  exports.resolvePaths = resolvePaths;
24
+ var _typeChecks = require("@stryke/type-checks");
24
25
  var _base = require("@stryke/types/base");
25
26
  var _correctPath = require("./correct-path.cjs");
26
27
  var _cwd = require("./cwd.cjs");
@@ -33,7 +34,7 @@ function findFileName(e, t = {}) {
33
34
  withExtension: n = !0
34
35
  } = t,
35
36
  i = (0, _correctPath.normalizeWindowsPath)(e)?.split(e?.includes("\\") ? "\\" : "/")?.pop() ?? "";
36
- return r === !0 && !i.includes(".") ? _base.EMPTY_STRING : n === !1 && i.includes(".") ? i.substring(0, i.lastIndexOf(".")) || _base.EMPTY_STRING : i;
37
+ return r === !0 && !i.includes(".") ? _base.EMPTY_STRING : n === !1 && i.includes(".") ? i.replace(`.${findFileExtension(i) ?? ""}`, "") || _base.EMPTY_STRING : i;
37
38
  }
38
39
  function findFilePath(e) {
39
40
  const t = (0, _correctPath.normalizeWindowsPath)(e),
@@ -58,9 +59,10 @@ function findFolderName(e) {
58
59
  const basename = exports.basename = findFolderName;
59
60
  function findFileExtension(e) {
60
61
  if (e.endsWith(".") || e.endsWith("/")) return;
61
- const t = /.(\.[^./]+|\.)$/.exec((0, _correctPath.normalizeWindowsPath)(e));
62
- return t && t[1] || void 0;
62
+ const t = _regex.FILE_EXTENSION_REGEX.exec((0, _correctPath.normalizeWindowsPath)(e));
63
+ return t && t.length > 0 && (0, _typeChecks.isSetString)(t[0]) ? t[0].replace(".", "") : void 0;
63
64
  }
65
+ const extname = exports.extname = findFileExtension;
64
66
  function findFileExtensionSafe(e) {
65
67
  return findFileExtension(e) ?? _base.EMPTY_STRING;
66
68
  }
@@ -63,14 +63,22 @@ export declare const basename: typeof findFolderName;
63
63
  * Find the file extension from a file path.
64
64
  *
65
65
  * @remarks
66
+ * The functionality of this method is similar to the {@link path.extname} function in Node's path module.
66
67
  * 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`.
67
68
  *
68
69
  * The returned extension **will not** include the dot, for example `txt` or `js` instead of `.txt` or `.js`.
69
70
  *
71
+ * @example
72
+ * ```ts
73
+ * findFileExtension("C:\\Users\\user\\Documents\\file.config.ts");
74
+ * // Returns "ts"
75
+ * ```
76
+ *
70
77
  * @param filePath - The file path to process
71
78
  * @returns The file extension or undefined if no extension is found
72
79
  */
73
80
  export declare function findFileExtension(filePath: string): string | undefined;
81
+ export declare const extname: typeof findFileExtension;
74
82
  /**
75
83
  * Find the file extension from a file path or an empty string.
76
84
  *
@@ -1 +1 @@
1
- import{EMPTY_STRING as a}from"@stryke/types/base";import{normalizeString as g,normalizeWindowsPath as l}from"./correct-path";import{cwd as u}from"./cwd";import{isAbsolute as p,isAbsolutePath as c}from"./is-type";import{joinPaths as f}from"./join-paths";import{ROOT_FOLDER_REGEX as x}from"./regex";export function findFileName(e,t={}){const{requireExtension:r=!1,withExtension:n=!0}=t,i=l(e)?.split(e?.includes("\\")?"\\":"/")?.pop()??"";return r===!0&&!i.includes(".")?a:n===!1&&i.includes(".")?i.substring(0,i.lastIndexOf("."))||a:i}export function findFilePath(e){const t=l(e),r=t.replace(findFileName(t,{requireExtension:!0}),"");return r==="/"?r:r.replace(/\/$/,"")}export const dirname=findFilePath;export function findFolderName(e){const t=findFilePath(e).split("/");let r="";for(let n=t.length-1;n>=0;n--){const i=t[n];if(i){r=i;break}}return r??a}export const basename=findFolderName;export function findFileExtension(e){if(e.endsWith(".")||e.endsWith("/"))return;const t=/.(\.[^./]+|\.)$/.exec(l(e));return t&&t[1]||void 0}export function findFileExtensionSafe(e){return findFileExtension(e)??a}export function hasFileName(e){return!!findFileName(e)}export function hasFilePath(e){return!!findFilePath(e)}export function hasFolderName(e){return!!findFolderName(e)}export function hasFileExtension(e){return!!findFileExtension(e)}export function resolvePath(e,t=u()){const r=l(e).split("/");let n="",i=!1;for(let o=r.length-1;o>=-1&&!i;o--){const s=o>=0?r[o]:t;!s||s.length===0||(n=f(s,n),i=c(s))}return n=g(n,!i),i&&!c(n)?`/${n}`:n.length>0?n:"."}export function resolve(...e){e=e.map(n=>l(n));let t="",r=!1;for(let n=e.length-1;n>=-1&&!r;n--){const i=n>=0?e[n]:u();!i||i.length===0||(t=`${i}/${t}`,r=p(i))}return t=g(t,!r),r&&!p(t)?`/${t}`:t.length>0?t:"."}export function resolvePaths(...e){return resolvePath(f(...e.map(t=>l(t))))}export function relative(e,t){const r=resolve(e).replace(x,"$1").split("/"),n=resolve(t).replace(x,"$1").split("/");if(n[0][1]===":"&&r[0][1]===":"&&r[0]!==n[0])return n.join("/");const i=[...r];for(const o of i){if(n[0]!==o)break;r.shift(),n.shift()}return[...r.map(()=>".."),...n].join("/")}export function relativePath(e,t,r=!1){return relative(r!==!0?e.replace(/\/$/,""):e,r!==!0?t.replace(/\/$/,""):t)}export function relativeToCurrentDir(e){return relativePath(e,u())}export function parsePath(e){const t=/^[/\\]|^[a-z]:[/\\]/i.exec(e)?.[0]?.replace(/\\/g,"/")||"",r=l(e),n=r.replace(/\/$/,"").split("/").slice(0,-1);n.length===1&&/^[A-Z]:$/i.test(n[0])&&(n[0]+="/");const i=findFolderName(r),o=n.join("/")||(c(e)?"/":"."),s=findFileExtensionSafe(e);return{root:t,dir:o,base:i,ext:s,name:i.slice(0,i.length-s.length)}}export function renameFile(e,t){const r=parsePath(e);return f(r.dir,t.includes(".")?t:t+r.ext)}
1
+ import{isSetString as x}from"@stryke/type-checks";import{EMPTY_STRING as a}from"@stryke/types/base";import{normalizeString as p,normalizeWindowsPath as l}from"./correct-path";import{cwd as c}from"./cwd";import{isAbsolute as g,isAbsolutePath as u}from"./is-type";import{joinPaths as f}from"./join-paths";import{FILE_EXTENSION_REGEX as d,ROOT_FOLDER_REGEX as m}from"./regex";export function findFileName(e,t={}){const{requireExtension:r=!1,withExtension:n=!0}=t,i=l(e)?.split(e?.includes("\\")?"\\":"/")?.pop()??"";return r===!0&&!i.includes(".")?a:n===!1&&i.includes(".")?i.replace(`.${findFileExtension(i)??""}`,"")||a:i}export function findFilePath(e){const t=l(e),r=t.replace(findFileName(t,{requireExtension:!0}),"");return r==="/"?r:r.replace(/\/$/,"")}export const dirname=findFilePath;export function findFolderName(e){const t=findFilePath(e).split("/");let r="";for(let n=t.length-1;n>=0;n--){const i=t[n];if(i){r=i;break}}return r??a}export const basename=findFolderName;export function findFileExtension(e){if(e.endsWith(".")||e.endsWith("/"))return;const t=d.exec(l(e));return t&&t.length>0&&x(t[0])?t[0].replace(".",""):void 0}export const extname=findFileExtension;export function findFileExtensionSafe(e){return findFileExtension(e)??a}export function hasFileName(e){return!!findFileName(e)}export function hasFilePath(e){return!!findFilePath(e)}export function hasFolderName(e){return!!findFolderName(e)}export function hasFileExtension(e){return!!findFileExtension(e)}export function resolvePath(e,t=c()){const r=l(e).split("/");let n="",i=!1;for(let o=r.length-1;o>=-1&&!i;o--){const s=o>=0?r[o]:t;!s||s.length===0||(n=f(s,n),i=u(s))}return n=p(n,!i),i&&!u(n)?`/${n}`:n.length>0?n:"."}export function resolve(...e){e=e.map(n=>l(n));let t="",r=!1;for(let n=e.length-1;n>=-1&&!r;n--){const i=n>=0?e[n]:c();!i||i.length===0||(t=`${i}/${t}`,r=g(i))}return t=p(t,!r),r&&!g(t)?`/${t}`:t.length>0?t:"."}export function resolvePaths(...e){return resolvePath(f(...e.map(t=>l(t))))}export function relative(e,t){const r=resolve(e).replace(m,"$1").split("/"),n=resolve(t).replace(m,"$1").split("/");if(n[0][1]===":"&&r[0][1]===":"&&r[0]!==n[0])return n.join("/");const i=[...r];for(const o of i){if(n[0]!==o)break;r.shift(),n.shift()}return[...r.map(()=>".."),...n].join("/")}export function relativePath(e,t,r=!1){return relative(r!==!0?e.replace(/\/$/,""):e,r!==!0?t.replace(/\/$/,""):t)}export function relativeToCurrentDir(e){return relativePath(e,c())}export function parsePath(e){const t=/^[/\\]|^[a-z]:[/\\]/i.exec(e)?.[0]?.replace(/\\/g,"/")||"",r=l(e),n=r.replace(/\/$/,"").split("/").slice(0,-1);n.length===1&&/^[A-Z]:$/i.test(n[0])&&(n[0]+="/");const i=findFolderName(r),o=n.join("/")||(u(e)?"/":"."),s=findFileExtensionSafe(e);return{root:t,dir:o,base:i,ext:s,name:i.slice(0,i.length-s.length)}}export function renameFile(e,t){const r=parsePath(e);return f(r.dir,t.includes(".")?t:t+r.ext)}
package/dist/find.cjs ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _filePathFns = require("./file-path-fns.cjs");
7
+ Object.keys(_filePathFns).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _filePathFns[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _filePathFns[key];
14
+ }
15
+ });
16
+ });
package/dist/find.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./file-path-fns";
package/dist/find.mjs ADDED
@@ -0,0 +1 @@
1
+ export*from"./file-path-fns";
package/dist/join.cjs ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _joinPaths = require("./join-paths.cjs");
7
+ Object.keys(_joinPaths).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _joinPaths[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _joinPaths[key];
14
+ }
15
+ });
16
+ });
package/dist/join.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./join-paths";
package/dist/join.mjs ADDED
@@ -0,0 +1 @@
1
+ export*from"./join-paths";
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _correctPath = require("./correct-path.cjs");
7
+ Object.keys(_correctPath).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _correctPath[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _correctPath[key];
14
+ }
15
+ });
16
+ });
@@ -0,0 +1 @@
1
+ export * from "./correct-path";
@@ -0,0 +1 @@
1
+ export*from"./correct-path";
package/dist/regex.cjs CHANGED
@@ -3,9 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.UNC_REGEX = exports.ROOT_FOLDER_REGEX = exports.DRIVE_LETTER_START_REGEX = exports.DRIVE_LETTER_REGEX = exports.ABSOLUTE_PATH_REGEX = void 0;
6
+ exports.UNC_REGEX = exports.ROOT_FOLDER_REGEX = exports.FILE_EXTENSION_REGEX = exports.DRIVE_LETTER_START_REGEX = exports.DRIVE_LETTER_REGEX = exports.ABSOLUTE_PATH_REGEX = void 0;
7
7
  const DRIVE_LETTER_START_REGEX = exports.DRIVE_LETTER_START_REGEX = /^[A-Z]:\//i,
8
8
  DRIVE_LETTER_REGEX = exports.DRIVE_LETTER_REGEX = /^[A-Z]:$/i,
9
9
  UNC_REGEX = exports.UNC_REGEX = /^[/\\]{2}/,
10
10
  ABSOLUTE_PATH_REGEX = exports.ABSOLUTE_PATH_REGEX = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i,
11
- ROOT_FOLDER_REGEX = exports.ROOT_FOLDER_REGEX = /^\/([A-Z]:)?$/i;
11
+ ROOT_FOLDER_REGEX = exports.ROOT_FOLDER_REGEX = /^\/([A-Z]:)?$/i,
12
+ FILE_EXTENSION_REGEX = exports.FILE_EXTENSION_REGEX = /\.[0-9a-z]+$/i;
package/dist/regex.d.ts CHANGED
@@ -3,3 +3,4 @@ export declare const DRIVE_LETTER_REGEX: RegExp;
3
3
  export declare const UNC_REGEX: RegExp;
4
4
  export declare const ABSOLUTE_PATH_REGEX: RegExp;
5
5
  export declare const ROOT_FOLDER_REGEX: RegExp;
6
+ export declare const FILE_EXTENSION_REGEX: RegExp;
package/dist/regex.mjs CHANGED
@@ -1 +1 @@
1
- export const DRIVE_LETTER_START_REGEX=/^[A-Z]:\//i,DRIVE_LETTER_REGEX=/^[A-Z]:$/i,UNC_REGEX=/^[/\\]{2}/,ABSOLUTE_PATH_REGEX=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i,ROOT_FOLDER_REGEX=/^\/([A-Z]:)?$/i;
1
+ export const DRIVE_LETTER_START_REGEX=/^[A-Z]:\//i,DRIVE_LETTER_REGEX=/^[A-Z]:$/i,UNC_REGEX=/^[/\\]{2}/,ABSOLUTE_PATH_REGEX=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i,ROOT_FOLDER_REGEX=/^\/([A-Z]:)?$/i,FILE_EXTENSION_REGEX=/\.[0-9a-z]+$/i;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.14.1",
3
+ "version": "0.14.2",
4
4
  "type": "module",
5
5
  "description": "A package containing various utilities that expand the functionality of NodeJs's built-in `path` module",
6
6
  "repository": {
@@ -9,7 +9,10 @@
9
9
  "directory": "packages/path"
10
10
  },
11
11
  "private": false,
12
- "devDependencies": { "@stryke/types": "^0.9.0" },
12
+ "devDependencies": {
13
+ "@stryke/type-checks": "^0.3.10",
14
+ "@stryke/types": "^0.9.0"
15
+ },
13
16
  "publishConfig": { "access": "public" },
14
17
  "dependencies": {},
15
18
  "sideEffects": false,
@@ -85,6 +88,25 @@
85
88
  },
86
89
  "default": { "types": "./dist/regex.d.ts", "default": "./dist/regex.mjs" }
87
90
  },
91
+ "./normalize": {
92
+ "import": {
93
+ "types": "./dist/normalize.d.ts",
94
+ "default": "./dist/normalize.mjs"
95
+ },
96
+ "require": {
97
+ "types": "./dist/normalize.d.ts",
98
+ "default": "./dist/normalize.cjs"
99
+ },
100
+ "default": {
101
+ "types": "./dist/normalize.d.ts",
102
+ "default": "./dist/normalize.mjs"
103
+ }
104
+ },
105
+ "./join": {
106
+ "import": { "types": "./dist/join.d.ts", "default": "./dist/join.mjs" },
107
+ "require": { "types": "./dist/join.d.ts", "default": "./dist/join.cjs" },
108
+ "default": { "types": "./dist/join.d.ts", "default": "./dist/join.mjs" }
109
+ },
88
110
  "./join-paths": {
89
111
  "import": {
90
112
  "types": "./dist/join-paths.d.ts",
@@ -163,6 +185,11 @@
163
185
  "default": "./dist/get-parent-path.mjs"
164
186
  }
165
187
  },
188
+ "./find": {
189
+ "import": { "types": "./dist/find.d.ts", "default": "./dist/find.mjs" },
190
+ "require": { "types": "./dist/find.d.ts", "default": "./dist/find.cjs" },
191
+ "default": { "types": "./dist/find.d.ts", "default": "./dist/find.mjs" }
192
+ },
166
193
  "./file-path-fns": {
167
194
  "import": {
168
195
  "types": "./dist/file-path-fns.d.ts",
@@ -251,5 +278,5 @@
251
278
  "main": "./dist/index.cjs",
252
279
  "module": "./dist/index.mjs",
253
280
  "types": "./dist/index.d.ts",
254
- "gitHead": "73e8ba817597f78f119c7924d64e609e72f158c4"
281
+ "gitHead": "7def42c7a092ae198b8a753e78496b3f49c64b76"
255
282
  }