@stryke/path 0.21.5 → 0.22.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.
@@ -38,25 +38,26 @@ function findFileName(e, t = {}) {
38
38
  i = (0, _correctPath.normalizeWindowsPath)(e)?.split(e?.includes("\\") ? "\\" : "/")?.pop() ?? "";
39
39
  return r === !0 && !i.includes(".") ? _base.EMPTY_STRING : n === !1 && i.includes(".") ? i.replace(`.${findFileExtension(i) ?? ""}`, "") || _base.EMPTY_STRING : i;
40
40
  }
41
- function findFilePath(e) {
42
- const t = (0, _correctPath.normalizeWindowsPath)(e),
43
- r = t.replace(findFileName(t, {
44
- requireExtension: !0
41
+ function findFilePath(e, t = {}) {
42
+ const r = (0, _correctPath.normalizeWindowsPath)(e),
43
+ n = r.replace(findFileName(r, {
44
+ requireExtension: !1,
45
+ ...t
45
46
  }), "");
46
- return r === "/" ? r : r.replace(/\/$/, "");
47
+ return n === "/" ? n : n.replace(/\/$/, "");
47
48
  }
48
49
  const dirname = exports.dirname = findFilePath;
49
- function findFolderName(e) {
50
- const t = findFilePath(e).split("/");
51
- let r = "";
52
- for (let n = t.length - 1; n >= 0; n--) {
53
- const i = t[n];
54
- if (i) {
55
- r = i;
50
+ function findFolderName(e, t) {
51
+ const r = findFilePath(e, t).split("/");
52
+ let n = "";
53
+ for (let i = r.length - 1; i >= 0; i--) {
54
+ const o = r[i];
55
+ if (o) {
56
+ n = o;
56
57
  break;
57
58
  }
58
59
  }
59
- return r ?? _base.EMPTY_STRING;
60
+ return n ?? _base.EMPTY_STRING;
60
61
  }
61
62
  const basename = exports.basename = findFolderName;
62
63
  function findFileExtension(e) {
@@ -39,9 +39,10 @@ export declare function findFileName(filePath: string, options?: FindFileNameOpt
39
39
  * ```
40
40
  *
41
41
  * @param filePath - The file path to process
42
+ * @param options - Options to control the file name extraction
42
43
  * @returns The full file path's directories
43
44
  */
44
- export declare function findFilePath(filePath: string): string;
45
+ export declare function findFilePath(filePath: string, options?: FindFileNameOptions): string;
45
46
  export declare const dirname: typeof findFilePath;
46
47
  /**
47
48
  * Find the top most folder containing the file from a file path.
@@ -55,9 +56,10 @@ export declare const dirname: typeof findFilePath;
55
56
  * // folderPath = "Documents"
56
57
  *
57
58
  * @param filePath - The file path to process
59
+ * @param options - Options to control the file name extraction
58
60
  * @returns The folder containing the file
59
61
  */
60
- export declare function findFolderName(filePath: string): string;
62
+ export declare function findFolderName(filePath: string, options?: FindFileNameOptions): string;
61
63
  export declare const basename: typeof findFolderName;
62
64
  /**
63
65
  * Find the file extension from a file path.
@@ -1 +1 @@
1
- import{isSetString as d}from"@stryke/type-checks/is-set-string";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)}
1
+ import{isSetString as d}from"@stryke/type-checks/is-set-string";import{EMPTY_STRING as a}from"@stryke/types/base";import{normalizeString as p,normalizeWindowsPath as l}from"./correct-path";import{cwd as u}from"./cwd";import{isAbsolute as g,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(".")?a:n===!1&&i.includes(".")?i.replace(`.${findFileExtension(i)??""}`,"")||a:i}export function findFilePath(e,t={}){const r=l(e),n=r.replace(findFileName(r,{requireExtension:!1,...t}),"");return n==="/"?n:n.replace(/\/$/,"")}export const dirname=findFilePath;export function findFolderName(e,t){const r=findFilePath(e,t).split("/");let n="";for(let i=r.length-1;i>=0;i--){const o=r[i];if(o){n=o;break}}return n??a}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)??a}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=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=p(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=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(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)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.21.5",
3
+ "version": "0.22.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": {
@@ -11,9 +11,9 @@
11
11
  "private": false,
12
12
  "devDependencies": {
13
13
  "@storm-software/testing-tools": "^1.119.50",
14
- "@stryke/convert": "^0.6.11",
15
- "@stryke/type-checks": "^0.4.2",
16
- "@stryke/types": "^0.10.11"
14
+ "@stryke/convert": "^0.6.13",
15
+ "@stryke/type-checks": "^0.4.4",
16
+ "@stryke/types": "^0.10.13"
17
17
  },
18
18
  "publishConfig": { "access": "public" },
19
19
  "dependencies": {},
@@ -280,5 +280,5 @@
280
280
  "main": "./dist/index.cjs",
281
281
  "module": "./dist/index.mjs",
282
282
  "types": "./dist/index.d.ts",
283
- "gitHead": "4f9ec36edfefa375090353856bca8d00e4e778e2"
283
+ "gitHead": "eb28313b3230b7ea654c87586ca07773e2e57f52"
284
284
  }