@stryke/path 0.18.4 → 0.19.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.
- package/dist/append.cjs +1 -1
- package/dist/append.mjs +1 -1
- package/dist/correct-path.cjs +22 -17
- package/dist/correct-path.d.ts +7 -0
- package/dist/correct-path.mjs +1 -1
- package/dist/is-parent-path.cjs +4 -4
- package/dist/is-parent-path.mjs +1 -1
- package/dist/replace.cjs +4 -5
- package/dist/replace.mjs +1 -1
- package/package.json +6 -6
package/dist/append.cjs
CHANGED
|
@@ -10,6 +10,6 @@ var _isParentPath = require("./is-parent-path.cjs");
|
|
|
10
10
|
var _joinPaths = require("./join-paths.cjs");
|
|
11
11
|
var _slash = require("./slash.cjs");
|
|
12
12
|
function appendPath(r, o = (0, _cwd.cwd)()) {
|
|
13
|
-
return (0, _slash.
|
|
13
|
+
return (0, _slash.slash)((0, _isParentPath.isParentPath)(r, o) ? r : (0, _joinPaths.joinPaths)(o, r));
|
|
14
14
|
}
|
|
15
15
|
const append = exports.append = appendPath;
|
package/dist/append.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cwd as t}from"./cwd";import{isParentPath as n}from"./is-parent-path";import{joinPaths as
|
|
1
|
+
import{cwd as t}from"./cwd";import{isParentPath as n}from"./is-parent-path";import{joinPaths as p}from"./join-paths";import{slash as i}from"./slash";export function appendPath(r,o=t()){return i(n(r,o)?r:p(o,r))}export const append=appendPath;
|
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/dist/is-parent-path.cjs
CHANGED
|
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.isParentPath = isParentPath;
|
|
7
7
|
var _slash = require("./slash.cjs");
|
|
8
|
-
function isParentPath(
|
|
9
|
-
const r = (0, _slash.
|
|
10
|
-
|
|
11
|
-
return
|
|
8
|
+
function isParentPath(a, n) {
|
|
9
|
+
const r = (0, _slash.slash)(a.replace(/\\/g, "/").replace(/\/$/, "")),
|
|
10
|
+
e = (0, _slash.slash)(n.replace(/\\/g, "/").replace(/\/$/, ""));
|
|
11
|
+
return r !== e && r.startsWith(`${e}/`);
|
|
12
12
|
}
|
package/dist/is-parent-path.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{slash as t}from"./slash";export function isParentPath(a,n){const r=t(a.replace(/\\/g,"/").replace(/\/$/,"")),e=t(n.replace(/\\/g,"/").replace(/\/$/,""));return r!==e&&r.startsWith(`${e}/`)}
|
package/dist/replace.cjs
CHANGED
|
@@ -5,14 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.replaceExtension = replaceExtension;
|
|
7
7
|
exports.replacePath = replacePath;
|
|
8
|
-
var _correctPath = require("./correct-path.cjs");
|
|
9
8
|
var _cwd = require("./cwd.cjs");
|
|
10
9
|
var _filePathFns = require("./file-path-fns.cjs");
|
|
11
10
|
var _isParentPath = require("./is-parent-path.cjs");
|
|
12
11
|
var _slash = require("./slash.cjs");
|
|
13
|
-
function replacePath(r,
|
|
14
|
-
return (0,
|
|
12
|
+
function replacePath(r, i = (0, _cwd.cwd)()) {
|
|
13
|
+
return (0, _isParentPath.isParentPath)(r, i) ? (0, _slash.slash)(r).replace((0, _slash.slash)(i), "").replace(/^\//, "") : r;
|
|
15
14
|
}
|
|
16
|
-
function replaceExtension(r,
|
|
17
|
-
return
|
|
15
|
+
function replaceExtension(r, i = "") {
|
|
16
|
+
return r.replace(!i || i.includes(".") ? (0, _filePathFns.findFileDotExtensionSafe)(r) : (0, _filePathFns.findFileExtensionSafe)(r), i);
|
|
18
17
|
}
|
package/dist/replace.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{cwd as e}from"./cwd";import{findFileDotExtensionSafe as o,findFileExtensionSafe as t}from"./file-path-fns";import{isParentPath as s}from"./is-parent-path";import{slash as n}from"./slash";export function replacePath(r,i=e()){return s(r,i)?n(r).replace(n(i),"").replace(/^\//,""):r}export function replaceExtension(r,i=""){return r.replace(!i||i.includes(".")?o(r):t(r),i)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/path",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.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,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.19",
|
|
14
|
+
"@stryke/convert": "^0.6.1",
|
|
15
|
+
"@stryke/type-checks": "^0.3.11",
|
|
16
|
+
"@stryke/types": "^0.10.1"
|
|
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": "906d6304c09a8964297fa784f96377535fca6769"
|
|
298
298
|
}
|