@stryke/path 0.4.14 → 0.5.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.
@@ -7,20 +7,24 @@ exports.resolveParentPath = exports.getParentPath = void 0;
7
7
  var _filePathFns = require("./file-path-fns.cjs");
8
8
  var _isFile = require("./is-file.cjs");
9
9
  var _joinPaths = require("./join-paths.cjs");
10
- const resolveParentPath = r => (0, _filePathFns.resolvePaths)(r, ".."),
11
- getParentPath = (r, a, o) => {
12
- const p = o?.ignoreCase ?? !0,
13
- l = o?.skipCwd ?? !1,
14
- e = o?.targetType ?? "both";
15
- let t = a;
16
- l && (t = resolveParentPath(a));
17
- let n = Array.isArray(r) ? r : [r];
18
- for (p && (n = n.map(i => i.toLowerCase()));;) {
19
- const i = n.find(g => (0, _isFile.isFile)((0, _joinPaths.joinPaths)(t, g)) && (e === "file" || e === "both") || (0, _isFile.isDirectory)((0, _joinPaths.joinPaths)(t, g)) && (e === "directory" || e === "both"));
20
- if (i) return (0, _joinPaths.joinPaths)(t, i);
21
- const f = resolveParentPath(t);
22
- if (f === t) return;
23
- t = f;
10
+ const resolveParentPath = (r, i = 1) => {
11
+ let t = r;
12
+ for (let o = 0; o < i; o++) t = (0, _filePathFns.resolvePaths)(t, "..");
13
+ return t;
14
+ },
15
+ getParentPath = (r, i, t) => {
16
+ const o = t?.ignoreCase ?? !0,
17
+ l = t?.skipCwd ?? !1,
18
+ n = t?.targetType ?? "both";
19
+ let e = i;
20
+ l && (e = resolveParentPath(i));
21
+ let a = Array.isArray(r) ? r : [r];
22
+ for (o && (a = a.map(s => s.toLowerCase()));;) {
23
+ const s = a.find(g => (0, _isFile.isFile)((0, _joinPaths.joinPaths)(e, g)) && (n === "file" || n === "both") || (0, _isFile.isDirectory)((0, _joinPaths.joinPaths)(e, g)) && (n === "directory" || n === "both"));
24
+ if (s) return (0, _joinPaths.joinPaths)(e, s);
25
+ const p = resolveParentPath(e);
26
+ if (p === e) return;
27
+ e = p;
24
28
  }
25
29
  };
26
30
  exports.getParentPath = getParentPath;
@@ -2,9 +2,10 @@
2
2
  * Resolve the parent path of the provided path.
3
3
  *
4
4
  * @param path - The path to resolve.
5
+ * @param count - The number of parent directories to traverse.
5
6
  * @returns The parent path of the provided path.
6
7
  */
7
- export declare const resolveParentPath: (path: string) => string;
8
+ export declare const resolveParentPath: (path: string, count?: number) => string;
8
9
  /**
9
10
  * Options for the `getParentPath` function.
10
11
  */
@@ -1 +1 @@
1
- import{resolvePaths as h}from"./file-path-fns";import{isDirectory as P,isFile as c}from"./is-file";import{joinPaths as s}from"./join-paths";export const resolveParentPath=r=>h(r,".."),getParentPath=(r,a,o)=>{const p=o?.ignoreCase??!0,l=o?.skipCwd??!1,e=o?.targetType??"both";let t=a;l&&(t=resolveParentPath(a));let n=Array.isArray(r)?r:[r];for(p&&(n=n.map(i=>i.toLowerCase()));;){const i=n.find(g=>c(s(t,g))&&(e==="file"||e==="both")||P(s(t,g))&&(e==="directory"||e==="both"));if(i)return s(t,i);const f=resolveParentPath(t);if(f===t)return;t=f}};
1
+ import{resolvePaths as h}from"./file-path-fns";import{isDirectory as P,isFile as c}from"./is-file";import{joinPaths as f}from"./join-paths";export const resolveParentPath=(r,i=1)=>{let t=r;for(let o=0;o<i;o++)t=h(t,"..");return t},getParentPath=(r,i,t)=>{const o=t?.ignoreCase??!0,l=t?.skipCwd??!1,n=t?.targetType??"both";let e=i;l&&(e=resolveParentPath(i));let a=Array.isArray(r)?r:[r];for(o&&(a=a.map(s=>s.toLowerCase()));;){const s=a.find(g=>c(f(e,g))&&(n==="file"||n==="both")||P(f(e,g))&&(n==="directory"||n==="both"));if(s)return f(e,s);const p=resolveParentPath(e);if(p===e)return;e=p}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.4.14",
3
+ "version": "0.5.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": {
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "private": false,
12
12
  "dependencies": { "@storm-software/config-tools": "latest", "mlly": "1.7.4" },
13
- "devDependencies": { "@stryke/types": "^0.8.3", "@types/node": "^22.13.1" },
13
+ "devDependencies": { "@stryke/types": "^0.8.3", "@types/node": "^22.14.0" },
14
14
  "publishConfig": { "access": "public" },
15
15
  "sideEffects": false,
16
16
  "files": ["dist/**/*"],