@stryke/path 0.7.1 → 0.7.3
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.
- package/dist/file-path-fns.cjs +26 -25
- package/dist/file-path-fns.mjs +1 -1
- package/dist/get-parent-path.cjs +11 -12
- package/dist/get-parent-path.mjs +1 -1
- package/package.json +1 -1
package/dist/file-path-fns.cjs
CHANGED
|
@@ -23,29 +23,30 @@ var _isFile = require("./is-file.cjs");
|
|
|
23
23
|
var _joinPaths = require("./join-paths.cjs");
|
|
24
24
|
function findFileName(t, e = {}) {
|
|
25
25
|
const {
|
|
26
|
-
requireExtension:
|
|
26
|
+
requireExtension: r = !1,
|
|
27
27
|
withExtension: n = !0
|
|
28
28
|
} = e,
|
|
29
|
-
|
|
30
|
-
return
|
|
29
|
+
i = (0, _correctPath.normalizeWindowsPath)(t)?.split(t?.includes("\\") ? "\\" : "/")?.pop() ?? "";
|
|
30
|
+
return r === !0 && !i.includes(".") ? _base.EMPTY_STRING : n === !1 && i.includes(".") ? i.split(".").slice(-1).join(".") || _base.EMPTY_STRING : i;
|
|
31
31
|
}
|
|
32
32
|
function findFilePath(t) {
|
|
33
|
-
const e = (0, _correctPath.normalizeWindowsPath)(t)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
const e = (0, _correctPath.normalizeWindowsPath)(t),
|
|
34
|
+
r = e.replace(findFileName(e, {
|
|
35
|
+
requireExtension: !0
|
|
36
|
+
}), "");
|
|
37
|
+
return r === "/" ? r : r.replace(/\/$/, "");
|
|
37
38
|
}
|
|
38
39
|
function findFolderName(t) {
|
|
39
40
|
const e = findFilePath(t).split("/");
|
|
40
|
-
let
|
|
41
|
+
let r = "";
|
|
41
42
|
for (let n = e.length - 1; n >= 0; n--) {
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
|
|
43
|
+
const i = e[n];
|
|
44
|
+
if (i) {
|
|
45
|
+
r = i;
|
|
45
46
|
break;
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
|
-
return
|
|
49
|
+
return r ?? _base.EMPTY_STRING;
|
|
49
50
|
}
|
|
50
51
|
function findFileExtension(t) {
|
|
51
52
|
if (t === "..") return "";
|
|
@@ -59,14 +60,14 @@ function hasFilePath(t) {
|
|
|
59
60
|
return !!findFilePath(t);
|
|
60
61
|
}
|
|
61
62
|
function resolvePath(t, e = (0, _getWorkspaceRoot.getWorkspaceRoot)()) {
|
|
62
|
-
const
|
|
63
|
+
const r = (0, _correctPath.normalizeWindowsPath)(t).split("/");
|
|
63
64
|
let n = "",
|
|
64
|
-
|
|
65
|
-
for (let s =
|
|
66
|
-
const o = s >= 0 ?
|
|
67
|
-
!o || o.length === 0 || (n = (0, _joinPaths.joinPaths)(o, n),
|
|
65
|
+
i = !1;
|
|
66
|
+
for (let s = r.length - 1; s >= -1 && !i; s--) {
|
|
67
|
+
const o = s >= 0 ? r[s] : e;
|
|
68
|
+
!o || o.length === 0 || (n = (0, _joinPaths.joinPaths)(o, n), i = (0, _isFile.isAbsolutePath)(o));
|
|
68
69
|
}
|
|
69
|
-
return n = (0, _correctPath.normalizeString)(n, !
|
|
70
|
+
return n = (0, _correctPath.normalizeString)(n, !i), i && !(0, _isFile.isAbsolutePath)(n) ? `/${n}` : n.length > 0 ? n : ".";
|
|
70
71
|
}
|
|
71
72
|
function resolvePaths(...t) {
|
|
72
73
|
return resolvePath((0, _joinPaths.joinPaths)(...t.map(e => (0, _correctPath.normalizeWindowsPath)(e))));
|
|
@@ -79,21 +80,21 @@ function relativeToWorkspaceRoot(t) {
|
|
|
79
80
|
}
|
|
80
81
|
function parsePath(t) {
|
|
81
82
|
const e = /^[/\\]|^[a-z]:[/\\]/i.exec(t)?.[0]?.replace(/\\/g, "/") || "",
|
|
82
|
-
|
|
83
|
-
n =
|
|
83
|
+
r = (0, _correctPath.normalizeWindowsPath)(t),
|
|
84
|
+
n = r.replace(/\/$/, "").split("/").slice(0, -1);
|
|
84
85
|
n.length === 1 && /^[A-Z]:$/i.test(n[0]) && (n[0] += "/");
|
|
85
|
-
const
|
|
86
|
+
const i = findFolderName(r),
|
|
86
87
|
s = n.join("/") || ((0, _isFile.isAbsolutePath)(t) ? "/" : "."),
|
|
87
88
|
o = findFileExtension(t);
|
|
88
89
|
return {
|
|
89
90
|
root: e,
|
|
90
91
|
dir: s,
|
|
91
|
-
base:
|
|
92
|
+
base: i,
|
|
92
93
|
ext: o,
|
|
93
|
-
name:
|
|
94
|
+
name: i.slice(0, i.length - o.length)
|
|
94
95
|
};
|
|
95
96
|
}
|
|
96
97
|
function renameFile(t, e) {
|
|
97
|
-
const
|
|
98
|
-
return (0, _joinPaths.joinPaths)(
|
|
98
|
+
const r = parsePath(t);
|
|
99
|
+
return (0, _joinPaths.joinPaths)(r.dir, e.includes(".") ? e : e + r.ext);
|
|
99
100
|
}
|
package/dist/file-path-fns.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EMPTY_STRING as a}from"@stryke/types/base";import{relative as f}from"node:path";import{normalizeString as g,normalizeWindowsPath as l}from"./correct-path";import{getWorkspaceRoot as p}from"./get-workspace-root";import{isAbsolutePath as c}from"./is-file";import{joinPaths as u}from"./join-paths";export function findFileName(t,e={}){const{requireExtension:
|
|
1
|
+
import{EMPTY_STRING as a}from"@stryke/types/base";import{relative as f}from"node:path";import{normalizeString as g,normalizeWindowsPath as l}from"./correct-path";import{getWorkspaceRoot as p}from"./get-workspace-root";import{isAbsolutePath as c}from"./is-file";import{joinPaths as u}from"./join-paths";export function findFileName(t,e={}){const{requireExtension:r=!1,withExtension:n=!0}=e,i=l(t)?.split(t?.includes("\\")?"\\":"/")?.pop()??"";return r===!0&&!i.includes(".")?a:n===!1&&i.includes(".")?i.split(".").slice(-1).join(".")||a:i}export function findFilePath(t){const e=l(t),r=e.replace(findFileName(e,{requireExtension:!0}),"");return r==="/"?r:r.replace(/\/$/,"")}export function findFolderName(t){const e=findFilePath(t).split("/");let r="";for(let n=e.length-1;n>=0;n--){const i=e[n];if(i){r=i;break}}return r??a}export function findFileExtension(t){if(t==="..")return"";const e=/.(\.[^./]+|\.)$/.exec(l(t));return e&&e[1]||a}export function hasFileName(t){return!!findFileName(t)}export function hasFilePath(t){return!!findFilePath(t)}export function resolvePath(t,e=p()){const r=l(t).split("/");let n="",i=!1;for(let s=r.length-1;s>=-1&&!i;s--){const o=s>=0?r[s]:e;!o||o.length===0||(n=u(o,n),i=c(o))}return n=g(n,!i),i&&!c(n)?`/${n}`:n.length>0?n:"."}export function resolvePaths(...t){return resolvePath(u(...t.map(e=>l(e))))}export function relativePath(t,e){return f(t.replace(/\/$/,""),e.replace(/\/$/,""))}export function relativeToWorkspaceRoot(t){return relativePath(t,p())}export function parsePath(t){const e=/^[/\\]|^[a-z]:[/\\]/i.exec(t)?.[0]?.replace(/\\/g,"/")||"",r=l(t),n=r.replace(/\/$/,"").split("/").slice(0,-1);n.length===1&&/^[A-Z]:$/i.test(n[0])&&(n[0]+="/");const i=findFolderName(r),s=n.join("/")||(c(t)?"/":"."),o=findFileExtension(t);return{root:e,dir:s,base:i,ext:o,name:i.slice(0,i.length-o.length)}}export function renameFile(t,e){const r=parsePath(t);return u(r.dir,e.includes(".")?e:e+r.ext)}
|
package/dist/get-parent-path.cjs
CHANGED
|
@@ -4,27 +4,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.resolveParentPath = exports.getParentPath = void 0;
|
|
7
|
-
var _filePathFns = require("./file-path-fns.cjs");
|
|
8
7
|
var _isFile = require("./is-file.cjs");
|
|
9
8
|
var _joinPaths = require("./join-paths.cjs");
|
|
10
9
|
const resolveParentPath = (r, i = 1) => {
|
|
11
10
|
let t = r.replaceAll(/\/+$/g, "");
|
|
12
|
-
for (let
|
|
11
|
+
for (let n = 0; n < i; n++) t = (0, _joinPaths.joinPaths)(t, "..");
|
|
13
12
|
return t;
|
|
14
13
|
},
|
|
15
14
|
getParentPath = (r, i, t) => {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const n = t?.ignoreCase ?? !0,
|
|
16
|
+
f = t?.skipCwd ?? !1,
|
|
17
|
+
o = t?.targetType ?? "both";
|
|
19
18
|
let e = i;
|
|
20
|
-
|
|
21
|
-
let
|
|
22
|
-
for (
|
|
23
|
-
const a =
|
|
19
|
+
f && (e = resolveParentPath(i));
|
|
20
|
+
let l = Array.isArray(r) ? r : [r];
|
|
21
|
+
for (n && (l = l.map(a => a.toLowerCase()));;) {
|
|
22
|
+
const a = l.find(p => (0, _isFile.isFile)((0, _joinPaths.joinPaths)(e, p)) && (o === "file" || o === "both") || (0, _isFile.isDirectory)((0, _joinPaths.joinPaths)(e, p)) && (o === "directory" || o === "both"));
|
|
24
23
|
if (a) return (0, _joinPaths.joinPaths)(e, a);
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
e =
|
|
24
|
+
const g = resolveParentPath(e);
|
|
25
|
+
if (g === e) return;
|
|
26
|
+
e = g;
|
|
28
27
|
}
|
|
29
28
|
};
|
|
30
29
|
exports.getParentPath = getParentPath;
|
package/dist/get-parent-path.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{isDirectory as c,isFile as h}from"./is-file";import{joinPaths as s}from"./join-paths";export const resolveParentPath=(r,i=1)=>{let t=r.replaceAll(/\/+$/g,"");for(let n=0;n<i;n++)t=s(t,"..");return t},getParentPath=(r,i,t)=>{const n=t?.ignoreCase??!0,f=t?.skipCwd??!1,o=t?.targetType??"both";let e=i;f&&(e=resolveParentPath(i));let l=Array.isArray(r)?r:[r];for(n&&(l=l.map(a=>a.toLowerCase()));;){const a=l.find(p=>h(s(e,p))&&(o==="file"||o==="both")||c(s(e,p))&&(o==="directory"||o==="both"));if(a)return s(e,a);const g=resolveParentPath(e);if(g===e)return;e=g}};
|