@stryke/path 0.17.0 → 0.18.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/correct-path.cjs +27 -20
- package/dist/correct-path.d.ts +16 -0
- package/dist/correct-path.mjs +1 -1
- package/dist/replace.cjs +3 -2
- package/dist/replace.mjs +1 -1
- package/package.json +2 -2
package/dist/correct-path.cjs
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.correctPath = correctPath;
|
|
7
7
|
exports.normalizeString = normalizeString;
|
|
8
8
|
exports.normalizeWindowsPath = normalizeWindowsPath;
|
|
9
|
+
exports.stripStars = stripStars;
|
|
9
10
|
exports.toAbsolutePath = toAbsolutePath;
|
|
10
11
|
exports.toRelativePath = toRelativePath;
|
|
11
12
|
var _cwd = require("./cwd.cjs");
|
|
@@ -14,49 +15,55 @@ var _joinPaths = require("./join-paths.cjs");
|
|
|
14
15
|
var _regex = require("./regex.cjs");
|
|
15
16
|
var _slash = require("./slash.cjs");
|
|
16
17
|
function normalizeWindowsPath(e = "") {
|
|
17
|
-
return e && (0, _slash.slash)(e).replace(_regex.DRIVE_LETTER_START_REGEX,
|
|
18
|
+
return e && (0, _slash.slash)(e).replace(_regex.DRIVE_LETTER_START_REGEX, t => t.toUpperCase());
|
|
18
19
|
}
|
|
19
20
|
function correctPath(e) {
|
|
20
21
|
if (!e || e.length === 0) return ".";
|
|
21
22
|
e = normalizeWindowsPath(e);
|
|
22
|
-
const
|
|
23
|
+
const t = e.match(_regex.UNC_REGEX),
|
|
23
24
|
r = (0, _isType.isAbsolutePath)(e),
|
|
24
|
-
|
|
25
|
-
return e = normalizeString(e, !r), e.length === 0 ? r ? "/" :
|
|
25
|
+
n = e.endsWith("/");
|
|
26
|
+
return e = normalizeString(e, !r), e.length === 0 ? r ? "/" : n ? "./" : "." : (n && (e += "/"), _regex.DRIVE_LETTER_REGEX.test(e) && (e += "/"), t ? r ? `//${e}` : `//./${e}` : !e.startsWith("/") && r && !_regex.DRIVE_LETTER_REGEX.test(e) ? `/${e}` : e);
|
|
26
27
|
}
|
|
27
|
-
function
|
|
28
|
+
function stripStars(e) {
|
|
29
|
+
if (!e || e.length === 0) return ".";
|
|
30
|
+
e = correctPath(e);
|
|
31
|
+
let t = !1;
|
|
32
|
+
return e.split("/").reduce((r, n) => n?.trim() ? t || n.includes("*") ? (t = !0, r) : r + (r.length > 0 ? `/${n}` : n) : r, "");
|
|
33
|
+
}
|
|
34
|
+
function normalizeString(e, t) {
|
|
28
35
|
let r = "",
|
|
29
|
-
|
|
36
|
+
n = 0,
|
|
30
37
|
l = -1,
|
|
31
38
|
s = 0,
|
|
32
39
|
o = null;
|
|
33
|
-
for (let
|
|
34
|
-
if (
|
|
40
|
+
for (let i = 0; i <= e.length; ++i) {
|
|
41
|
+
if (i < e.length) o = e[i];else {
|
|
35
42
|
if (o === "/") break;
|
|
36
43
|
o = "/";
|
|
37
44
|
}
|
|
38
45
|
if (o === "/") {
|
|
39
|
-
if (!(l ===
|
|
40
|
-
if (r.length < 2 ||
|
|
46
|
+
if (!(l === i - 1 || s === 1)) if (s === 2) {
|
|
47
|
+
if (r.length < 2 || n !== 2 || r[r.length - 1] !== "." || r[r.length - 2] !== ".") {
|
|
41
48
|
if (r.length > 2) {
|
|
42
|
-
const
|
|
43
|
-
|
|
49
|
+
const c = r.lastIndexOf("/");
|
|
50
|
+
c === -1 ? (r = "", n = 0) : (r = r.slice(0, c), n = r.length - 1 - r.lastIndexOf("/")), l = i, s = 0;
|
|
44
51
|
continue;
|
|
45
52
|
} else if (r.length > 0) {
|
|
46
|
-
r = "",
|
|
53
|
+
r = "", n = 0, l = i, s = 0;
|
|
47
54
|
continue;
|
|
48
55
|
}
|
|
49
56
|
}
|
|
50
|
-
|
|
51
|
-
} else r.length > 0 ? r += `/${e.slice(l + 1,
|
|
52
|
-
l =
|
|
57
|
+
t && (r += r.length > 0 ? "/.." : "..", n = 2);
|
|
58
|
+
} else r.length > 0 ? r += `/${e.slice(l + 1, i)}` : r = e.slice(l + 1, i), n = i - l - 1;
|
|
59
|
+
l = i, s = 0;
|
|
53
60
|
} else o === "." && s !== -1 ? ++s : s = -1;
|
|
54
61
|
}
|
|
55
62
|
return r;
|
|
56
63
|
}
|
|
57
|
-
function toAbsolutePath(e,
|
|
58
|
-
return (0, _isType.isAbsolutePath)(e) ? e : (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(
|
|
64
|
+
function toAbsolutePath(e, t) {
|
|
65
|
+
return (0, _isType.isAbsolutePath)(e) ? e : (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(t || process.cwd(), e), !0));
|
|
59
66
|
}
|
|
60
|
-
function toRelativePath(e,
|
|
61
|
-
return !e || e.length === 0 ? "." : ((0, _isType.isAbsolutePath)(e) ? e = (0, _slash.slash)(normalizeString(e, !0)) : e = (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(
|
|
67
|
+
function toRelativePath(e, t = (0, _cwd.cwd)()) {
|
|
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)(t, e), !0)), e.startsWith("./") ? e.slice(2) : e);
|
|
62
69
|
}
|
package/dist/correct-path.d.ts
CHANGED
|
@@ -6,6 +6,22 @@ export declare function normalizeWindowsPath(input?: string): string;
|
|
|
6
6
|
* @returns The corrected path.
|
|
7
7
|
*/
|
|
8
8
|
export declare function correctPath(path?: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Remove any star tokens (*) from the end of the file path
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* stripStars("src/**") // returns "src"
|
|
14
|
+
* stripStars("src/*") // returns "src"
|
|
15
|
+
* stripStars("src/**\/*") // returns "src"
|
|
16
|
+
* stripStars("src/**\/*.txt") // returns "src"
|
|
17
|
+
* stripStars("src/**\/file.txt") // returns "src"
|
|
18
|
+
* stripStars("src/file.txt") // returns "src/file.txt"
|
|
19
|
+
* stripStars("") // returns "."
|
|
20
|
+
*
|
|
21
|
+
* @param path - The path to correct.
|
|
22
|
+
* @returns The corrected path.
|
|
23
|
+
*/
|
|
24
|
+
export declare function stripStars(path?: string): string;
|
|
9
25
|
/**
|
|
10
26
|
* Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.
|
|
11
27
|
*
|
package/dist/correct-path.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cwd as
|
|
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,t=>t.toUpperCase())}export function correctPath(e){if(!e||e.length===0)return".";e=normalizeWindowsPath(e);const t=e.match(x),r=u(e),n=e.endsWith("/");return e=normalizeString(e,!r),e.length===0?r?"/":n?"./":".":(n&&(e+="/"),d.test(e)&&(e+="/"),t?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 t=!1;return e.split("/").reduce((r,n)=>n?.trim()?t||n.includes("*")?(t=!0,r):r+(r.length>0?`/${n}`:n):r,"")}export function normalizeString(e,t){let r="",n=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||n!==2||r[r.length-1]!=="."||r[r.length-2]!=="."){if(r.length>2){const c=r.lastIndexOf("/");c===-1?(r="",n=0):(r=r.slice(0,c),n=r.length-1-r.lastIndexOf("/")),l=i,s=0;continue}else if(r.length>0){r="",n=0,l=i,s=0;continue}}t&&(r+=r.length>0?"/..":"..",n=2)}else r.length>0?r+=`/${e.slice(l+1,i)}`:r=e.slice(l+1,i),n=i-l-1;l=i,s=0}else o==="."&&s!==-1?++s:s=-1}return r}export function toAbsolutePath(e,t){return u(e)?e:f(normalizeString(g(t||process.cwd(),e),!0))}export function toRelativePath(e,t=m()){return!e||e.length===0?".":(u(e)?e=f(normalizeString(e,!0)):e=f(normalizeString(g(t,e),!0)),e.startsWith("./")?e.slice(2):e)}
|
package/dist/replace.cjs
CHANGED
|
@@ -5,13 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.replaceExtension = replaceExtension;
|
|
7
7
|
exports.replacePath = replacePath;
|
|
8
|
+
var _correctPath = require("./correct-path.cjs");
|
|
8
9
|
var _cwd = require("./cwd.cjs");
|
|
9
10
|
var _filePathFns = require("./file-path-fns.cjs");
|
|
10
11
|
var _isParentPath = require("./is-parent-path.cjs");
|
|
11
12
|
var _slash = require("./slash.cjs");
|
|
12
13
|
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;
|
|
14
|
+
return (0, _correctPath.correctPath)((0, _isParentPath.isParentPath)(r, i) ? (0, _slash.slash)(r).replace((0, _slash.slash)(i), "").replace(/^\//, "") : r);
|
|
14
15
|
}
|
|
15
16
|
function replaceExtension(r, i = "") {
|
|
16
|
-
return r.replace(!i || i.includes(".") ? (0, _filePathFns.findFileDotExtensionSafe)(r) : (0, _filePathFns.findFileExtensionSafe)(r), i);
|
|
17
|
+
return (0, _correctPath.correctPath)(r.replace(!i || i.includes(".") ? (0, _filePathFns.findFileDotExtensionSafe)(r) : (0, _filePathFns.findFileExtensionSafe)(r), i));
|
|
17
18
|
}
|
package/dist/replace.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cwd as e}from"./cwd";import{findFileDotExtensionSafe as
|
|
1
|
+
import{correctPath as o}from"./correct-path";import{cwd as e}from"./cwd";import{findFileDotExtensionSafe as t,findFileExtensionSafe as s}from"./file-path-fns";import{isParentPath as f}from"./is-parent-path";import{slash as n}from"./slash";export function replacePath(r,i=e()){return o(f(r,i)?n(r).replace(n(i),"").replace(/^\//,""):r)}export function replaceExtension(r,i=""){return o(r.replace(!i||i.includes(".")?t(r):s(r),i))}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/path",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.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": {
|
|
@@ -279,5 +279,5 @@
|
|
|
279
279
|
"main": "./dist/index.cjs",
|
|
280
280
|
"module": "./dist/index.mjs",
|
|
281
281
|
"types": "./dist/index.d.ts",
|
|
282
|
-
"gitHead": "
|
|
282
|
+
"gitHead": "04107da5bbf439fe7e705783009e18fc5080a4fe"
|
|
283
283
|
}
|