@stryke/path 0.4.10 → 0.4.11
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 +16 -21
- package/dist/correct-path.d.ts +0 -7
- package/dist/correct-path.mjs +1 -1
- package/dist/index.cjs +22 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +1 -1
- package/dist/is-file.cjs +6 -4
- package/dist/is-file.d.ts +6 -6
- package/dist/is-file.mjs +1 -1
- package/dist/regex.cjs +10 -0
- package/dist/regex.d.ts +4 -0
- package/dist/regex.mjs +1 -0
- package/dist/slash.cjs +9 -0
- package/dist/slash.d.ts +7 -0
- package/dist/slash.mjs +1 -0
- package/package.json +17 -1
package/dist/correct-path.cjs
CHANGED
|
@@ -6,51 +6,46 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.correctPath = correctPath;
|
|
7
7
|
exports.normalizeString = normalizeString;
|
|
8
8
|
exports.normalizeWindowsPath = normalizeWindowsPath;
|
|
9
|
-
exports.slash = slash;
|
|
10
9
|
var _isFile = require("./is-file.cjs");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
const c = /^[A-Z]:\//i;
|
|
10
|
+
var _regex = require("./regex.cjs");
|
|
11
|
+
var _slash = require("./slash.cjs");
|
|
15
12
|
function normalizeWindowsPath(e = "") {
|
|
16
|
-
return e &&
|
|
13
|
+
return e && (0, _slash.slash)(e).replace(_regex.DRIVE_LETTER_START_REGEX, s => s.toUpperCase());
|
|
17
14
|
}
|
|
18
|
-
const u = /^[/\\]{2}/,
|
|
19
|
-
E = /^[A-Z]:$/i;
|
|
20
15
|
function correctPath(e) {
|
|
21
16
|
if (!e || e.length === 0) return ".";
|
|
22
17
|
e = normalizeWindowsPath(e);
|
|
23
|
-
const s = e.match(
|
|
18
|
+
const s = e.match(_regex.UNC_REGEX),
|
|
24
19
|
n = (0, _isFile.isAbsolutePath)(e),
|
|
25
|
-
|
|
26
|
-
return e = normalizeString(e, !n), e.length === 0 ? n ? "/" :
|
|
20
|
+
l = e.endsWith("/");
|
|
21
|
+
return e = normalizeString(e, !n), e.length === 0 ? n ? "/" : l ? "./" : "." : (l && (e += "/"), _regex.DRIVE_LETTER_REGEX.test(e) && (e += "/"), s ? n ? `//${e}` : `//./${e}` : !e.startsWith("/") && n && !_regex.DRIVE_LETTER_REGEX.test(e) ? `/${e}` : e);
|
|
27
22
|
}
|
|
28
23
|
function normalizeString(e, s) {
|
|
29
24
|
let n = "",
|
|
30
|
-
|
|
25
|
+
l = 0,
|
|
31
26
|
i = -1,
|
|
32
27
|
r = 0,
|
|
33
28
|
o = null;
|
|
34
|
-
for (let
|
|
35
|
-
if (
|
|
29
|
+
for (let t = 0; t <= e.length; ++t) {
|
|
30
|
+
if (t < e.length) o = e[t];else {
|
|
36
31
|
if (o === "/") break;
|
|
37
32
|
o = "/";
|
|
38
33
|
}
|
|
39
34
|
if (o === "/") {
|
|
40
|
-
if (!(i ===
|
|
41
|
-
if (n.length < 2 ||
|
|
35
|
+
if (!(i === t - 1 || r === 1)) if (r === 2) {
|
|
36
|
+
if (n.length < 2 || l !== 2 || n[n.length - 1] !== "." || n[n.length - 2] !== ".") {
|
|
42
37
|
if (n.length > 2) {
|
|
43
38
|
const f = n.lastIndexOf("/");
|
|
44
|
-
f === -1 ? (n = "",
|
|
39
|
+
f === -1 ? (n = "", l = 0) : (n = n.slice(0, f), l = n.length - 1 - n.lastIndexOf("/")), i = t, r = 0;
|
|
45
40
|
continue;
|
|
46
41
|
} else if (n.length > 0) {
|
|
47
|
-
n = "",
|
|
42
|
+
n = "", l = 0, i = t, r = 0;
|
|
48
43
|
continue;
|
|
49
44
|
}
|
|
50
45
|
}
|
|
51
|
-
s && (n += n.length > 0 ? "/.." : "..",
|
|
52
|
-
} else n.length > 0 ? n += `/${e.slice(i + 1,
|
|
53
|
-
i =
|
|
46
|
+
s && (n += n.length > 0 ? "/.." : "..", l = 2);
|
|
47
|
+
} else n.length > 0 ? n += `/${e.slice(i + 1, t)}` : n = e.slice(i + 1, t), l = t - i - 1;
|
|
48
|
+
i = t, r = 0;
|
|
54
49
|
} else o === "." && r !== -1 ? ++r : r = -1;
|
|
55
50
|
}
|
|
56
51
|
return n;
|
package/dist/correct-path.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Replace backslash to slash
|
|
3
|
-
*
|
|
4
|
-
* @param str - The string to replace
|
|
5
|
-
* @returns The string with replaced backslashes
|
|
6
|
-
*/
|
|
7
|
-
export declare function slash(str: string): string;
|
|
8
1
|
export declare function normalizeWindowsPath(input?: string): string;
|
|
9
2
|
/**
|
|
10
3
|
* Corrects/normalized a file path.
|
package/dist/correct-path.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isAbsolutePath as
|
|
1
|
+
import{isAbsolutePath as c}from"./is-file";import{DRIVE_LETTER_REGEX as g,DRIVE_LETTER_START_REGEX as u,UNC_REGEX as E}from"./regex";import{slash as m}from"./slash";export function normalizeWindowsPath(e=""){return e&&m(e).replace(u,s=>s.toUpperCase())}export function correctPath(e){if(!e||e.length===0)return".";e=normalizeWindowsPath(e);const s=e.match(E),n=c(e),l=e.endsWith("/");return e=normalizeString(e,!n),e.length===0?n?"/":l?"./":".":(l&&(e+="/"),g.test(e)&&(e+="/"),s?n?`//${e}`:`//./${e}`:!e.startsWith("/")&&n&&!g.test(e)?`/${e}`:e)}export function normalizeString(e,s){let n="",l=0,i=-1,r=0,o=null;for(let t=0;t<=e.length;++t){if(t<e.length)o=e[t];else{if(o==="/")break;o="/"}if(o==="/"){if(!(i===t-1||r===1))if(r===2){if(n.length<2||l!==2||n[n.length-1]!=="."||n[n.length-2]!=="."){if(n.length>2){const f=n.lastIndexOf("/");f===-1?(n="",l=0):(n=n.slice(0,f),l=n.length-1-n.lastIndexOf("/")),i=t,r=0;continue}else if(n.length>0){n="",l=0,i=t,r=0;continue}}s&&(n+=n.length>0?"/..":"..",l=2)}else n.length>0?n+=`/${e.slice(i+1,t)}`:n=e.slice(i+1,t),l=t-i-1;i=t,r=0}else o==="."&&r!==-1?++r:r=-1}return n}
|
package/dist/index.cjs
CHANGED
|
@@ -113,6 +113,17 @@ Object.keys(_joinPaths).forEach(function (key) {
|
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
115
|
});
|
|
116
|
+
var _regex = require("./regex.cjs");
|
|
117
|
+
Object.keys(_regex).forEach(function (key) {
|
|
118
|
+
if (key === "default" || key === "__esModule") return;
|
|
119
|
+
if (key in exports && exports[key] === _regex[key]) return;
|
|
120
|
+
Object.defineProperty(exports, key, {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
get: function () {
|
|
123
|
+
return _regex[key];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
116
127
|
var _resolve = require("./resolve.cjs");
|
|
117
128
|
Object.keys(_resolve).forEach(function (key) {
|
|
118
129
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -123,4 +134,15 @@ Object.keys(_resolve).forEach(function (key) {
|
|
|
123
134
|
return _resolve[key];
|
|
124
135
|
}
|
|
125
136
|
});
|
|
137
|
+
});
|
|
138
|
+
var _slash = require("./slash.cjs");
|
|
139
|
+
Object.keys(_slash).forEach(function (key) {
|
|
140
|
+
if (key === "default" || key === "__esModule") return;
|
|
141
|
+
if (key in exports && exports[key] === _slash[key]) return;
|
|
142
|
+
Object.defineProperty(exports, key, {
|
|
143
|
+
enumerable: true,
|
|
144
|
+
get: function () {
|
|
145
|
+
return _slash[key];
|
|
146
|
+
}
|
|
147
|
+
});
|
|
126
148
|
});
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./asset-extensions";export*from"./correct-path";export*from"./delimiter";export*from"./exists";export*from"./file-path-fns";export*from"./get-parent-path";export*from"./get-workspace-root";export*from"./is-file";export*from"./is-root-dir";export*from"./join-paths";export*from"./resolve";
|
|
1
|
+
export*from"./asset-extensions";export*from"./correct-path";export*from"./delimiter";export*from"./exists";export*from"./file-path-fns";export*from"./get-parent-path";export*from"./get-workspace-root";export*from"./is-file";export*from"./is-root-dir";export*from"./join-paths";export*from"./regex";export*from"./resolve";export*from"./slash";
|
package/dist/is-file.cjs
CHANGED
|
@@ -11,6 +11,8 @@ exports.isFileSymlink = void 0;
|
|
|
11
11
|
exports.isRelativePath = isRelativePath;
|
|
12
12
|
var _nodeFs = require("node:fs");
|
|
13
13
|
var _joinPaths = require("./join-paths.cjs");
|
|
14
|
+
var _regex = require("./regex.cjs");
|
|
15
|
+
var _slash = require("./slash.cjs");
|
|
14
16
|
function isFile(r, o) {
|
|
15
17
|
return !!(0, _nodeFs.statSync)(o ? (0, _joinPaths.joinPaths)(o, r) : r, {
|
|
16
18
|
throwIfNoEntry: !1
|
|
@@ -29,9 +31,9 @@ const isFileSymlink = (r, o) => !!(0, _nodeFs.lstatSync)(o ? (0, _joinPaths.join
|
|
|
29
31
|
})?.isDirectory();
|
|
30
32
|
exports.isDirectorySymlink = isDirectorySymlink;
|
|
31
33
|
exports.isFileSymlink = isFileSymlink;
|
|
32
|
-
function isRelativePath(r) {
|
|
33
|
-
return r === "." || r === ".." || r.startsWith("./") || r.startsWith("../");
|
|
34
|
-
}
|
|
35
34
|
function isAbsolutePath(r) {
|
|
36
|
-
return
|
|
35
|
+
return _regex.ABSOLUTE_PATH_REGEX.test((0, _slash.slash)(r));
|
|
36
|
+
}
|
|
37
|
+
function isRelativePath(r) {
|
|
38
|
+
return !isAbsolutePath(r);
|
|
37
39
|
}
|
package/dist/is-file.d.ts
CHANGED
|
@@ -31,16 +31,16 @@ export declare const isFileSymlink: (path: string, additionalPath?: string) => b
|
|
|
31
31
|
*/
|
|
32
32
|
export declare const isDirectorySymlink: (path: string, additionalPath?: string) => boolean;
|
|
33
33
|
/**
|
|
34
|
-
* Check if the path is
|
|
34
|
+
* Check if the path is an absolute path.
|
|
35
35
|
*
|
|
36
36
|
* @param path - The path to check
|
|
37
|
-
* @returns An indicator specifying if the path is
|
|
37
|
+
* @returns An indicator specifying if the path is an absolute path
|
|
38
38
|
*/
|
|
39
|
-
export declare function
|
|
39
|
+
export declare function isAbsolutePath(path: string): boolean;
|
|
40
40
|
/**
|
|
41
|
-
* Check if the path is
|
|
41
|
+
* Check if the path is a relative path.
|
|
42
42
|
*
|
|
43
43
|
* @param path - The path to check
|
|
44
|
-
* @returns An indicator specifying if the path is
|
|
44
|
+
* @returns An indicator specifying if the path is a relative path
|
|
45
45
|
*/
|
|
46
|
-
export declare function
|
|
46
|
+
export declare function isRelativePath(path: string): boolean;
|
package/dist/is-file.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{lstatSync as n,statSync as e}from"node:fs";import{joinPaths as t}from"./join-paths";export function isFile(r,o){return!!e(o?t(o,r):r,{throwIfNoEntry:!1})?.isFile()}export function isDirectory(r,o){return!!e(o?t(o,r):r,{throwIfNoEntry:!1})?.isDirectory()}export const isFileSymlink=(r,o)=>!!n(o?t(o,r):r,{throwIfNoEntry:!1})?.isFile(),isDirectorySymlink=(r,o)=>!!n(o?t(o,r):r,{throwIfNoEntry:!1})?.isDirectory();export function
|
|
1
|
+
import{lstatSync as n,statSync as e}from"node:fs";import{joinPaths as t}from"./join-paths";import{ABSOLUTE_PATH_REGEX as s}from"./regex";import{slash as i}from"./slash";export function isFile(r,o){return!!e(o?t(o,r):r,{throwIfNoEntry:!1})?.isFile()}export function isDirectory(r,o){return!!e(o?t(o,r):r,{throwIfNoEntry:!1})?.isDirectory()}export const isFileSymlink=(r,o)=>!!n(o?t(o,r):r,{throwIfNoEntry:!1})?.isFile(),isDirectorySymlink=(r,o)=>!!n(o?t(o,r):r,{throwIfNoEntry:!1})?.isDirectory();export function isAbsolutePath(r){return s.test(i(r))}export function isRelativePath(r){return!isAbsolutePath(r)}
|
package/dist/regex.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UNC_REGEX = exports.DRIVE_LETTER_START_REGEX = exports.DRIVE_LETTER_REGEX = exports.ABSOLUTE_PATH_REGEX = void 0;
|
|
7
|
+
const DRIVE_LETTER_START_REGEX = exports.DRIVE_LETTER_START_REGEX = /^[A-Z]:\//i,
|
|
8
|
+
DRIVE_LETTER_REGEX = exports.DRIVE_LETTER_REGEX = /^[A-Z]:$/i,
|
|
9
|
+
UNC_REGEX = exports.UNC_REGEX = /^[/\\]{2}/,
|
|
10
|
+
ABSOLUTE_PATH_REGEX = exports.ABSOLUTE_PATH_REGEX = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i;
|
package/dist/regex.d.ts
ADDED
package/dist/regex.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DRIVE_LETTER_START_REGEX=/^[A-Z]:\//i,DRIVE_LETTER_REGEX=/^[A-Z]:$/i,UNC_REGEX=/^[/\\]{2}/,ABSOLUTE_PATH_REGEX=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^~[/\\]|^[A-Z]:[/\\]/i;
|
package/dist/slash.cjs
ADDED
package/dist/slash.d.ts
ADDED
package/dist/slash.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function slash(r){return r.replace(/\\/g,"/")}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/path",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.11",
|
|
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": {
|
|
@@ -55,6 +55,14 @@
|
|
|
55
55
|
}
|
|
56
56
|
],
|
|
57
57
|
"exports": {
|
|
58
|
+
"./slash": {
|
|
59
|
+
"import": { "types": "./dist/slash.d.ts", "default": "./dist/slash.mjs" },
|
|
60
|
+
"require": {
|
|
61
|
+
"types": "./dist/slash.d.ts",
|
|
62
|
+
"default": "./dist/slash.cjs"
|
|
63
|
+
},
|
|
64
|
+
"default": { "types": "./dist/slash.d.ts", "default": "./dist/slash.mjs" }
|
|
65
|
+
},
|
|
58
66
|
"./resolve": {
|
|
59
67
|
"import": {
|
|
60
68
|
"types": "./dist/resolve.d.ts",
|
|
@@ -69,6 +77,14 @@
|
|
|
69
77
|
"default": "./dist/resolve.mjs"
|
|
70
78
|
}
|
|
71
79
|
},
|
|
80
|
+
"./regex": {
|
|
81
|
+
"import": { "types": "./dist/regex.d.ts", "default": "./dist/regex.mjs" },
|
|
82
|
+
"require": {
|
|
83
|
+
"types": "./dist/regex.d.ts",
|
|
84
|
+
"default": "./dist/regex.cjs"
|
|
85
|
+
},
|
|
86
|
+
"default": { "types": "./dist/regex.d.ts", "default": "./dist/regex.mjs" }
|
|
87
|
+
},
|
|
72
88
|
"./join-paths": {
|
|
73
89
|
"import": {
|
|
74
90
|
"types": "./dist/join-paths.d.ts",
|