@stryke/path 0.7.3 → 0.7.4
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 +25 -25
- package/dist/file-path-fns.d.ts +6 -1
- package/dist/file-path-fns.mjs +1 -1
- package/package.json +1 -1
package/dist/file-path-fns.cjs
CHANGED
|
@@ -23,30 +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:
|
|
27
|
-
withExtension:
|
|
26
|
+
requireExtension: n = !1,
|
|
27
|
+
withExtension: r = !0
|
|
28
28
|
} = e,
|
|
29
29
|
i = (0, _correctPath.normalizeWindowsPath)(t)?.split(t?.includes("\\") ? "\\" : "/")?.pop() ?? "";
|
|
30
|
-
return
|
|
30
|
+
return n === !0 && !i.includes(".") ? _base.EMPTY_STRING : r === !1 && i.includes(".") ? i.split(".").slice(-1).join(".") || _base.EMPTY_STRING : i;
|
|
31
31
|
}
|
|
32
32
|
function findFilePath(t) {
|
|
33
33
|
const e = (0, _correctPath.normalizeWindowsPath)(t),
|
|
34
|
-
|
|
34
|
+
n = e.replace(findFileName(e, {
|
|
35
35
|
requireExtension: !0
|
|
36
36
|
}), "");
|
|
37
|
-
return
|
|
37
|
+
return n === "/" ? n : n.replace(/\/$/, "");
|
|
38
38
|
}
|
|
39
39
|
function findFolderName(t) {
|
|
40
40
|
const e = findFilePath(t).split("/");
|
|
41
|
-
let
|
|
42
|
-
for (let
|
|
43
|
-
const i = e[
|
|
41
|
+
let n = "";
|
|
42
|
+
for (let r = e.length - 1; r >= 0; r--) {
|
|
43
|
+
const i = e[r];
|
|
44
44
|
if (i) {
|
|
45
|
-
|
|
45
|
+
n = i;
|
|
46
46
|
break;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
return
|
|
49
|
+
return n ?? _base.EMPTY_STRING;
|
|
50
50
|
}
|
|
51
51
|
function findFileExtension(t) {
|
|
52
52
|
if (t === "..") return "";
|
|
@@ -60,31 +60,31 @@ function hasFilePath(t) {
|
|
|
60
60
|
return !!findFilePath(t);
|
|
61
61
|
}
|
|
62
62
|
function resolvePath(t, e = (0, _getWorkspaceRoot.getWorkspaceRoot)()) {
|
|
63
|
-
const
|
|
64
|
-
let
|
|
63
|
+
const n = (0, _correctPath.normalizeWindowsPath)(t).split("/");
|
|
64
|
+
let r = "",
|
|
65
65
|
i = !1;
|
|
66
|
-
for (let s =
|
|
67
|
-
const o = s >= 0 ?
|
|
68
|
-
!o || o.length === 0 || (
|
|
66
|
+
for (let s = n.length - 1; s >= -1 && !i; s--) {
|
|
67
|
+
const o = s >= 0 ? n[s] : e;
|
|
68
|
+
!o || o.length === 0 || (r = (0, _joinPaths.joinPaths)(o, r), i = (0, _isFile.isAbsolutePath)(o));
|
|
69
69
|
}
|
|
70
|
-
return
|
|
70
|
+
return r = (0, _correctPath.normalizeString)(r, !i), i && !(0, _isFile.isAbsolutePath)(r) ? `/${r}` : r.length > 0 ? r : ".";
|
|
71
71
|
}
|
|
72
72
|
function resolvePaths(...t) {
|
|
73
73
|
return resolvePath((0, _joinPaths.joinPaths)(...t.map(e => (0, _correctPath.normalizeWindowsPath)(e))));
|
|
74
74
|
}
|
|
75
|
-
function relativePath(t, e) {
|
|
76
|
-
return (0, _nodePath.relative)(t.replace(/\/$/, ""), e.replace(/\/$/, ""));
|
|
75
|
+
function relativePath(t, e, n = !1) {
|
|
76
|
+
return (0, _nodePath.relative)(n !== !0 ? t.replace(/\/$/, "") : t, n !== !0 ? e.replace(/\/$/, "") : e);
|
|
77
77
|
}
|
|
78
78
|
function relativeToWorkspaceRoot(t) {
|
|
79
79
|
return relativePath(t, (0, _getWorkspaceRoot.getWorkspaceRoot)());
|
|
80
80
|
}
|
|
81
81
|
function parsePath(t) {
|
|
82
82
|
const e = /^[/\\]|^[a-z]:[/\\]/i.exec(t)?.[0]?.replace(/\\/g, "/") || "",
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const i = findFolderName(
|
|
87
|
-
s =
|
|
83
|
+
n = (0, _correctPath.normalizeWindowsPath)(t),
|
|
84
|
+
r = n.replace(/\/$/, "").split("/").slice(0, -1);
|
|
85
|
+
r.length === 1 && /^[A-Z]:$/i.test(r[0]) && (r[0] += "/");
|
|
86
|
+
const i = findFolderName(n),
|
|
87
|
+
s = r.join("/") || ((0, _isFile.isAbsolutePath)(t) ? "/" : "."),
|
|
88
88
|
o = findFileExtension(t);
|
|
89
89
|
return {
|
|
90
90
|
root: e,
|
|
@@ -95,6 +95,6 @@ function parsePath(t) {
|
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
function renameFile(t, e) {
|
|
98
|
-
const
|
|
99
|
-
return (0, _joinPaths.joinPaths)(
|
|
98
|
+
const n = parsePath(t);
|
|
99
|
+
return (0, _joinPaths.joinPaths)(n.dir, e.includes(".") ? e : e + n.ext);
|
|
100
100
|
}
|
package/dist/file-path-fns.d.ts
CHANGED
|
@@ -96,8 +96,13 @@ export declare function resolvePaths(...paths: string[]): string;
|
|
|
96
96
|
*
|
|
97
97
|
* @remarks
|
|
98
98
|
* This function wraps the `path.relative` function in Node's path module.
|
|
99
|
+
*
|
|
100
|
+
* @param from - The base path to start from
|
|
101
|
+
* @param to - The target path to resolve relative to the base path
|
|
102
|
+
* @param withEndSlash - Whether to include a trailing slash at the end of the path
|
|
103
|
+
* @returns The relative path from the base path to the target path
|
|
99
104
|
*/
|
|
100
|
-
export declare function relativePath(from: string, to: string): string;
|
|
105
|
+
export declare function relativePath(from: string, to: string, withEndSlash?: boolean): string;
|
|
101
106
|
/**
|
|
102
107
|
* Find the file path relative to the workspace root path.
|
|
103
108
|
*
|
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:n=!1,withExtension:r=!0}=e,i=l(t)?.split(t?.includes("\\")?"\\":"/")?.pop()??"";return n===!0&&!i.includes(".")?a:r===!1&&i.includes(".")?i.split(".").slice(-1).join(".")||a:i}export function findFilePath(t){const e=l(t),n=e.replace(findFileName(e,{requireExtension:!0}),"");return n==="/"?n:n.replace(/\/$/,"")}export function findFolderName(t){const e=findFilePath(t).split("/");let n="";for(let r=e.length-1;r>=0;r--){const i=e[r];if(i){n=i;break}}return n??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 n=l(t).split("/");let r="",i=!1;for(let s=n.length-1;s>=-1&&!i;s--){const o=s>=0?n[s]:e;!o||o.length===0||(r=u(o,r),i=c(o))}return r=g(r,!i),i&&!c(r)?`/${r}`:r.length>0?r:"."}export function resolvePaths(...t){return resolvePath(u(...t.map(e=>l(e))))}export function relativePath(t,e,n=!1){return f(n!==!0?t.replace(/\/$/,""):t,n!==!0?e.replace(/\/$/,""):e)}export function relativeToWorkspaceRoot(t){return relativePath(t,p())}export function parsePath(t){const e=/^[/\\]|^[a-z]:[/\\]/i.exec(t)?.[0]?.replace(/\\/g,"/")||"",n=l(t),r=n.replace(/\/$/,"").split("/").slice(0,-1);r.length===1&&/^[A-Z]:$/i.test(r[0])&&(r[0]+="/");const i=findFolderName(n),s=r.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 n=parsePath(t);return u(n.dir,e.includes(".")?e:e+n.ext)}
|