ventojs 0.7.1 → 0.7.3
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/esm/_dnt.shims.js +0 -1
- package/esm/deps/deno.land/std@0.201.0/assert/assert.d.ts +2 -0
- package/esm/deps/deno.land/std@0.201.0/assert/assert.js +8 -0
- package/esm/deps/deno.land/std@0.201.0/assert/assertion_error.d.ts +4 -0
- package/esm/deps/deno.land/std@0.201.0/assert/assertion_error.js +7 -0
- package/esm/deps/deno.land/std@0.201.0/path/_basename.d.ts +16 -0
- package/esm/deps/deno.land/std@0.201.0/path/_basename.js +78 -0
- package/esm/deps/deno.land/std@0.201.0/path/_dirname.d.ts +10 -0
- package/esm/deps/deno.land/std@0.201.0/path/_dirname.js +132 -0
- package/esm/deps/deno.land/std@0.201.0/path/_extname.d.ts +12 -0
- package/esm/deps/deno.land/std@0.201.0/path/_extname.js +121 -0
- package/esm/deps/deno.land/std@0.201.0/path/_format.d.ts +11 -0
- package/esm/deps/deno.land/std@0.201.0/path/_format.js +35 -0
- package/esm/deps/deno.land/std@0.201.0/path/_from_file_url.d.ts +25 -0
- package/esm/deps/deno.land/std@0.201.0/path/_from_file_url.js +46 -0
- package/esm/deps/deno.land/std@0.201.0/path/_is_absolute.d.ts +10 -0
- package/esm/deps/deno.land/std@0.201.0/path/_is_absolute.js +34 -0
- package/esm/deps/deno.land/std@0.201.0/path/_join.d.ts +10 -0
- package/esm/deps/deno.land/std@0.201.0/path/_join.js +93 -0
- package/esm/deps/deno.land/std@0.201.0/path/_normalize.d.ts +14 -0
- package/esm/deps/deno.land/std@0.201.0/path/_normalize.js +153 -0
- package/esm/deps/deno.land/std@0.201.0/path/_parse.d.ts +11 -0
- package/esm/deps/deno.land/std@0.201.0/path/_parse.js +250 -0
- package/esm/deps/deno.land/std@0.201.0/path/_relative.d.ts +19 -0
- package/esm/deps/deno.land/std@0.201.0/path/_relative.js +216 -0
- package/esm/deps/deno.land/std@0.201.0/path/_resolve.d.ts +10 -0
- package/esm/deps/deno.land/std@0.201.0/path/_resolve.js +183 -0
- package/esm/deps/deno.land/std@0.201.0/path/_to_file_url.d.ts +25 -0
- package/esm/deps/deno.land/std@0.201.0/path/_to_file_url.js +61 -0
- package/esm/deps/deno.land/std@0.201.0/path/_to_namespaced_path.d.ts +10 -0
- package/esm/deps/deno.land/std@0.201.0/path/_to_namespaced_path.js +46 -0
- package/esm/deps/deno.land/{std@0.178.0 → std@0.201.0}/path/_util.d.ts +0 -5
- package/esm/deps/deno.land/{std@0.178.0 → std@0.201.0}/path/_util.js +0 -54
- package/esm/deps/deno.land/std@0.201.0/path/basename.d.ts +8 -0
- package/esm/deps/deno.land/std@0.201.0/path/basename.js +16 -0
- package/esm/deps/deno.land/std@0.201.0/path/dirname.d.ts +5 -0
- package/esm/deps/deno.land/std@0.201.0/path/dirname.js +11 -0
- package/esm/deps/deno.land/std@0.201.0/path/extname.d.ts +6 -0
- package/esm/deps/deno.land/std@0.201.0/path/extname.js +12 -0
- package/esm/deps/deno.land/std@0.201.0/path/format.d.ts +6 -0
- package/esm/deps/deno.land/std@0.201.0/path/format.js +11 -0
- package/esm/deps/deno.land/std@0.201.0/path/from_file_url.d.ts +18 -0
- package/esm/deps/deno.land/std@0.201.0/path/from_file_url.js +23 -0
- package/esm/deps/deno.land/{std@0.178.0 → std@0.201.0}/path/glob.d.ts +1 -1
- package/esm/deps/deno.land/{std@0.178.0 → std@0.201.0}/path/glob.js +50 -50
- package/esm/deps/deno.land/std@0.201.0/path/is_absolute.d.ts +5 -0
- package/esm/deps/deno.land/std@0.201.0/path/is_absolute.js +11 -0
- package/esm/deps/deno.land/std@0.201.0/path/join.d.ts +5 -0
- package/esm/deps/deno.land/std@0.201.0/path/join.js +11 -0
- package/esm/deps/deno.land/std@0.201.0/path/mod.d.ts +22 -0
- package/esm/deps/deno.land/{std@0.178.0 → std@0.201.0}/path/mod.js +17 -4
- package/esm/deps/deno.land/std@0.201.0/path/normalize.d.ts +7 -0
- package/esm/deps/deno.land/std@0.201.0/path/normalize.js +13 -0
- package/esm/deps/deno.land/std@0.201.0/path/parse.d.ts +6 -0
- package/esm/deps/deno.land/std@0.201.0/path/parse.js +11 -0
- package/esm/deps/deno.land/std@0.201.0/path/posix.d.ts +15 -0
- package/esm/deps/deno.land/std@0.201.0/path/posix.js +19 -0
- package/esm/deps/deno.land/std@0.201.0/path/relative.d.ts +12 -0
- package/esm/deps/deno.land/std@0.201.0/path/relative.js +18 -0
- package/esm/deps/deno.land/std@0.201.0/path/resolve.d.ts +5 -0
- package/esm/deps/deno.land/std@0.201.0/path/resolve.js +13 -0
- package/esm/deps/deno.land/{std@0.178.0 → std@0.201.0}/path/separator.js +1 -1
- package/esm/deps/deno.land/std@0.201.0/path/to_file_url.d.ts +18 -0
- package/esm/deps/deno.land/std@0.201.0/path/to_file_url.js +23 -0
- package/esm/deps/deno.land/std@0.201.0/path/to_namespaced_path.d.ts +5 -0
- package/esm/deps/deno.land/std@0.201.0/path/to_namespaced_path.js +13 -0
- package/esm/deps/deno.land/std@0.201.0/path/win32.d.ts +15 -0
- package/esm/deps/deno.land/std@0.201.0/path/win32.js +19 -0
- package/esm/deps.d.ts +1 -1
- package/esm/deps.js +1 -1
- package/esm/src/environment.js +1 -1
- package/package.json +1 -1
- package/esm/_dnt.test_polyfills.d.ts +0 -11
- package/esm/_dnt.test_shims.d.ts +0 -5
- package/esm/deps/deno.land/std@0.178.0/_util/asserts.d.ts +0 -10
- package/esm/deps/deno.land/std@0.178.0/_util/asserts.js +0 -21
- package/esm/deps/deno.land/std@0.178.0/path/mod.d.ts +0 -9
- package/esm/deps/deno.land/std@0.178.0/path/posix.d.ts +0 -86
- package/esm/deps/deno.land/std@0.178.0/path/posix.js +0 -442
- package/esm/deps/deno.land/std@0.178.0/path/win32.d.ts +0 -91
- package/esm/deps/deno.land/std@0.178.0/path/win32.js +0 -909
- package/esm/deps/deno.land/std@0.190.0/_util/asserts.d.ts +0 -10
- package/esm/deps/deno.land/std@0.190.0/bytes/copy.d.ts +0 -27
- package/esm/deps/deno.land/std@0.190.0/fmt/colors.d.ts +0 -270
- package/esm/deps/deno.land/std@0.190.0/front_matter/mod.d.ts +0 -78
- package/esm/deps/deno.land/std@0.190.0/front_matter/yaml.d.ts +0 -4
- package/esm/deps/deno.land/std@0.190.0/io/buffer.d.ts +0 -81
- package/esm/deps/deno.land/std@0.190.0/testing/_diff.d.ts +0 -26
- package/esm/deps/deno.land/std@0.190.0/testing/_format.d.ts +0 -1
- package/esm/deps/deno.land/std@0.190.0/testing/asserts.d.ts +0 -284
- package/esm/deps/deno.land/std@0.190.0/yaml/_error.d.ts +0 -6
- package/esm/deps/deno.land/std@0.190.0/yaml/_loader/loader.d.ts +0 -4
- package/esm/deps/deno.land/std@0.190.0/yaml/_loader/loader_state.d.ts +0 -43
- package/esm/deps/deno.land/std@0.190.0/yaml/_mark.d.ts +0 -10
- package/esm/deps/deno.land/std@0.190.0/yaml/_state.d.ts +0 -5
- package/esm/deps/deno.land/std@0.190.0/yaml/_type/binary.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/_type/bool.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/_type/float.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/_type/function.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/_type/int.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/_type/map.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/_type/merge.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/_type/mod.d.ts +0 -16
- package/esm/deps/deno.land/std@0.190.0/yaml/_type/nil.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/_type/omap.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/_type/pairs.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/_type/regexp.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/_type/seq.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/_type/set.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/_type/str.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/_type/timestamp.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/_type/undefined.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/_utils.d.ts +0 -19
- package/esm/deps/deno.land/std@0.190.0/yaml/parse.d.ts +0 -35
- package/esm/deps/deno.land/std@0.190.0/yaml/schema/core.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/schema/default.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/schema/extended.d.ts +0 -30
- package/esm/deps/deno.land/std@0.190.0/yaml/schema/failsafe.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/schema/json.d.ts +0 -2
- package/esm/deps/deno.land/std@0.190.0/yaml/schema/mod.d.ts +0 -5
- package/esm/deps/deno.land/std@0.190.0/yaml/schema.d.ts +0 -22
- package/esm/deps/deno.land/std@0.190.0/yaml/type.d.ts +0 -28
- package/esm/test/comment.test.d.ts +0 -1
- package/esm/test/escape.test.d.ts +0 -1
- package/esm/test/for.test.d.ts +0 -1
- package/esm/test/function.test.d.ts +0 -1
- package/esm/test/if.test.d.ts +0 -1
- package/esm/test/import.test.d.ts +0 -1
- package/esm/test/include.test.d.ts +0 -1
- package/esm/test/js.test.d.ts +0 -1
- package/esm/test/layout.test.d.ts +0 -1
- package/esm/test/print.test.d.ts +0 -1
- package/esm/test/raw.test.d.ts +0 -1
- package/esm/test/set.test.d.ts +0 -1
- package/esm/test/tokenizer.test.d.ts +0 -1
- package/esm/test/utils.d.ts +0 -24
- /package/esm/deps/deno.land/{std@0.178.0 → std@0.201.0}/path/_constants.d.ts +0 -0
- /package/esm/deps/deno.land/{std@0.178.0 → std@0.201.0}/path/_constants.js +0 -0
- /package/esm/deps/deno.land/{std@0.178.0 → std@0.201.0}/path/_interface.d.ts +0 -0
- /package/esm/deps/deno.land/{std@0.178.0 → std@0.201.0}/path/_interface.js +0 -0
- /package/esm/deps/deno.land/{std@0.178.0/_util/os.d.ts → std@0.201.0/path/_os.d.ts} +0 -0
- /package/esm/deps/deno.land/{std@0.178.0/_util/os.js → std@0.201.0/path/_os.js} +0 -0
- /package/esm/deps/deno.land/{std@0.178.0 → std@0.201.0}/path/common.d.ts +0 -0
- /package/esm/deps/deno.land/{std@0.178.0 → std@0.201.0}/path/common.js +0 -0
- /package/esm/deps/deno.land/{std@0.178.0 → std@0.201.0}/path/separator.d.ts +0 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
import { CHAR_BACKWARD_SLASH } from "./_constants.js";
|
|
4
|
+
import { assertPath, isPosixPathSeparator } from "./_util.js";
|
|
5
|
+
import { posixResolve, windowsResolve } from "./_resolve.js";
|
|
6
|
+
function assertArgs(from, to) {
|
|
7
|
+
assertPath(from);
|
|
8
|
+
assertPath(to);
|
|
9
|
+
if (from === to)
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Return the relative path from `from` to `to` based on current working directory.
|
|
14
|
+
*
|
|
15
|
+
* @param from path in current working directory
|
|
16
|
+
* @param to path in current working directory
|
|
17
|
+
*/
|
|
18
|
+
export function posixRelative(from, to) {
|
|
19
|
+
assertArgs(from, to);
|
|
20
|
+
from = posixResolve(from);
|
|
21
|
+
to = posixResolve(to);
|
|
22
|
+
if (from === to)
|
|
23
|
+
return "";
|
|
24
|
+
// Trim any leading backslashes
|
|
25
|
+
let fromStart = 1;
|
|
26
|
+
const fromEnd = from.length;
|
|
27
|
+
for (; fromStart < fromEnd; ++fromStart) {
|
|
28
|
+
if (!isPosixPathSeparator(from.charCodeAt(fromStart)))
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
const fromLen = fromEnd - fromStart;
|
|
32
|
+
// Trim any leading backslashes
|
|
33
|
+
let toStart = 1;
|
|
34
|
+
const toEnd = to.length;
|
|
35
|
+
for (; toStart < toEnd; ++toStart) {
|
|
36
|
+
if (!isPosixPathSeparator(to.charCodeAt(toStart)))
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
const toLen = toEnd - toStart;
|
|
40
|
+
// Compare paths to find the longest common path from root
|
|
41
|
+
const length = fromLen < toLen ? fromLen : toLen;
|
|
42
|
+
let lastCommonSep = -1;
|
|
43
|
+
let i = 0;
|
|
44
|
+
for (; i <= length; ++i) {
|
|
45
|
+
if (i === length) {
|
|
46
|
+
if (toLen > length) {
|
|
47
|
+
if (isPosixPathSeparator(to.charCodeAt(toStart + i))) {
|
|
48
|
+
// We get here if `from` is the exact base path for `to`.
|
|
49
|
+
// For example: from='/foo/bar'; to='/foo/bar/baz'
|
|
50
|
+
return to.slice(toStart + i + 1);
|
|
51
|
+
}
|
|
52
|
+
else if (i === 0) {
|
|
53
|
+
// We get here if `from` is the root
|
|
54
|
+
// For example: from='/'; to='/foo'
|
|
55
|
+
return to.slice(toStart + i);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else if (fromLen > length) {
|
|
59
|
+
if (isPosixPathSeparator(from.charCodeAt(fromStart + i))) {
|
|
60
|
+
// We get here if `to` is the exact base path for `from`.
|
|
61
|
+
// For example: from='/foo/bar/baz'; to='/foo/bar'
|
|
62
|
+
lastCommonSep = i;
|
|
63
|
+
}
|
|
64
|
+
else if (i === 0) {
|
|
65
|
+
// We get here if `to` is the root.
|
|
66
|
+
// For example: from='/foo'; to='/'
|
|
67
|
+
lastCommonSep = 0;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
const fromCode = from.charCodeAt(fromStart + i);
|
|
73
|
+
const toCode = to.charCodeAt(toStart + i);
|
|
74
|
+
if (fromCode !== toCode)
|
|
75
|
+
break;
|
|
76
|
+
else if (isPosixPathSeparator(fromCode))
|
|
77
|
+
lastCommonSep = i;
|
|
78
|
+
}
|
|
79
|
+
let out = "";
|
|
80
|
+
// Generate the relative path based on the path difference between `to`
|
|
81
|
+
// and `from`
|
|
82
|
+
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
|
83
|
+
if (i === fromEnd || isPosixPathSeparator(from.charCodeAt(i))) {
|
|
84
|
+
if (out.length === 0)
|
|
85
|
+
out += "..";
|
|
86
|
+
else
|
|
87
|
+
out += "/..";
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Lastly, append the rest of the destination (`to`) path that comes after
|
|
91
|
+
// the common path parts
|
|
92
|
+
if (out.length > 0)
|
|
93
|
+
return out + to.slice(toStart + lastCommonSep);
|
|
94
|
+
else {
|
|
95
|
+
toStart += lastCommonSep;
|
|
96
|
+
if (isPosixPathSeparator(to.charCodeAt(toStart)))
|
|
97
|
+
++toStart;
|
|
98
|
+
return to.slice(toStart);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Return the relative path from `from` to `to` based on current working directory.
|
|
103
|
+
*
|
|
104
|
+
* An example in windws, for instance:
|
|
105
|
+
* from = 'C:\\orandea\\test\\aaa'
|
|
106
|
+
* to = 'C:\\orandea\\impl\\bbb'
|
|
107
|
+
* The output of the function should be: '..\\..\\impl\\bbb'
|
|
108
|
+
*
|
|
109
|
+
* @param from path in current working directory
|
|
110
|
+
* @param to path in current working directory
|
|
111
|
+
*/
|
|
112
|
+
export function windowsRelative(from, to) {
|
|
113
|
+
assertArgs(from, to);
|
|
114
|
+
const fromOrig = windowsResolve(from);
|
|
115
|
+
const toOrig = windowsResolve(to);
|
|
116
|
+
if (fromOrig === toOrig)
|
|
117
|
+
return "";
|
|
118
|
+
from = fromOrig.toLowerCase();
|
|
119
|
+
to = toOrig.toLowerCase();
|
|
120
|
+
if (from === to)
|
|
121
|
+
return "";
|
|
122
|
+
// Trim any leading backslashes
|
|
123
|
+
let fromStart = 0;
|
|
124
|
+
let fromEnd = from.length;
|
|
125
|
+
for (; fromStart < fromEnd; ++fromStart) {
|
|
126
|
+
if (from.charCodeAt(fromStart) !== CHAR_BACKWARD_SLASH)
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
// Trim trailing backslashes (applicable to UNC paths only)
|
|
130
|
+
for (; fromEnd - 1 > fromStart; --fromEnd) {
|
|
131
|
+
if (from.charCodeAt(fromEnd - 1) !== CHAR_BACKWARD_SLASH)
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
const fromLen = fromEnd - fromStart;
|
|
135
|
+
// Trim any leading backslashes
|
|
136
|
+
let toStart = 0;
|
|
137
|
+
let toEnd = to.length;
|
|
138
|
+
for (; toStart < toEnd; ++toStart) {
|
|
139
|
+
if (to.charCodeAt(toStart) !== CHAR_BACKWARD_SLASH)
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
// Trim trailing backslashes (applicable to UNC paths only)
|
|
143
|
+
for (; toEnd - 1 > toStart; --toEnd) {
|
|
144
|
+
if (to.charCodeAt(toEnd - 1) !== CHAR_BACKWARD_SLASH)
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
const toLen = toEnd - toStart;
|
|
148
|
+
// Compare paths to find the longest common path from root
|
|
149
|
+
const length = fromLen < toLen ? fromLen : toLen;
|
|
150
|
+
let lastCommonSep = -1;
|
|
151
|
+
let i = 0;
|
|
152
|
+
for (; i <= length; ++i) {
|
|
153
|
+
if (i === length) {
|
|
154
|
+
if (toLen > length) {
|
|
155
|
+
if (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) {
|
|
156
|
+
// We get here if `from` is the exact base path for `to`.
|
|
157
|
+
// For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
|
|
158
|
+
return toOrig.slice(toStart + i + 1);
|
|
159
|
+
}
|
|
160
|
+
else if (i === 2) {
|
|
161
|
+
// We get here if `from` is the device root.
|
|
162
|
+
// For example: from='C:\\'; to='C:\\foo'
|
|
163
|
+
return toOrig.slice(toStart + i);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (fromLen > length) {
|
|
167
|
+
if (from.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) {
|
|
168
|
+
// We get here if `to` is the exact base path for `from`.
|
|
169
|
+
// For example: from='C:\\foo\\bar'; to='C:\\foo'
|
|
170
|
+
lastCommonSep = i;
|
|
171
|
+
}
|
|
172
|
+
else if (i === 2) {
|
|
173
|
+
// We get here if `to` is the device root.
|
|
174
|
+
// For example: from='C:\\foo\\bar'; to='C:\\'
|
|
175
|
+
lastCommonSep = 3;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
const fromCode = from.charCodeAt(fromStart + i);
|
|
181
|
+
const toCode = to.charCodeAt(toStart + i);
|
|
182
|
+
if (fromCode !== toCode)
|
|
183
|
+
break;
|
|
184
|
+
else if (fromCode === CHAR_BACKWARD_SLASH)
|
|
185
|
+
lastCommonSep = i;
|
|
186
|
+
}
|
|
187
|
+
// We found a mismatch before the first common path separator was seen, so
|
|
188
|
+
// return the original `to`.
|
|
189
|
+
if (i !== length && lastCommonSep === -1) {
|
|
190
|
+
return toOrig;
|
|
191
|
+
}
|
|
192
|
+
let out = "";
|
|
193
|
+
if (lastCommonSep === -1)
|
|
194
|
+
lastCommonSep = 0;
|
|
195
|
+
// Generate the relative path based on the path difference between `to` and
|
|
196
|
+
// `from`
|
|
197
|
+
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
|
198
|
+
if (i === fromEnd || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) {
|
|
199
|
+
if (out.length === 0)
|
|
200
|
+
out += "..";
|
|
201
|
+
else
|
|
202
|
+
out += "\\..";
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// Lastly, append the rest of the destination (`to`) path that comes after
|
|
206
|
+
// the common path parts
|
|
207
|
+
if (out.length > 0) {
|
|
208
|
+
return out + toOrig.slice(toStart + lastCommonSep, toEnd);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
toStart += lastCommonSep;
|
|
212
|
+
if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH)
|
|
213
|
+
++toStart;
|
|
214
|
+
return toOrig.slice(toStart, toEnd);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves path segments into a `path`
|
|
3
|
+
* @param pathSegments to process to path
|
|
4
|
+
*/
|
|
5
|
+
export declare function posixResolve(...pathSegments: string[]): string;
|
|
6
|
+
/**
|
|
7
|
+
* Resolves path segments into a `path`
|
|
8
|
+
* @param pathSegments to process to path
|
|
9
|
+
*/
|
|
10
|
+
export declare function windowsResolve(...pathSegments: string[]): string;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
4
|
+
import { CHAR_COLON } from "./_constants.js";
|
|
5
|
+
import { assertPath, isPathSeparator, isPosixPathSeparator, isWindowsDeviceRoot, normalizeString, } from "./_util.js";
|
|
6
|
+
/**
|
|
7
|
+
* Resolves path segments into a `path`
|
|
8
|
+
* @param pathSegments to process to path
|
|
9
|
+
*/
|
|
10
|
+
export function posixResolve(...pathSegments) {
|
|
11
|
+
let resolvedPath = "";
|
|
12
|
+
let resolvedAbsolute = false;
|
|
13
|
+
for (let i = pathSegments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
14
|
+
let path;
|
|
15
|
+
if (i >= 0)
|
|
16
|
+
path = pathSegments[i];
|
|
17
|
+
else {
|
|
18
|
+
// deno-lint-ignore no-explicit-any
|
|
19
|
+
const { Deno } = dntShim.dntGlobalThis;
|
|
20
|
+
if (typeof Deno?.cwd !== "function") {
|
|
21
|
+
throw new TypeError("Resolved a relative path without a CWD.");
|
|
22
|
+
}
|
|
23
|
+
path = Deno.cwd();
|
|
24
|
+
}
|
|
25
|
+
assertPath(path);
|
|
26
|
+
// Skip empty entries
|
|
27
|
+
if (path.length === 0) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
31
|
+
resolvedAbsolute = isPosixPathSeparator(path.charCodeAt(0));
|
|
32
|
+
}
|
|
33
|
+
// At this point the path should be resolved to a full absolute path, but
|
|
34
|
+
// handle relative paths to be safe (might happen when Deno.cwd() fails)
|
|
35
|
+
// Normalize the path
|
|
36
|
+
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, "/", isPosixPathSeparator);
|
|
37
|
+
if (resolvedAbsolute) {
|
|
38
|
+
if (resolvedPath.length > 0)
|
|
39
|
+
return `/${resolvedPath}`;
|
|
40
|
+
else
|
|
41
|
+
return "/";
|
|
42
|
+
}
|
|
43
|
+
else if (resolvedPath.length > 0)
|
|
44
|
+
return resolvedPath;
|
|
45
|
+
else
|
|
46
|
+
return ".";
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Resolves path segments into a `path`
|
|
50
|
+
* @param pathSegments to process to path
|
|
51
|
+
*/
|
|
52
|
+
export function windowsResolve(...pathSegments) {
|
|
53
|
+
let resolvedDevice = "";
|
|
54
|
+
let resolvedTail = "";
|
|
55
|
+
let resolvedAbsolute = false;
|
|
56
|
+
for (let i = pathSegments.length - 1; i >= -1; i--) {
|
|
57
|
+
let path;
|
|
58
|
+
// deno-lint-ignore no-explicit-any
|
|
59
|
+
const { Deno } = dntShim.dntGlobalThis;
|
|
60
|
+
if (i >= 0) {
|
|
61
|
+
path = pathSegments[i];
|
|
62
|
+
}
|
|
63
|
+
else if (!resolvedDevice) {
|
|
64
|
+
if (typeof Deno?.cwd !== "function") {
|
|
65
|
+
throw new TypeError("Resolved a drive-letter-less path without a CWD.");
|
|
66
|
+
}
|
|
67
|
+
path = Deno.cwd();
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
if (typeof Deno?.env?.get !== "function" || typeof Deno?.cwd !== "function") {
|
|
71
|
+
throw new TypeError("Resolved a relative path without a CWD.");
|
|
72
|
+
}
|
|
73
|
+
path = Deno.cwd();
|
|
74
|
+
// Verify that a cwd was found and that it actually points
|
|
75
|
+
// to our drive. If not, default to the drive's root.
|
|
76
|
+
if (path === undefined ||
|
|
77
|
+
path.slice(0, 3).toLowerCase() !== `${resolvedDevice.toLowerCase()}\\`) {
|
|
78
|
+
path = `${resolvedDevice}\\`;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
assertPath(path);
|
|
82
|
+
const len = path.length;
|
|
83
|
+
// Skip empty entries
|
|
84
|
+
if (len === 0)
|
|
85
|
+
continue;
|
|
86
|
+
let rootEnd = 0;
|
|
87
|
+
let device = "";
|
|
88
|
+
let isAbsolute = false;
|
|
89
|
+
const code = path.charCodeAt(0);
|
|
90
|
+
// Try to match a root
|
|
91
|
+
if (len > 1) {
|
|
92
|
+
if (isPathSeparator(code)) {
|
|
93
|
+
// Possible UNC root
|
|
94
|
+
// If we started with a separator, we know we at least have an
|
|
95
|
+
// absolute path of some kind (UNC or otherwise)
|
|
96
|
+
isAbsolute = true;
|
|
97
|
+
if (isPathSeparator(path.charCodeAt(1))) {
|
|
98
|
+
// Matched double path separator at beginning
|
|
99
|
+
let j = 2;
|
|
100
|
+
let last = j;
|
|
101
|
+
// Match 1 or more non-path separators
|
|
102
|
+
for (; j < len; ++j) {
|
|
103
|
+
if (isPathSeparator(path.charCodeAt(j)))
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
if (j < len && j !== last) {
|
|
107
|
+
const firstPart = path.slice(last, j);
|
|
108
|
+
// Matched!
|
|
109
|
+
last = j;
|
|
110
|
+
// Match 1 or more path separators
|
|
111
|
+
for (; j < len; ++j) {
|
|
112
|
+
if (!isPathSeparator(path.charCodeAt(j)))
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
if (j < len && j !== last) {
|
|
116
|
+
// Matched!
|
|
117
|
+
last = j;
|
|
118
|
+
// Match 1 or more non-path separators
|
|
119
|
+
for (; j < len; ++j) {
|
|
120
|
+
if (isPathSeparator(path.charCodeAt(j)))
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
if (j === len) {
|
|
124
|
+
// We matched a UNC root only
|
|
125
|
+
device = `\\\\${firstPart}\\${path.slice(last)}`;
|
|
126
|
+
rootEnd = j;
|
|
127
|
+
}
|
|
128
|
+
else if (j !== last) {
|
|
129
|
+
// We matched a UNC root with leftovers
|
|
130
|
+
device = `\\\\${firstPart}\\${path.slice(last, j)}`;
|
|
131
|
+
rootEnd = j;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
rootEnd = 1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else if (isWindowsDeviceRoot(code)) {
|
|
141
|
+
// Possible device root
|
|
142
|
+
if (path.charCodeAt(1) === CHAR_COLON) {
|
|
143
|
+
device = path.slice(0, 2);
|
|
144
|
+
rootEnd = 2;
|
|
145
|
+
if (len > 2) {
|
|
146
|
+
if (isPathSeparator(path.charCodeAt(2))) {
|
|
147
|
+
// Treat separator following drive name as an absolute path
|
|
148
|
+
// indicator
|
|
149
|
+
isAbsolute = true;
|
|
150
|
+
rootEnd = 3;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
else if (isPathSeparator(code)) {
|
|
157
|
+
// `path` contains just a path separator
|
|
158
|
+
rootEnd = 1;
|
|
159
|
+
isAbsolute = true;
|
|
160
|
+
}
|
|
161
|
+
if (device.length > 0 &&
|
|
162
|
+
resolvedDevice.length > 0 &&
|
|
163
|
+
device.toLowerCase() !== resolvedDevice.toLowerCase()) {
|
|
164
|
+
// This path points to another device so it is not applicable
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if (resolvedDevice.length === 0 && device.length > 0) {
|
|
168
|
+
resolvedDevice = device;
|
|
169
|
+
}
|
|
170
|
+
if (!resolvedAbsolute) {
|
|
171
|
+
resolvedTail = `${path.slice(rootEnd)}\\${resolvedTail}`;
|
|
172
|
+
resolvedAbsolute = isAbsolute;
|
|
173
|
+
}
|
|
174
|
+
if (resolvedAbsolute && resolvedDevice.length > 0)
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
// At this point the path should be resolved to a full absolute path,
|
|
178
|
+
// but handle relative paths to be safe (might happen when Deno.cwd()
|
|
179
|
+
// fails)
|
|
180
|
+
// Normalize the tail path
|
|
181
|
+
resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, "\\", isPathSeparator);
|
|
182
|
+
return resolvedDevice + (resolvedAbsolute ? "\\" : "") + resolvedTail || ".";
|
|
183
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* Converts a path string to a file URL.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { toFileUrl } from "https://deno.land/std@$STD_VERSION/path/posix.ts";
|
|
7
|
+
*
|
|
8
|
+
* toFileUrl("/home/foo"); // new URL("file:///home/foo")
|
|
9
|
+
* ```
|
|
10
|
+
* @param path to convert to file URL
|
|
11
|
+
*/
|
|
12
|
+
export declare function posixToFileUrl(path: string): import("url").URL;
|
|
13
|
+
/**
|
|
14
|
+
* Converts a path string to a file URL.
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { toFileUrl } from "https://deno.land/std@$STD_VERSION/path/win32.ts";
|
|
18
|
+
*
|
|
19
|
+
* toFileUrl("\\home\\foo"); // new URL("file:///home/foo")
|
|
20
|
+
* toFileUrl("C:\\Users\\foo"); // new URL("file:///C:/Users/foo")
|
|
21
|
+
* toFileUrl("\\\\127.0.0.1\\home\\foo"); // new URL("file://127.0.0.1/home/foo")
|
|
22
|
+
* ```
|
|
23
|
+
* @param path to convert to file URL
|
|
24
|
+
*/
|
|
25
|
+
export declare function windowsToFileUrl(path: string): URL;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
import { posixIsAbsolute, windowsIsAbsolute } from "./_is_absolute.js";
|
|
4
|
+
const WHITESPACE_ENCODINGS = {
|
|
5
|
+
"\u0009": "%09",
|
|
6
|
+
"\u000A": "%0A",
|
|
7
|
+
"\u000B": "%0B",
|
|
8
|
+
"\u000C": "%0C",
|
|
9
|
+
"\u000D": "%0D",
|
|
10
|
+
"\u0020": "%20",
|
|
11
|
+
};
|
|
12
|
+
function encodeWhitespace(string) {
|
|
13
|
+
return string.replaceAll(/[\s]/g, (c) => {
|
|
14
|
+
return WHITESPACE_ENCODINGS[c] ?? c;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Converts a path string to a file URL.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { toFileUrl } from "https://deno.land/std@$STD_VERSION/path/posix.ts";
|
|
22
|
+
*
|
|
23
|
+
* toFileUrl("/home/foo"); // new URL("file:///home/foo")
|
|
24
|
+
* ```
|
|
25
|
+
* @param path to convert to file URL
|
|
26
|
+
*/
|
|
27
|
+
export function posixToFileUrl(path) {
|
|
28
|
+
if (!posixIsAbsolute(path)) {
|
|
29
|
+
throw new TypeError("Must be an absolute path.");
|
|
30
|
+
}
|
|
31
|
+
const url = new URL("file:///");
|
|
32
|
+
url.pathname = encodeWhitespace(path.replace(/%/g, "%25").replace(/\\/g, "%5C"));
|
|
33
|
+
return url;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Converts a path string to a file URL.
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { toFileUrl } from "https://deno.land/std@$STD_VERSION/path/win32.ts";
|
|
40
|
+
*
|
|
41
|
+
* toFileUrl("\\home\\foo"); // new URL("file:///home/foo")
|
|
42
|
+
* toFileUrl("C:\\Users\\foo"); // new URL("file:///C:/Users/foo")
|
|
43
|
+
* toFileUrl("\\\\127.0.0.1\\home\\foo"); // new URL("file://127.0.0.1/home/foo")
|
|
44
|
+
* ```
|
|
45
|
+
* @param path to convert to file URL
|
|
46
|
+
*/
|
|
47
|
+
export function windowsToFileUrl(path) {
|
|
48
|
+
if (!windowsIsAbsolute(path)) {
|
|
49
|
+
throw new TypeError("Must be an absolute path.");
|
|
50
|
+
}
|
|
51
|
+
const [, hostname, pathname] = path.match(/^(?:[/\\]{2}([^/\\]+)(?=[/\\](?:[^/\\]|$)))?(.*)/);
|
|
52
|
+
const url = new URL("file:///");
|
|
53
|
+
url.pathname = encodeWhitespace(pathname.replace(/%/g, "%25"));
|
|
54
|
+
if (hostname !== undefined && hostname !== "localhost") {
|
|
55
|
+
url.hostname = hostname;
|
|
56
|
+
if (!url.hostname) {
|
|
57
|
+
throw new TypeError("Invalid hostname.");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return url;
|
|
61
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves path to a namespace path
|
|
3
|
+
* @param path to resolve to namespace
|
|
4
|
+
*/
|
|
5
|
+
export declare function posixToNamespacedPath(path: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Resolves path to a namespace path
|
|
8
|
+
* @param path to resolve to namespace
|
|
9
|
+
*/
|
|
10
|
+
export declare function windowsToNamespacedPath(path: string): string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
import { CHAR_BACKWARD_SLASH, CHAR_COLON, CHAR_DOT, CHAR_QUESTION_MARK, } from "./_constants.js";
|
|
4
|
+
import { isWindowsDeviceRoot } from "./_util.js";
|
|
5
|
+
import { windowsResolve } from "./_resolve.js";
|
|
6
|
+
/**
|
|
7
|
+
* Resolves path to a namespace path
|
|
8
|
+
* @param path to resolve to namespace
|
|
9
|
+
*/
|
|
10
|
+
export function posixToNamespacedPath(path) {
|
|
11
|
+
// Non-op on posix systems
|
|
12
|
+
return path;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolves path to a namespace path
|
|
16
|
+
* @param path to resolve to namespace
|
|
17
|
+
*/
|
|
18
|
+
export function windowsToNamespacedPath(path) {
|
|
19
|
+
// Note: this will *probably* throw somewhere.
|
|
20
|
+
if (typeof path !== "string")
|
|
21
|
+
return path;
|
|
22
|
+
if (path.length === 0)
|
|
23
|
+
return "";
|
|
24
|
+
const resolvedPath = windowsResolve(path);
|
|
25
|
+
if (resolvedPath.length >= 3) {
|
|
26
|
+
if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) {
|
|
27
|
+
// Possible UNC root
|
|
28
|
+
if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) {
|
|
29
|
+
const code = resolvedPath.charCodeAt(2);
|
|
30
|
+
if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) {
|
|
31
|
+
// Matched non-long UNC root, convert the path to a long UNC path
|
|
32
|
+
return `\\\\?\\UNC\\${resolvedPath.slice(2)}`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (isWindowsDeviceRoot(resolvedPath.charCodeAt(0))) {
|
|
37
|
+
// Possible device root
|
|
38
|
+
if (resolvedPath.charCodeAt(1) === CHAR_COLON &&
|
|
39
|
+
resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) {
|
|
40
|
+
// Matched device root, convert the path to a long UNC path
|
|
41
|
+
return `\\\\?\\${resolvedPath}`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return path;
|
|
46
|
+
}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import type { FormatInputPathObject } from "./_interface.js";
|
|
2
1
|
export declare function assertPath(path: string): void;
|
|
3
2
|
export declare function isPosixPathSeparator(code: number): boolean;
|
|
4
3
|
export declare function isPathSeparator(code: number): boolean;
|
|
5
4
|
export declare function isWindowsDeviceRoot(code: number): boolean;
|
|
6
5
|
export declare function normalizeString(path: string, allowAboveRoot: boolean, separator: string, isPathSeparator: (code: number) => boolean): string;
|
|
7
|
-
export declare function _format(sep: string, pathObject: FormatInputPathObject): string;
|
|
8
|
-
export declare function encodeWhitespace(string: string): string;
|
|
9
|
-
export declare function lastPathSegment(path: string, isSep: (char: number) => boolean, start?: number): string;
|
|
10
6
|
export declare function stripTrailingSeparators(segment: string, isSep: (char: number) => boolean): string;
|
|
11
|
-
export declare function stripSuffix(name: string, suffix: string): string;
|
|
@@ -90,48 +90,6 @@ export function normalizeString(path, allowAboveRoot, separator, isPathSeparator
|
|
|
90
90
|
}
|
|
91
91
|
return res;
|
|
92
92
|
}
|
|
93
|
-
export function _format(sep, pathObject) {
|
|
94
|
-
const dir = pathObject.dir || pathObject.root;
|
|
95
|
-
const base = pathObject.base ||
|
|
96
|
-
(pathObject.name || "") + (pathObject.ext || "");
|
|
97
|
-
if (!dir)
|
|
98
|
-
return base;
|
|
99
|
-
if (base === sep)
|
|
100
|
-
return dir;
|
|
101
|
-
if (dir === pathObject.root)
|
|
102
|
-
return dir + base;
|
|
103
|
-
return dir + sep + base;
|
|
104
|
-
}
|
|
105
|
-
const WHITESPACE_ENCODINGS = {
|
|
106
|
-
"\u0009": "%09",
|
|
107
|
-
"\u000A": "%0A",
|
|
108
|
-
"\u000B": "%0B",
|
|
109
|
-
"\u000C": "%0C",
|
|
110
|
-
"\u000D": "%0D",
|
|
111
|
-
"\u0020": "%20",
|
|
112
|
-
};
|
|
113
|
-
export function encodeWhitespace(string) {
|
|
114
|
-
return string.replaceAll(/[\s]/g, (c) => {
|
|
115
|
-
return WHITESPACE_ENCODINGS[c] ?? c;
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
export function lastPathSegment(path, isSep, start = 0) {
|
|
119
|
-
let matchedNonSeparator = false;
|
|
120
|
-
let end = path.length;
|
|
121
|
-
for (let i = path.length - 1; i >= start; --i) {
|
|
122
|
-
if (isSep(path.charCodeAt(i))) {
|
|
123
|
-
if (matchedNonSeparator) {
|
|
124
|
-
start = i + 1;
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
else if (!matchedNonSeparator) {
|
|
129
|
-
matchedNonSeparator = true;
|
|
130
|
-
end = i + 1;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return path.slice(start, end);
|
|
134
|
-
}
|
|
135
93
|
export function stripTrailingSeparators(segment, isSep) {
|
|
136
94
|
if (segment.length <= 1) {
|
|
137
95
|
return segment;
|
|
@@ -147,15 +105,3 @@ export function stripTrailingSeparators(segment, isSep) {
|
|
|
147
105
|
}
|
|
148
106
|
return segment.slice(0, end);
|
|
149
107
|
}
|
|
150
|
-
export function stripSuffix(name, suffix) {
|
|
151
|
-
if (suffix.length >= name.length) {
|
|
152
|
-
return name;
|
|
153
|
-
}
|
|
154
|
-
const lenDiff = name.length - suffix.length;
|
|
155
|
-
for (let i = suffix.length - 1; i >= 0; --i) {
|
|
156
|
-
if (name.charCodeAt(lenDiff + i) !== suffix.charCodeAt(i)) {
|
|
157
|
-
return name;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return name.slice(0, -suffix.length);
|
|
161
|
-
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Return the last portion of a `path`.
|
|
3
|
+
* Trailing directory separators are ignored, and optional suffix is removed.
|
|
4
|
+
*
|
|
5
|
+
* @param path - path to extract the name from.
|
|
6
|
+
* @param [suffix] - suffix to remove from extracted name.
|
|
7
|
+
*/
|
|
8
|
+
export declare function basename(path: string, suffix?: string): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
import { isWindows } from "./_os.js";
|
|
4
|
+
import { posixBasename, windowsBasename } from "./_basename.js";
|
|
5
|
+
/**
|
|
6
|
+
* Return the last portion of a `path`.
|
|
7
|
+
* Trailing directory separators are ignored, and optional suffix is removed.
|
|
8
|
+
*
|
|
9
|
+
* @param path - path to extract the name from.
|
|
10
|
+
* @param [suffix] - suffix to remove from extracted name.
|
|
11
|
+
*/
|
|
12
|
+
export function basename(path, suffix = "") {
|
|
13
|
+
return isWindows
|
|
14
|
+
? windowsBasename(path, suffix)
|
|
15
|
+
: posixBasename(path, suffix);
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
import { isWindows } from "./_os.js";
|
|
4
|
+
import { posixDirname, windowsDirname } from "./_dirname.js";
|
|
5
|
+
/**
|
|
6
|
+
* Return the directory path of a `path`.
|
|
7
|
+
* @param path - path to extract the directory from.
|
|
8
|
+
*/
|
|
9
|
+
export function dirname(path) {
|
|
10
|
+
return isWindows ? windowsDirname(path) : posixDirname(path);
|
|
11
|
+
}
|