@stryke/path 0.3.0 → 0.3.2
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.
|
@@ -20,24 +20,24 @@ var _getWorkspaceRoot = require("../workspace/get-workspace-root.cjs");
|
|
|
20
20
|
var _isFile = require("./is-file.cjs");
|
|
21
21
|
var _joinPaths = require("./join-paths.cjs");
|
|
22
22
|
var _normalizePath = require("./normalize-path.cjs");
|
|
23
|
-
function findFileName(
|
|
23
|
+
function findFileName(n, {
|
|
24
24
|
requireExtension: e,
|
|
25
25
|
withExtension: r
|
|
26
26
|
} = {}) {
|
|
27
|
-
const
|
|
28
|
-
return e === !0 && !
|
|
27
|
+
const t = (0, _normalizePath.normalizeWindowsPath)(n)?.split(n?.includes("\\") ? "\\" : "/")?.pop() ?? "";
|
|
28
|
+
return e === !0 && !t.includes(".") ? _base.EMPTY_STRING : r === !1 && t.includes(".") ? t.split(".").slice(-1).join(".") || _base.EMPTY_STRING : t;
|
|
29
29
|
}
|
|
30
|
-
function findFilePath(
|
|
31
|
-
const e = (0, _normalizePath.normalizeWindowsPath)(
|
|
30
|
+
function findFilePath(n) {
|
|
31
|
+
const e = (0, _normalizePath.normalizeWindowsPath)(n);
|
|
32
32
|
return e.replace(findFileName(e, {
|
|
33
33
|
requireExtension: !0
|
|
34
34
|
}), "");
|
|
35
35
|
}
|
|
36
|
-
function findFolderName(
|
|
37
|
-
const e = findFilePath(
|
|
36
|
+
function findFolderName(n) {
|
|
37
|
+
const e = findFilePath(n).split("/");
|
|
38
38
|
let r = "";
|
|
39
|
-
for (let
|
|
40
|
-
const i = e[
|
|
39
|
+
for (let t = e.length - 1; t >= 0; t--) {
|
|
40
|
+
const i = e[t];
|
|
41
41
|
if (i) {
|
|
42
42
|
r = i;
|
|
43
43
|
break;
|
|
@@ -45,52 +45,52 @@ function findFolderName(t) {
|
|
|
45
45
|
}
|
|
46
46
|
return r ?? _base.EMPTY_STRING;
|
|
47
47
|
}
|
|
48
|
-
function findFileExtension(
|
|
49
|
-
if (
|
|
50
|
-
const e = /.(\.[^./]+|\.)$/.exec((0, _normalizePath.normalizeWindowsPath)(
|
|
48
|
+
function findFileExtension(n) {
|
|
49
|
+
if (n === "..") return "";
|
|
50
|
+
const e = /.(\.[^./]+|\.)$/.exec((0, _normalizePath.normalizeWindowsPath)(n));
|
|
51
51
|
return e && e[1] || _base.EMPTY_STRING;
|
|
52
52
|
}
|
|
53
|
-
function hasFileName(
|
|
54
|
-
return !!findFileName(
|
|
53
|
+
function hasFileName(n) {
|
|
54
|
+
return !!findFileName(n);
|
|
55
55
|
}
|
|
56
|
-
function hasFilePath(
|
|
57
|
-
return !!findFilePath(
|
|
56
|
+
function hasFilePath(n) {
|
|
57
|
+
return !!findFilePath(n);
|
|
58
58
|
}
|
|
59
|
-
function resolvePath(
|
|
60
|
-
const r = (0, _normalizePath.normalizeWindowsPath)(
|
|
61
|
-
let
|
|
59
|
+
function resolvePath(n, e = (0, _getWorkspaceRoot.getWorkspaceRoot)()) {
|
|
60
|
+
const r = (0, _normalizePath.normalizeWindowsPath)(n).split("/");
|
|
61
|
+
let t = "",
|
|
62
62
|
i = !1;
|
|
63
63
|
for (let o = r.length - 1; o >= -1 && !i; o--) {
|
|
64
64
|
const s = o >= 0 ? r[o] : e;
|
|
65
|
-
!s || s.length === 0 || (
|
|
65
|
+
!s || s.length === 0 || (t = (0, _joinPaths.joinPaths)(s, t), i = (0, _isFile.isAbsolutePath)(s));
|
|
66
66
|
}
|
|
67
|
-
return
|
|
67
|
+
return t = (0, _normalizePath.normalizeString)(t, !i), i && !(0, _isFile.isAbsolutePath)(t) ? `/${t}` : t.length > 0 ? t : ".";
|
|
68
68
|
}
|
|
69
|
-
function resolvePaths(...
|
|
70
|
-
return resolvePath((0, _joinPaths.joinPaths)(...
|
|
69
|
+
function resolvePaths(...n) {
|
|
70
|
+
return resolvePath((0, _joinPaths.joinPaths)(...n.map(e => (0, _normalizePath.normalizeWindowsPath)(e))));
|
|
71
71
|
}
|
|
72
|
-
function relativePath(
|
|
73
|
-
const r = resolvePath(
|
|
74
|
-
|
|
75
|
-
if (
|
|
72
|
+
function relativePath(n, e) {
|
|
73
|
+
const r = resolvePath(n).replace(/^\/([A-Z]:)?$/i, "$1").split("/"),
|
|
74
|
+
t = resolvePath(e).replace(/^\/([A-Z]:)?$/i, "$1").split("/");
|
|
75
|
+
if (t[0][1] === ":" && r[0][1] === ":" && r[0] !== t[0]) return t.join("/");
|
|
76
76
|
const i = [...r];
|
|
77
77
|
for (const o of i) {
|
|
78
|
-
if (
|
|
79
|
-
r.shift(),
|
|
78
|
+
if (t[0] !== o) break;
|
|
79
|
+
r.shift(), t.shift();
|
|
80
80
|
}
|
|
81
|
-
return [...r.map(() => ".."), ...
|
|
81
|
+
return [...r.map(() => ".."), ...t].join("/");
|
|
82
82
|
}
|
|
83
|
-
function relativeToWorkspaceRoot(
|
|
84
|
-
return relativePath(
|
|
83
|
+
function relativeToWorkspaceRoot(n) {
|
|
84
|
+
return relativePath(n, (0, _getWorkspaceRoot.getWorkspaceRoot)());
|
|
85
85
|
}
|
|
86
|
-
function parsePath(
|
|
87
|
-
const e = /^[/\\]|^[a-z]:[/\\]/i.exec(
|
|
88
|
-
r = (0, _normalizePath.normalizeWindowsPath)(
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
function parsePath(n) {
|
|
87
|
+
const e = /^[/\\]|^[a-z]:[/\\]/i.exec(n)?.[0]?.replace(/\\/g, "/") || "",
|
|
88
|
+
r = (0, _normalizePath.normalizeWindowsPath)(n),
|
|
89
|
+
t = r.replace(/\/$/, "").split("/").slice(0, -1);
|
|
90
|
+
t.length === 1 && /^[A-Z]:$/i.test(t[0]) && (t[0] += "/");
|
|
91
91
|
const i = findFolderName(r),
|
|
92
|
-
o =
|
|
93
|
-
s = findFileExtension(
|
|
92
|
+
o = t.join("/") || ((0, _isFile.isAbsolutePath)(n) ? "/" : "."),
|
|
93
|
+
s = findFileExtension(n);
|
|
94
94
|
return {
|
|
95
95
|
root: e,
|
|
96
96
|
dir: o,
|
|
@@ -99,7 +99,7 @@ function parsePath(t) {
|
|
|
99
99
|
name: i.slice(0, i.length - s.length)
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
|
-
function renameFile(
|
|
103
|
-
const r = parsePath(
|
|
102
|
+
function renameFile(n, e) {
|
|
103
|
+
const r = parsePath(n);
|
|
104
104
|
return (0, _joinPaths.joinPaths)(r.dir, e.includes(".") ? e : e + r.ext);
|
|
105
105
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EMPTY_STRING as a}from"@stryke/types/utility-types/base";import{getWorkspaceRoot as f}from"../workspace/get-workspace-root";import{isAbsolutePath as c}from"./is-file";import{joinPaths as u}from"./join-paths";import{normalizeString as
|
|
1
|
+
import{EMPTY_STRING as a}from"@stryke/types/utility-types/base";import{getWorkspaceRoot as f}from"../workspace/get-workspace-root";import{isAbsolutePath as c}from"./is-file";import{joinPaths as u}from"./join-paths";import{normalizeString as p,normalizeWindowsPath as l}from"./normalize-path";export function findFileName(n,{requireExtension:e,withExtension:r}={}){const t=l(n)?.split(n?.includes("\\")?"\\":"/")?.pop()??"";return e===!0&&!t.includes(".")?a:r===!1&&t.includes(".")?t.split(".").slice(-1).join(".")||a:t}export function findFilePath(n){const e=l(n);return e.replace(findFileName(e,{requireExtension:!0}),"")}export function findFolderName(n){const e=findFilePath(n).split("/");let r="";for(let t=e.length-1;t>=0;t--){const i=e[t];if(i){r=i;break}}return r??a}export function findFileExtension(n){if(n==="..")return"";const e=/.(\.[^./]+|\.)$/.exec(l(n));return e&&e[1]||a}export function hasFileName(n){return!!findFileName(n)}export function hasFilePath(n){return!!findFilePath(n)}export function resolvePath(n,e=f()){const r=l(n).split("/");let t="",i=!1;for(let o=r.length-1;o>=-1&&!i;o--){const s=o>=0?r[o]:e;!s||s.length===0||(t=u(s,t),i=c(s))}return t=p(t,!i),i&&!c(t)?`/${t}`:t.length>0?t:"."}export function resolvePaths(...n){return resolvePath(u(...n.map(e=>l(e))))}export function relativePath(n,e){const r=resolvePath(n).replace(/^\/([A-Z]:)?$/i,"$1").split("/"),t=resolvePath(e).replace(/^\/([A-Z]:)?$/i,"$1").split("/");if(t[0][1]===":"&&r[0][1]===":"&&r[0]!==t[0])return t.join("/");const i=[...r];for(const o of i){if(t[0]!==o)break;r.shift(),t.shift()}return[...r.map(()=>".."),...t].join("/")}export function relativeToWorkspaceRoot(n){return relativePath(n,f())}export function parsePath(n){const e=/^[/\\]|^[a-z]:[/\\]/i.exec(n)?.[0]?.replace(/\\/g,"/")||"",r=l(n),t=r.replace(/\/$/,"").split("/").slice(0,-1);t.length===1&&/^[A-Z]:$/i.test(t[0])&&(t[0]+="/");const i=findFolderName(r),o=t.join("/")||(c(n)?"/":"."),s=findFileExtension(n);return{root:e,dir:o,base:i,ext:s,name:i.slice(0,i.length-s.length)}}export function renameFile(n,e){const r=parsePath(n);return u(r.dir,e.includes(".")?e:e+r.ext)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/path",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing various utilities that expand the functionality of NodeJs's `path` module",
|
|
6
6
|
"repository": {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@storm-software/config-tools": "latest",
|
|
14
14
|
"mlly": "1.7.4",
|
|
15
|
-
"@stryke/types": ">=0.5.
|
|
15
|
+
"@stryke/types": ">=0.5.1"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": { "@types/node": "^22.13.1" },
|
|
18
18
|
"publishConfig": { "access": "public" },
|
|
@@ -110,34 +110,6 @@
|
|
|
110
110
|
"default": "./dist/workspace/asset-extensions.mjs"
|
|
111
111
|
}
|
|
112
112
|
},
|
|
113
|
-
"./resolve/resolve": {
|
|
114
|
-
"import": {
|
|
115
|
-
"types": "./dist/resolve/resolve.d.ts",
|
|
116
|
-
"default": "./dist/resolve/resolve.mjs"
|
|
117
|
-
},
|
|
118
|
-
"require": {
|
|
119
|
-
"types": "./dist/resolve/resolve.d.ts",
|
|
120
|
-
"default": "./dist/resolve/resolve.cjs"
|
|
121
|
-
},
|
|
122
|
-
"default": {
|
|
123
|
-
"types": "./dist/resolve/resolve.d.ts",
|
|
124
|
-
"default": "./dist/resolve/resolve.mjs"
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
"./resolve/index": {
|
|
128
|
-
"import": {
|
|
129
|
-
"types": "./dist/resolve/index.d.ts",
|
|
130
|
-
"default": "./dist/resolve/index.mjs"
|
|
131
|
-
},
|
|
132
|
-
"require": {
|
|
133
|
-
"types": "./dist/resolve/index.d.ts",
|
|
134
|
-
"default": "./dist/resolve/index.cjs"
|
|
135
|
-
},
|
|
136
|
-
"default": {
|
|
137
|
-
"types": "./dist/resolve/index.d.ts",
|
|
138
|
-
"default": "./dist/resolve/index.mjs"
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
113
|
"./utilities/normalize-path": {
|
|
142
114
|
"import": {
|
|
143
115
|
"types": "./dist/utilities/normalize-path.d.ts",
|
|
@@ -264,6 +236,34 @@
|
|
|
264
236
|
"default": "./dist/utilities/delimiter.mjs"
|
|
265
237
|
}
|
|
266
238
|
},
|
|
239
|
+
"./resolve/resolve": {
|
|
240
|
+
"import": {
|
|
241
|
+
"types": "./dist/resolve/resolve.d.ts",
|
|
242
|
+
"default": "./dist/resolve/resolve.mjs"
|
|
243
|
+
},
|
|
244
|
+
"require": {
|
|
245
|
+
"types": "./dist/resolve/resolve.d.ts",
|
|
246
|
+
"default": "./dist/resolve/resolve.cjs"
|
|
247
|
+
},
|
|
248
|
+
"default": {
|
|
249
|
+
"types": "./dist/resolve/resolve.d.ts",
|
|
250
|
+
"default": "./dist/resolve/resolve.mjs"
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
"./resolve/index": {
|
|
254
|
+
"import": {
|
|
255
|
+
"types": "./dist/resolve/index.d.ts",
|
|
256
|
+
"default": "./dist/resolve/index.mjs"
|
|
257
|
+
},
|
|
258
|
+
"require": {
|
|
259
|
+
"types": "./dist/resolve/index.d.ts",
|
|
260
|
+
"default": "./dist/resolve/index.cjs"
|
|
261
|
+
},
|
|
262
|
+
"default": {
|
|
263
|
+
"types": "./dist/resolve/index.d.ts",
|
|
264
|
+
"default": "./dist/resolve/index.mjs"
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
267
|
".": {
|
|
268
268
|
"import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" },
|
|
269
269
|
"require": {
|
|
@@ -286,20 +286,6 @@
|
|
|
286
286
|
"default": "./dist/workspace/index.mjs"
|
|
287
287
|
}
|
|
288
288
|
},
|
|
289
|
-
"./resolve": {
|
|
290
|
-
"import": {
|
|
291
|
-
"types": "./dist/resolve/index.d.ts",
|
|
292
|
-
"default": "./dist/resolve/index.mjs"
|
|
293
|
-
},
|
|
294
|
-
"require": {
|
|
295
|
-
"types": "./dist/resolve/index.d.ts",
|
|
296
|
-
"default": "./dist/resolve/index.cjs"
|
|
297
|
-
},
|
|
298
|
-
"default": {
|
|
299
|
-
"types": "./dist/resolve/index.d.ts",
|
|
300
|
-
"default": "./dist/resolve/index.mjs"
|
|
301
|
-
}
|
|
302
|
-
},
|
|
303
289
|
"./utilities": {
|
|
304
290
|
"import": {
|
|
305
291
|
"types": "./dist/utilities/index.d.ts",
|
|
@@ -314,6 +300,20 @@
|
|
|
314
300
|
"default": "./dist/utilities/index.mjs"
|
|
315
301
|
}
|
|
316
302
|
},
|
|
303
|
+
"./resolve": {
|
|
304
|
+
"import": {
|
|
305
|
+
"types": "./dist/resolve/index.d.ts",
|
|
306
|
+
"default": "./dist/resolve/index.mjs"
|
|
307
|
+
},
|
|
308
|
+
"require": {
|
|
309
|
+
"types": "./dist/resolve/index.d.ts",
|
|
310
|
+
"default": "./dist/resolve/index.cjs"
|
|
311
|
+
},
|
|
312
|
+
"default": {
|
|
313
|
+
"types": "./dist/resolve/index.d.ts",
|
|
314
|
+
"default": "./dist/resolve/index.mjs"
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
317
|
"./package.json": "./package.json"
|
|
318
318
|
},
|
|
319
319
|
"main": "./dist/index.cjs",
|