@stryke/path 0.14.2 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.extname = exports.dirname = exports.basename = void 0;
7
+ exports.findFileDotExtension = findFileDotExtension;
8
+ exports.findFileDotExtensionSafe = findFileDotExtensionSafe;
7
9
  exports.findFileExtension = findFileExtension;
8
10
  exports.findFileExtensionSafe = findFileExtensionSafe;
9
11
  exports.findFileName = findFileName;
@@ -63,9 +65,17 @@ function findFileExtension(e) {
63
65
  return t && t.length > 0 && (0, _typeChecks.isSetString)(t[0]) ? t[0].replace(".", "") : void 0;
64
66
  }
65
67
  const extname = exports.extname = findFileExtension;
68
+ function findFileDotExtension(e) {
69
+ const t = findFileExtension(e);
70
+ return t ? `.${t}` : void 0;
71
+ }
66
72
  function findFileExtensionSafe(e) {
67
73
  return findFileExtension(e) ?? _base.EMPTY_STRING;
68
74
  }
75
+ function findFileDotExtensionSafe(e) {
76
+ const t = findFileExtension(e);
77
+ return t ? `.${t}` : "";
78
+ }
69
79
  function hasFileName(e) {
70
80
  return !!findFileName(e);
71
81
  }
@@ -79,6 +79,18 @@ export declare const basename: typeof findFolderName;
79
79
  */
80
80
  export declare function findFileExtension(filePath: string): string | undefined;
81
81
  export declare const extname: typeof findFileExtension;
82
+ /**
83
+ * Find the file extension including the `"."` character prefix from a file path.
84
+ *
85
+ * @remarks
86
+ * 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`.
87
+ *
88
+ * The returned extension **will** include the dot, for example `.txt` or `.js` instead of `txt` or `js`.
89
+ *
90
+ * @param filePath - The file path to process
91
+ * @returns The file extension (including the `"."` prefix) or undefined if no extension is found
92
+ */
93
+ export declare function findFileDotExtension(filePath: string): string | undefined;
82
94
  /**
83
95
  * Find the file extension from a file path or an empty string.
84
96
  *
@@ -91,6 +103,18 @@ export declare const extname: typeof findFileExtension;
91
103
  * @returns The file extension or an empty string if no extension is found
92
104
  */
93
105
  export declare function findFileExtensionSafe(filePath: string): string;
106
+ /**
107
+ * Find the file extension including the `"."` character prefix from a file path or an empty string.
108
+ *
109
+ * @remarks
110
+ * 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`.
111
+ *
112
+ * The returned extension **will** include the dot, for example `.txt` or `.js` instead of `txt` or `js`.
113
+ *
114
+ * @param filePath - The file path to process
115
+ * @returns The file extension (including the `"."` prefix) or an empty string if no extension is found
116
+ */
117
+ export declare function findFileDotExtensionSafe(filePath: string): string;
94
118
  /**
95
119
  * Check if a file path has a file name.
96
120
  *
@@ -1 +1 @@
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)}
1
+ import{isSetString as d}from"@stryke/type-checks";import{EMPTY_STRING as u}from"@stryke/types/base";import{normalizeString as g,normalizeWindowsPath as l}from"./correct-path";import{cwd as a}from"./cwd";import{isAbsolute as p,isAbsolutePath as c}from"./is-type";import{joinPaths as f}from"./join-paths";import{FILE_EXTENSION_REGEX as m,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(".")?u:n===!1&&i.includes(".")?i.replace(`.${findFileExtension(i)??""}`,"")||u: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??u}export const basename=findFolderName;export function findFileExtension(e){if(e.endsWith(".")||e.endsWith("/"))return;const t=m.exec(l(e));return t&&t.length>0&&d(t[0])?t[0].replace(".",""):void 0}export const extname=findFileExtension;export function findFileDotExtension(e){const t=findFileExtension(e);return t?`.${t}`:void 0}export function findFileExtensionSafe(e){return findFileExtension(e)??u}export function findFileDotExtensionSafe(e){const t=findFileExtension(e);return t?`.${t}`:""}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=a()){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]:a();!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,a())}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)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.14.2",
3
+ "version": "0.15.0",
4
4
  "type": "module",
5
5
  "description": "A package containing various utilities that expand the functionality of NodeJs's built-in `path` module",
6
6
  "repository": {
@@ -278,5 +278,5 @@
278
278
  "main": "./dist/index.cjs",
279
279
  "module": "./dist/index.mjs",
280
280
  "types": "./dist/index.d.ts",
281
- "gitHead": "7def42c7a092ae198b8a753e78496b3f49c64b76"
281
+ "gitHead": "4074c4a56f6e2c42ca4c39c30df5309c19024c7b"
282
282
  }