@stryke/path 0.18.5 → 0.19.1
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/correct-path.cjs +22 -17
- package/dist/correct-path.d.ts +7 -0
- package/dist/correct-path.mjs +1 -1
- package/package.json +6 -6
package/dist/correct-path.cjs
CHANGED
|
@@ -9,31 +9,32 @@ exports.normalizeWindowsPath = normalizeWindowsPath;
|
|
|
9
9
|
exports.stripStars = stripStars;
|
|
10
10
|
exports.toAbsolutePath = toAbsolutePath;
|
|
11
11
|
exports.toRelativePath = toRelativePath;
|
|
12
|
+
exports.withTrailingSlash = withTrailingSlash;
|
|
12
13
|
var _cwd = require("./cwd.cjs");
|
|
13
14
|
var _isType = require("./is-type.cjs");
|
|
14
15
|
var _joinPaths = require("./join-paths.cjs");
|
|
15
16
|
var _regex = require("./regex.cjs");
|
|
16
17
|
var _slash = require("./slash.cjs");
|
|
17
18
|
function normalizeWindowsPath(e = "") {
|
|
18
|
-
return e && (0, _slash.slash)(e).replace(_regex.DRIVE_LETTER_START_REGEX,
|
|
19
|
+
return e && (0, _slash.slash)(e).replace(_regex.DRIVE_LETTER_START_REGEX, n => n.toUpperCase());
|
|
19
20
|
}
|
|
20
21
|
function correctPath(e) {
|
|
21
22
|
if (!e || e.length === 0) return ".";
|
|
22
23
|
e = normalizeWindowsPath(e);
|
|
23
|
-
const
|
|
24
|
+
const n = e.match(_regex.UNC_REGEX),
|
|
24
25
|
r = (0, _isType.isAbsolutePath)(e),
|
|
25
|
-
|
|
26
|
-
return e = normalizeString(e, !r), e.length === 0 ? r ? "/" :
|
|
26
|
+
t = e.endsWith("/");
|
|
27
|
+
return e = normalizeString(e, !r), e.length === 0 ? r ? "/" : t ? "./" : "." : (t && (e += "/"), _regex.DRIVE_LETTER_REGEX.test(e) && (e += "/"), n ? r ? `//${e}` : `//./${e}` : !e.startsWith("/") && r && !_regex.DRIVE_LETTER_REGEX.test(e) ? `/${e}` : e);
|
|
27
28
|
}
|
|
28
29
|
function stripStars(e) {
|
|
29
30
|
if (!e || e.length === 0) return ".";
|
|
30
31
|
e = correctPath(e);
|
|
31
|
-
let
|
|
32
|
-
return e.split("/").reduce((r,
|
|
32
|
+
let n = !1;
|
|
33
|
+
return e.split("/").reduce((r, t) => t?.trim() ? n || t.includes("*") ? (n = !0, r) : r + (r ? `/${t}` : t) : r, "");
|
|
33
34
|
}
|
|
34
|
-
function normalizeString(e,
|
|
35
|
+
function normalizeString(e, n) {
|
|
35
36
|
let r = "",
|
|
36
|
-
|
|
37
|
+
t = 0,
|
|
37
38
|
l = -1,
|
|
38
39
|
s = 0,
|
|
39
40
|
o = null;
|
|
@@ -44,26 +45,30 @@ function normalizeString(e, t) {
|
|
|
44
45
|
}
|
|
45
46
|
if (o === "/") {
|
|
46
47
|
if (!(l === i - 1 || s === 1)) if (s === 2) {
|
|
47
|
-
if (r.length < 2 ||
|
|
48
|
+
if (r.length < 2 || t !== 2 || r[r.length - 1] !== "." || r[r.length - 2] !== ".") {
|
|
48
49
|
if (r.length > 2) {
|
|
49
50
|
const c = r.lastIndexOf("/");
|
|
50
|
-
c === -1 ? (r = "",
|
|
51
|
+
c === -1 ? (r = "", t = 0) : (r = r.slice(0, c), t = r.length - 1 - r.lastIndexOf("/")), l = i, s = 0;
|
|
51
52
|
continue;
|
|
52
53
|
} else if (r.length > 0) {
|
|
53
|
-
r = "",
|
|
54
|
+
r = "", t = 0, l = i, s = 0;
|
|
54
55
|
continue;
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
} else r.length > 0 ? r += `/${e.slice(l + 1, i)}` : r = e.slice(l + 1, i),
|
|
58
|
+
n && (r += r.length > 0 ? "/.." : "..", t = 2);
|
|
59
|
+
} else r.length > 0 ? r += `/${e.slice(l + 1, i)}` : r = e.slice(l + 1, i), t = i - l - 1;
|
|
59
60
|
l = i, s = 0;
|
|
60
61
|
} else o === "." && s !== -1 ? ++s : s = -1;
|
|
61
62
|
}
|
|
62
63
|
return r;
|
|
63
64
|
}
|
|
64
|
-
function toAbsolutePath(e,
|
|
65
|
-
return (0, _isType.isAbsolutePath)(e) ? e : (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(
|
|
65
|
+
function toAbsolutePath(e, n) {
|
|
66
|
+
return (0, _isType.isAbsolutePath)(e) ? e : (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(n || process.cwd(), e), !0));
|
|
66
67
|
}
|
|
67
|
-
function toRelativePath(e,
|
|
68
|
-
return !e || e.length === 0 ? "." : ((0, _isType.isAbsolutePath)(e) ? e = (0, _slash.slash)(normalizeString(e, !0)) : e = (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(
|
|
68
|
+
function toRelativePath(e, n = (0, _cwd.cwd)()) {
|
|
69
|
+
return !e || e.length === 0 ? "." : ((0, _isType.isAbsolutePath)(e) ? e = (0, _slash.slash)(normalizeString(e, !0)) : e = (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(n, e), !0)), e.startsWith("./") ? e.slice(2) : e);
|
|
70
|
+
}
|
|
71
|
+
function withTrailingSlash(e) {
|
|
72
|
+
const n = correctPath(e);
|
|
73
|
+
return n.endsWith("/") ? n : `${n}/`;
|
|
69
74
|
}
|
package/dist/correct-path.d.ts
CHANGED
|
@@ -46,3 +46,10 @@ export declare function toAbsolutePath(path: string, cwd?: string): string;
|
|
|
46
46
|
* @returns The relative path.
|
|
47
47
|
*/
|
|
48
48
|
export declare function toRelativePath(path: string, cwd?: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Adds a trailing slash to a path if it doesn't already have one.
|
|
51
|
+
*
|
|
52
|
+
* @param path - The path to modify.
|
|
53
|
+
* @returns The modified path with a trailing slash.
|
|
54
|
+
*/
|
|
55
|
+
export declare function withTrailingSlash(path: string): string;
|
package/dist/correct-path.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cwd as m}from"./cwd";import{isAbsolutePath as u}from"./is-type";import{joinPaths as g}from"./join-paths";import{DRIVE_LETTER_REGEX as d,DRIVE_LETTER_START_REGEX as E,UNC_REGEX as x}from"./regex";import{slash as f}from"./slash";export function normalizeWindowsPath(e=""){return e&&f(e).replace(E,
|
|
1
|
+
import{cwd as m}from"./cwd";import{isAbsolutePath as u}from"./is-type";import{joinPaths as g}from"./join-paths";import{DRIVE_LETTER_REGEX as d,DRIVE_LETTER_START_REGEX as E,UNC_REGEX as x}from"./regex";import{slash as f}from"./slash";export function normalizeWindowsPath(e=""){return e&&f(e).replace(E,n=>n.toUpperCase())}export function correctPath(e){if(!e||e.length===0)return".";e=normalizeWindowsPath(e);const n=e.match(x),r=u(e),t=e.endsWith("/");return e=normalizeString(e,!r),e.length===0?r?"/":t?"./":".":(t&&(e+="/"),d.test(e)&&(e+="/"),n?r?`//${e}`:`//./${e}`:!e.startsWith("/")&&r&&!d.test(e)?`/${e}`:e)}export function stripStars(e){if(!e||e.length===0)return".";e=correctPath(e);let n=!1;return e.split("/").reduce((r,t)=>t?.trim()?n||t.includes("*")?(n=!0,r):r+(r?`/${t}`:t):r,"")}export function normalizeString(e,n){let r="",t=0,l=-1,s=0,o=null;for(let i=0;i<=e.length;++i){if(i<e.length)o=e[i];else{if(o==="/")break;o="/"}if(o==="/"){if(!(l===i-1||s===1))if(s===2){if(r.length<2||t!==2||r[r.length-1]!=="."||r[r.length-2]!=="."){if(r.length>2){const c=r.lastIndexOf("/");c===-1?(r="",t=0):(r=r.slice(0,c),t=r.length-1-r.lastIndexOf("/")),l=i,s=0;continue}else if(r.length>0){r="",t=0,l=i,s=0;continue}}n&&(r+=r.length>0?"/..":"..",t=2)}else r.length>0?r+=`/${e.slice(l+1,i)}`:r=e.slice(l+1,i),t=i-l-1;l=i,s=0}else o==="."&&s!==-1?++s:s=-1}return r}export function toAbsolutePath(e,n){return u(e)?e:f(normalizeString(g(n||process.cwd(),e),!0))}export function toRelativePath(e,n=m()){return!e||e.length===0?".":(u(e)?e=f(normalizeString(e,!0)):e=f(normalizeString(g(n,e),!0)),e.startsWith("./")?e.slice(2):e)}export function withTrailingSlash(e){const n=correctPath(e);return n.endsWith("/")?n:`${n}/`}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/path",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.1",
|
|
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,10 +10,10 @@
|
|
|
10
10
|
},
|
|
11
11
|
"private": false,
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"@storm-software/testing-tools": "^1.119.
|
|
14
|
-
"@stryke/convert": "^0.6.
|
|
15
|
-
"@stryke/type-checks": "^0.3.
|
|
16
|
-
"@stryke/types": "^0.10.
|
|
13
|
+
"@storm-software/testing-tools": "^1.119.38",
|
|
14
|
+
"@stryke/convert": "^0.6.2",
|
|
15
|
+
"@stryke/type-checks": "^0.3.12",
|
|
16
|
+
"@stryke/types": "^0.10.2"
|
|
17
17
|
},
|
|
18
18
|
"publishConfig": { "access": "public" },
|
|
19
19
|
"dependencies": {},
|
|
@@ -294,5 +294,5 @@
|
|
|
294
294
|
"main": "./dist/index.cjs",
|
|
295
295
|
"module": "./dist/index.mjs",
|
|
296
296
|
"types": "./dist/index.d.ts",
|
|
297
|
-
"gitHead": "
|
|
297
|
+
"gitHead": "6772e4e88d48af5c80a74dcc8f6eafafc8ce77d1"
|
|
298
298
|
}
|