@mangos/filepath 1.0.4 → 1.0.5
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/README.md +15 -10
- package/dist/ParsedPath.d.ts +2 -2
- package/dist/ParsedPathError.d.ts +2 -2
- package/dist/Token.d.ts +7 -7
- package/dist/Token.js +6 -6
- package/dist/absorbers/ddp.d.ts +2 -2
- package/dist/absorbers/ddp.js +3 -3
- package/dist/absorbers/posix.d.ts +2 -2
- package/dist/absorbers/posix.js +6 -6
- package/dist/absorbers/tdp.d.ts +3 -3
- package/dist/absorbers/tdp.js +9 -9
- package/dist/absorbers/unc.d.ts +2 -2
- package/dist/absorbers/unc.js +3 -3
- package/dist/constants.d.ts +4 -4
- package/dist/constants.js +3 -3
- package/dist/index.d.ts +6 -4
- package/dist/index.js +4 -0
- package/dist/parser.d.ts +4 -4
- package/dist/parser.js +14 -11
- package/dist/togglePathFragment.js +2 -2
- package/dist/types/TokenValueType.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ _Note: `\` needs to be escaped when using it in js code._
|
|
|
37
37
|
```javascript
|
|
38
38
|
// node resolve
|
|
39
39
|
path.resolve('//?/UNC/Server/share', '../../../txt');
|
|
40
|
-
// -> '
|
|
40
|
+
// -> '\\\\?\\txt' mangled unc loot
|
|
41
41
|
|
|
42
42
|
// this library
|
|
43
43
|
filePath.resolve('//?/UNC/Server/share', '../../../txt').toString();
|
|
@@ -61,6 +61,12 @@ There are 4 exported functions:
|
|
|
61
61
|
import { allPath, firstPath, resolve, resolvePathObject } from '@mangos/filepath';
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
+
There are 2 exported classes:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { ParsedPath, ParsedPathError } from '@mangos/filepath';
|
|
68
|
+
```
|
|
69
|
+
|
|
64
70
|
Most of the time you will be using <a href="#fn-resolve"><code>resolve</code></a>, <a href="#fn-first-path"><code>firstPath</code></a>.
|
|
65
71
|
|
|
66
72
|
<h3 id="infer-path-options">Type <code>InferPathOptions</code></h3>
|
|
@@ -96,10 +102,10 @@ An instance of `ParsedPath` has the following fields/members
|
|
|
96
102
|
|
|
97
103
|
- members:
|
|
98
104
|
- <code>toString(): <i>string</i></code>: return the original path string
|
|
99
|
-
- <code>isRelative(): <i>boolean</i></
|
|
105
|
+
- <code>isRelative(): <i>boolean</i></code>: is the a path a relative one?
|
|
100
106
|
- fields:
|
|
101
107
|
- <code>type: <i>string</i></code>: one of the value `devicePath`, `unc`, `dos`, `posix`.
|
|
102
|
-
- <code>path: <i>
|
|
108
|
+
- <code>path: <i>FileToken[]</i></code>: the path tokenized (see source).
|
|
103
109
|
|
|
104
110
|
<h3 id="parsed-path-error"><code>ParsedPathError</code> object</h3>
|
|
105
111
|
|
|
@@ -109,7 +115,7 @@ If a path has illigal characters or is invalid the result of a tokenization will
|
|
|
109
115
|
- <code>toString(): <i>string</i></code>: algamation of all errors found during parsing.
|
|
110
116
|
- attributes:
|
|
111
117
|
- <code>type: <i>string</i></code>: one of the values `devicePath`, `unc`, `dos`, `posix`.
|
|
112
|
-
- <code>path: <i>
|
|
118
|
+
- <code>path: <i>FileToken[]</i></code>: the path tokenized.
|
|
113
119
|
|
|
114
120
|
|
|
115
121
|
<h3 id="path-type-order-of-evaluation">Path type order of evaluation</h4>
|
|
@@ -179,7 +185,7 @@ function firstPath(path = '', options: InferPathOptions = {}): ParsedPath | Pars
|
|
|
179
185
|
<h4 id="fn-resolve-path-object">function: <code>resolvePathObject</code></h4>
|
|
180
186
|
|
|
181
187
|
```typescript
|
|
182
|
-
function resolvePathObject(from: ParsedPath, ...toFragments: string[]): ParsedPath
|
|
188
|
+
function resolvePathObject(from: ParsedPath, ...toFragments: string[]): ParsedPath;
|
|
183
189
|
```
|
|
184
190
|
|
|
185
191
|
<h5 id="fn-resolve-path-object-arguments">Arguments:</h5>
|
|
@@ -190,16 +196,16 @@ function resolvePathObject(from: ParsedPath, ...toFragments: string[]): ParsedPa
|
|
|
190
196
|
<h5 id="fn-resolve-path-object-return">Return:</h5>
|
|
191
197
|
|
|
192
198
|
- <a href="#parsed-path"><code>ParsedPath</code></a>: In case of successfull resolve.
|
|
193
|
-
- <a href="#parsed-path-error"><code>ParsedPathError</code></a>: In case of legal structure but illegal characters in the `from` or `toFragments`.
|
|
194
199
|
|
|
195
200
|
<h5 id="fn-resolve-path-object-throws">throws:</h5>
|
|
196
201
|
|
|
197
|
-
If <code>from</code> is a <a href="#parsed-path-error"><code>ParsedPathError</code></a> an `Error` will be thrown.
|
|
202
|
+
- If <code>from</code> is a <a href="#parsed-path-error"><code>ParsedPathError</code></a> an `Error` will be thrown.
|
|
203
|
+
- If any of the `toFragments` is an invalid path an Error will be thrown.
|
|
198
204
|
|
|
199
205
|
<h4 id="fn-resolve">function: <code>resolve</code></h4>
|
|
200
206
|
|
|
201
207
|
```typescript
|
|
202
|
-
function resolve(fromStr: string, ...toFragments: string[]): ParsedPath
|
|
208
|
+
function resolve(fromStr: string, ...toFragments: string[]): ParsedPath;
|
|
203
209
|
```
|
|
204
210
|
|
|
205
211
|
<h5 id="fn-resolve-arguments">Arguments:</h5>
|
|
@@ -210,11 +216,10 @@ function resolve(fromStr: string, ...toFragments: string[]): ParsedPath | Parsed
|
|
|
210
216
|
<h5 id="fn-resolve-return">Return:</h5>
|
|
211
217
|
|
|
212
218
|
- <a href="#parsed-path"><code>ParsedPath</code></a>: In case of successfull resolve.
|
|
213
|
-
- <a href="#parsed-path-error"><code>ParsedPathError</code></a>: In case of legal structure but illegal characters in the `from` or `toFragments`.
|
|
214
219
|
|
|
215
220
|
<h5 id="fn-resolve-throws">throws:</h5>
|
|
216
221
|
|
|
217
|
-
If <code>fromStr</code> is a <a href="#parsed-path-error"><code>ParsedPathError</code></a> an `Error` will be thrown.
|
|
222
|
+
If <code>fromStr</code> is invalid a <a href="#parsed-path-error"><code>ParsedPathError</code></a> an `Error` will be thrown.
|
|
218
223
|
|
|
219
224
|
<h2>License</h2>
|
|
220
225
|
|
package/dist/ParsedPath.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FileSystem, ParsedPathDTO } from './parser.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { PathToken } from './Token.js';
|
|
3
3
|
export declare class ParsedPath {
|
|
4
|
-
readonly path:
|
|
4
|
+
readonly path: PathToken[];
|
|
5
5
|
readonly type: FileSystem;
|
|
6
6
|
constructor(parsed: ParsedPathDTO);
|
|
7
7
|
toString(): string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PathToken } from 'Token.js';
|
|
2
2
|
import type { FileSystem, ParsedPathDTO } from './parser.js';
|
|
3
3
|
export declare class ParsedPathError {
|
|
4
4
|
private readonly parsed;
|
|
5
|
-
readonly path:
|
|
5
|
+
readonly path: PathToken[];
|
|
6
6
|
readonly type: FileSystem;
|
|
7
7
|
constructor(parsed: ParsedPathDTO);
|
|
8
8
|
toString(): string;
|
package/dist/Token.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare class
|
|
3
|
-
readonly token:
|
|
1
|
+
import type { PathTokenValueType } from './types/TokenValueType.js';
|
|
2
|
+
export declare class PathToken {
|
|
3
|
+
readonly token: PathTokenValueType;
|
|
4
4
|
readonly value: string;
|
|
5
5
|
readonly start: number;
|
|
6
6
|
readonly end: number;
|
|
7
7
|
static from(o: {
|
|
8
|
-
token:
|
|
8
|
+
token: PathTokenValueType;
|
|
9
9
|
value: string;
|
|
10
10
|
start: number;
|
|
11
11
|
end: number;
|
|
12
12
|
error?: string;
|
|
13
|
-
}):
|
|
13
|
+
}): PathToken;
|
|
14
14
|
readonly error?: string;
|
|
15
|
-
constructor(token:
|
|
15
|
+
constructor(token: PathTokenValueType, value: string, start: number, end: number, error?: string);
|
|
16
16
|
isRoot(): boolean;
|
|
17
|
-
equals(ot:
|
|
17
|
+
equals(ot: PathToken): boolean;
|
|
18
18
|
}
|
package/dist/Token.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
class
|
|
1
|
+
import { PathTokenEnum } from "./constants.js";
|
|
2
|
+
class PathToken {
|
|
3
3
|
constructor(token, value, start, end, error) {
|
|
4
4
|
this.token = token;
|
|
5
5
|
this.value = value;
|
|
@@ -10,16 +10,16 @@ class Token {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
static from(o) {
|
|
13
|
-
return new
|
|
13
|
+
return new PathToken(o.token, o.value, o.start, o.end, o.error);
|
|
14
14
|
}
|
|
15
15
|
error;
|
|
16
16
|
isRoot() {
|
|
17
|
-
return this.token ===
|
|
17
|
+
return this.token === PathTokenEnum.ROOT;
|
|
18
18
|
}
|
|
19
19
|
equals(ot) {
|
|
20
|
-
return ot.token === this.token && ot.value === this.value && ot.
|
|
20
|
+
return ot.token === this.token && ot.value === this.value && ot.error === this.error;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
export {
|
|
24
|
-
|
|
24
|
+
PathToken
|
|
25
25
|
};
|
package/dist/absorbers/ddp.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PathToken } from '../Token.js';
|
|
2
2
|
type RegExporderdMapDDP = {
|
|
3
3
|
ddpwithUNC: RegExp;
|
|
4
4
|
ddpwithVolumeUUID: RegExp;
|
|
@@ -6,5 +6,5 @@ type RegExporderdMapDDP = {
|
|
|
6
6
|
unc?: RegExp;
|
|
7
7
|
};
|
|
8
8
|
export declare const regExpOrderedMapDDP: RegExporderdMapDDP;
|
|
9
|
-
export declare function ddpAbsorber(str?: string, start?: number, end?: number): Generator<
|
|
9
|
+
export declare function ddpAbsorber(str?: string, start?: number, end?: number): Generator<PathToken, undefined, undefined>;
|
|
10
10
|
export {};
|
package/dist/absorbers/ddp.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { PathTokenEnum } from "../constants.js";
|
|
2
|
+
import { PathToken } from "../Token.js";
|
|
3
3
|
import { tdpBodyAbsorber } from "./tdp.js";
|
|
4
4
|
const regExpOrderedMapDDP = {
|
|
5
5
|
// \\?\UNC\Server\Share\
|
|
@@ -24,7 +24,7 @@ const createRootValueMap = {
|
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
function createRootToken(value, offset = 0) {
|
|
27
|
-
return new
|
|
27
|
+
return new PathToken(PathTokenEnum.ROOT, value, offset, offset + value.length - 1);
|
|
28
28
|
}
|
|
29
29
|
function* ddpAbsorber(str = "", start = 0, end = str.length - 1) {
|
|
30
30
|
const pks = Object.keys(regExpOrderedMapDDP);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default function posixAbsorber(str?: string, start?: number, end?: number): Generator<
|
|
1
|
+
import { PathToken } from '../Token.js';
|
|
2
|
+
export default function posixAbsorber(str?: string, start?: number, end?: number): Generator<PathToken, undefined, undefined>;
|
package/dist/absorbers/posix.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import absorbSuccessiveValues from "../absorbSuccessiveValues.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { PathTokenEnum } from "../constants.js";
|
|
3
|
+
import { PathToken } from "../Token.js";
|
|
4
4
|
import { togglePathFragment } from "../togglePathFragment.js";
|
|
5
5
|
function* posixAbsorber(str = "", start = 0, end = str.length - 1) {
|
|
6
6
|
let i = start;
|
|
7
7
|
const root = absorbSuccessiveValues(str, (s) => s === "/", start, end);
|
|
8
8
|
if (root) {
|
|
9
|
-
yield new
|
|
9
|
+
yield new PathToken(PathTokenEnum.ROOT, str.slice(start, root.end + 1), start, root.end);
|
|
10
10
|
i = root.end + 1;
|
|
11
11
|
}
|
|
12
12
|
let toggle = 0;
|
|
@@ -17,12 +17,12 @@ function* posixAbsorber(str = "", start = 0, end = str.length - 1) {
|
|
|
17
17
|
const value = str.slice(i, result.end + 1);
|
|
18
18
|
let token = togglePathFragment[toggle % 2];
|
|
19
19
|
if (value === "..") {
|
|
20
|
-
token =
|
|
20
|
+
token = PathTokenEnum.PARENT;
|
|
21
21
|
}
|
|
22
22
|
if (value === ".") {
|
|
23
|
-
token =
|
|
23
|
+
token = PathTokenEnum.CURRENT;
|
|
24
24
|
}
|
|
25
|
-
yield new
|
|
25
|
+
yield new PathToken(token, value, result.start, result.end);
|
|
26
26
|
i = result.end + 1;
|
|
27
27
|
}
|
|
28
28
|
toggle = ++toggle % 2;
|
package/dist/absorbers/tdp.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default function tdpAbsorber(str?: string): Generator<
|
|
3
|
-
export declare function tdpBodyAbsorber(str: string | undefined, start: number, end?: number): Generator<
|
|
1
|
+
import { PathToken } from '../Token.js';
|
|
2
|
+
export default function tdpAbsorber(str?: string): Generator<PathToken, undefined, undefined>;
|
|
3
|
+
export declare function tdpBodyAbsorber(str: string | undefined, start: number, end?: number): Generator<PathToken, undefined, undefined>;
|
package/dist/absorbers/tdp.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import absorbSuccessiveValues from "../absorbSuccessiveValues.js";
|
|
2
|
-
import {
|
|
2
|
+
import { PathTokenEnum } from "../constants.js";
|
|
3
3
|
import getCWD from "../getCWD.js";
|
|
4
4
|
import getDrive from "../getDrive.js";
|
|
5
5
|
import mapPlatformNames from "../platform.js";
|
|
6
|
-
import {
|
|
6
|
+
import { PathToken } from "../Token.js";
|
|
7
7
|
import { togglePathFragment } from "../togglePathFragment.js";
|
|
8
8
|
import validSep from "../validSep.js";
|
|
9
9
|
import { regExpOrderedMapDDP, ddpAbsorber } from "./ddp.js";
|
|
@@ -37,7 +37,7 @@ function getCWDDOSRoot() {
|
|
|
37
37
|
}
|
|
38
38
|
const drive = getDrive(getCWD());
|
|
39
39
|
if (drive[0] >= "a" && drive[0] <= "z" && drive[1] === ":") {
|
|
40
|
-
return new
|
|
40
|
+
return new PathToken(PathTokenEnum.ROOT, `${drive.join("")}`, 0, 1);
|
|
41
41
|
}
|
|
42
42
|
return void 0;
|
|
43
43
|
}
|
|
@@ -73,8 +73,8 @@ function* tdpAbsorber(str = "") {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
const value = str.slice(result.start, result.end + 1);
|
|
76
|
-
yield new
|
|
77
|
-
|
|
76
|
+
yield new PathToken(
|
|
77
|
+
PathTokenEnum.PATHELT,
|
|
78
78
|
value,
|
|
79
79
|
0,
|
|
80
80
|
result.end,
|
|
@@ -87,7 +87,7 @@ function* tdpAbsorber(str = "") {
|
|
|
87
87
|
}
|
|
88
88
|
const drive = getDrive(str.slice(i, i + 2).toLowerCase());
|
|
89
89
|
if (drive[0] >= "a" && drive[0] <= "z" && drive[1] === ":") {
|
|
90
|
-
yield new
|
|
90
|
+
yield new PathToken(PathTokenEnum.ROOT, `${drive.join("")}`, i, i + 1);
|
|
91
91
|
i = 2;
|
|
92
92
|
}
|
|
93
93
|
yield* tdpBodyAbsorber(str, i, str.length - 1);
|
|
@@ -104,10 +104,10 @@ function* tdpBodyAbsorber(str = "", start, end = str.length - 1) {
|
|
|
104
104
|
if (toggle === 0) {
|
|
105
105
|
switch (value) {
|
|
106
106
|
case "..":
|
|
107
|
-
token =
|
|
107
|
+
token = PathTokenEnum.PARENT;
|
|
108
108
|
break;
|
|
109
109
|
case ".":
|
|
110
|
-
token =
|
|
110
|
+
token = PathTokenEnum.CURRENT;
|
|
111
111
|
break;
|
|
112
112
|
default: {
|
|
113
113
|
const ldn = hasLegacyDeviceName(value);
|
|
@@ -120,7 +120,7 @@ function* tdpBodyAbsorber(str = "", start, end = str.length - 1) {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
yield errors?.length ? new
|
|
123
|
+
yield errors?.length ? new PathToken(token, value, result.start, result.end, errors?.join("|")) : new PathToken(token, value, result.start, result.end);
|
|
124
124
|
i = result.end + 1;
|
|
125
125
|
}
|
|
126
126
|
toggle = ++toggle % 2;
|
package/dist/absorbers/unc.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PathToken } from '../Token.js';
|
|
2
2
|
export declare const uncRegExp: RegExp;
|
|
3
|
-
export default function uncAbsorber(str?: string): Generator<
|
|
3
|
+
export default function uncAbsorber(str?: string): Generator<PathToken, undefined, undefined>;
|
package/dist/absorbers/unc.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { PathTokenEnum } from "../constants.js";
|
|
2
|
+
import { PathToken } from "../Token.js";
|
|
3
3
|
import { tdpBodyAbsorber } from "./tdp.js";
|
|
4
4
|
const uncRegExp = /^(\/\/|\\\\)([^\\/\\?\\.]+)(\/|\\)([^\\/]+)(\/|\\)?/;
|
|
5
5
|
function* uncAbsorber(str = "") {
|
|
@@ -11,7 +11,7 @@ function* uncAbsorber(str = "") {
|
|
|
11
11
|
const share = match[4];
|
|
12
12
|
const value = `\\\\${server}\\${share}`;
|
|
13
13
|
const endUnc = value.length - 1;
|
|
14
|
-
yield new
|
|
14
|
+
yield new PathToken(PathTokenEnum.ROOT, value, 0, endUnc);
|
|
15
15
|
yield* tdpBodyAbsorber(str, endUnc + 1, str.length - 1);
|
|
16
16
|
}
|
|
17
17
|
export {
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const PathTokenEnum: {
|
|
2
2
|
readonly SEP: "\u0001";
|
|
3
3
|
readonly ROOT: "\u0003";
|
|
4
4
|
readonly PATHELT: "\u0006";
|
|
5
5
|
readonly PARENT: "\u0007";
|
|
6
6
|
readonly CURRENT: "\b";
|
|
7
7
|
};
|
|
8
|
-
export type
|
|
9
|
-
-readonly [K in keyof typeof
|
|
8
|
+
export type PathTokenValueEnumType = {
|
|
9
|
+
-readonly [K in keyof typeof PathTokenEnum as (typeof PathTokenEnum)[K]]: K;
|
|
10
10
|
};
|
|
11
|
-
export declare const TokenValueEnum:
|
|
11
|
+
export declare const TokenValueEnum: PathTokenValueEnumType;
|
package/dist/constants.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const PathTokenEnum = {
|
|
2
2
|
SEP: "",
|
|
3
3
|
ROOT: "",
|
|
4
4
|
PATHELT: "",
|
|
@@ -6,12 +6,12 @@ const TokenEnum = {
|
|
|
6
6
|
CURRENT: "\b"
|
|
7
7
|
};
|
|
8
8
|
(() => {
|
|
9
|
-
const entries = Object.entries(
|
|
9
|
+
const entries = Object.entries(PathTokenEnum);
|
|
10
10
|
return entries.reduce((obj, [prop, value]) => {
|
|
11
11
|
obj[value] = prop;
|
|
12
12
|
return obj;
|
|
13
13
|
}, {});
|
|
14
14
|
})();
|
|
15
15
|
export {
|
|
16
|
-
|
|
16
|
+
PathTokenEnum
|
|
17
17
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { ParsedPath } from './ParsedPath.js';
|
|
2
|
+
import { ParsedPathError } from './ParsedPathError.js';
|
|
1
3
|
import { allPath, firstPath, resolve } from './parser.js';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
export { resolve, firstPath, allPath,
|
|
5
|
-
export type {
|
|
4
|
+
import type { PathToken } from './Token.js';
|
|
5
|
+
import type { PathTokenValueType } from './types/TokenValueType.js';
|
|
6
|
+
export { resolve, firstPath, allPath, ParsedPath, ParsedPathError };
|
|
7
|
+
export type { PathTokenValueType, PathToken };
|
package/dist/index.js
CHANGED
package/dist/parser.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { ParsedPath } from './ParsedPath.js';
|
|
2
2
|
import { ParsedPathError } from './ParsedPathError.js';
|
|
3
|
-
import {
|
|
3
|
+
import { PathToken } from './Token.js';
|
|
4
4
|
export type FileSystem = 'devicePath' | 'unc' | 'dos' | 'posix';
|
|
5
5
|
declare function firstPath(path?: string, options?: InferPathOptions): ParsedPath | ParsedPathError | undefined;
|
|
6
6
|
declare function allPath(path?: string, options?: InferPathOptions): (ParsedPath | ParsedPathError)[];
|
|
7
7
|
export type ParsedPathDTO = {
|
|
8
8
|
type: FileSystem;
|
|
9
|
-
path:
|
|
9
|
+
path: PathToken[];
|
|
10
10
|
firstError?: number;
|
|
11
11
|
};
|
|
12
|
-
declare function resolve(fromStr?: string, ...toFragments: string[]): ParsedPath
|
|
13
|
-
declare function resolvePathObject(from: ParsedPath, ...toFragments: string[]): ParsedPath
|
|
12
|
+
declare function resolve(fromStr?: string, ...toFragments: string[]): ParsedPath;
|
|
13
|
+
declare function resolvePathObject(from: ParsedPath, ...toFragments: string[]): ParsedPath;
|
|
14
14
|
type InferPathOptions = {
|
|
15
15
|
[key in FileSystem]+?: boolean;
|
|
16
16
|
};
|
package/dist/parser.js
CHANGED
|
@@ -2,12 +2,12 @@ import { ddpAbsorber } from "./absorbers/ddp.js";
|
|
|
2
2
|
import posixAbsorber from "./absorbers/posix.js";
|
|
3
3
|
import tdpAbsorber from "./absorbers/tdp.js";
|
|
4
4
|
import uncAbsorber from "./absorbers/unc.js";
|
|
5
|
-
import {
|
|
5
|
+
import { PathTokenEnum } from "./constants.js";
|
|
6
6
|
import getCWD from "./getCWD.js";
|
|
7
7
|
import { ParsedPath } from "./ParsedPath.js";
|
|
8
8
|
import { ParsedPathError } from "./ParsedPathError.js";
|
|
9
9
|
import mapPlatformNames from "./platform.js";
|
|
10
|
-
import {
|
|
10
|
+
import { PathToken } from "./Token.js";
|
|
11
11
|
const absorberMapping = {
|
|
12
12
|
unc: uncAbsorber,
|
|
13
13
|
dos: tdpAbsorber,
|
|
@@ -16,6 +16,9 @@ const absorberMapping = {
|
|
|
16
16
|
};
|
|
17
17
|
const allNamespaces = ["devicePath", "unc", "dos", "posix"];
|
|
18
18
|
function firstPath(path = "", options = {}) {
|
|
19
|
+
if (path === "") {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
19
22
|
const iterator = inferPathType(path, options);
|
|
20
23
|
const step = iterator.next();
|
|
21
24
|
if (step.done) {
|
|
@@ -54,7 +57,7 @@ function last(arr) {
|
|
|
54
57
|
}
|
|
55
58
|
function upp(path) {
|
|
56
59
|
let _last;
|
|
57
|
-
for (_last = last(path); _last.token ===
|
|
60
|
+
for (_last = last(path); _last.token === PathTokenEnum.SEP; _last = last(path)) {
|
|
58
61
|
path.pop();
|
|
59
62
|
}
|
|
60
63
|
if (_last !== path[0]) {
|
|
@@ -62,15 +65,15 @@ function upp(path) {
|
|
|
62
65
|
}
|
|
63
66
|
}
|
|
64
67
|
function add(_tokens, token) {
|
|
65
|
-
if (token.token ===
|
|
68
|
+
if (token.token === PathTokenEnum.SEP) {
|
|
66
69
|
return;
|
|
67
70
|
}
|
|
68
71
|
let _last = last(_tokens);
|
|
69
|
-
for (; _last.token ===
|
|
72
|
+
for (; _last.token === PathTokenEnum.SEP; _last = last(_tokens)) {
|
|
70
73
|
_tokens.pop();
|
|
71
74
|
}
|
|
72
|
-
_tokens.push(new
|
|
73
|
-
_tokens.push(new
|
|
75
|
+
_tokens.push(new PathToken(PathTokenEnum.SEP, getSeperator(), _last.end + 1, _last.end + 1));
|
|
76
|
+
_tokens.push(new PathToken(token.token, token.value, _last.end + 2, _last.end + 2 + token.end));
|
|
74
77
|
}
|
|
75
78
|
function firstPathFromCWD() {
|
|
76
79
|
return firstPath(getCWD());
|
|
@@ -107,13 +110,13 @@ function resolvePathObject(from, ...toFragments) {
|
|
|
107
110
|
const working = structuredClone(from.path);
|
|
108
111
|
for (const token of firstPathTo.path) {
|
|
109
112
|
switch (token.token) {
|
|
110
|
-
case
|
|
111
|
-
case
|
|
113
|
+
case PathTokenEnum.SEP:
|
|
114
|
+
case PathTokenEnum.CURRENT:
|
|
112
115
|
break;
|
|
113
|
-
case
|
|
116
|
+
case PathTokenEnum.PARENT:
|
|
114
117
|
upp(working);
|
|
115
118
|
break;
|
|
116
|
-
case
|
|
119
|
+
case PathTokenEnum.PATHELT:
|
|
117
120
|
add(working, token);
|
|
118
121
|
break;
|
|
119
122
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const togglePathFragment = [
|
|
1
|
+
import { PathTokenEnum } from "./constants.js";
|
|
2
|
+
const togglePathFragment = [PathTokenEnum.PATHELT, PathTokenEnum.SEP];
|
|
3
3
|
export {
|
|
4
4
|
togglePathFragment
|
|
5
5
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export type
|
|
1
|
+
import type { PathTokenEnum } from '../constants';
|
|
2
|
+
export type PathTokenValueType = (typeof PathTokenEnum)[keyof typeof PathTokenEnum];
|