@jsenv/urls 1.0.0 → 1.1.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/main.js +17 -0
- package/package.json +13 -5
- package/src/caller_position.js +1 -1
- package/src/common_pathname.js +42 -0
- package/src/ensure_url_trailing_slash.js +3 -0
- package/src/filesystem_path_to_url.js +10 -0
- package/src/inline_content_url_generator.js +1 -1
- package/src/is_filesystem_path.js +21 -0
- package/src/move_url.js +10 -0
- package/src/resolve_directory_url.js +7 -0
- package/src/resolve_url.js +6 -0
- package/src/url_is_inside_of.js +17 -0
- package/src/url_to_basename.js +9 -0
- package/src/url_to_extension.js +19 -0
- package/src/url_to_filename.js +14 -0
- package/src/url_to_filesystem_path.js +12 -0
- package/src/url_to_origin.js +7 -0
- package/src/url_to_parent_url.js +31 -0
- package/src/url_to_pathname.js +19 -0
- package/src/url_to_relative_url.js +56 -0
- package/src/url_to_ressource.js +21 -0
- package/src/url_to_scheme.js +10 -0
- package/src/url_trace.js +1 -1
- package/src/url_utils.js +3 -1
- package/docs/url_meta/advanced.md +0 -28
- package/docs/url_meta/demo/apply_associations.mjs +0 -27
- package/docs/url_meta/demo/full_match.mjs +0 -7
- package/docs/url_meta/demo/partial_match.mjs +0 -7
- package/docs/url_meta/demo/resolve_associations.mjs +0 -12
- package/docs/url_meta/notes.md +0 -26
- package/docs/url_meta/pattern_matching.md +0 -71
- package/docs/url_meta/readme.md +0 -87
- package/test/data_url.test.mjs +0 -57
- package/test/meta/aliasing.test.mjs +0 -47
- package/test/meta/as_flat_associations/basic.test.mjs +0 -64
- package/test/meta/assertions.test.mjs +0 -23
- package/test/meta/get_url_meta/any.test.mjs +0 -94
- package/test/meta/get_url_meta/basic.test.mjs +0 -226
- package/test/meta/get_url_meta/complex.test.mjs +0 -203
- package/test/meta/get_url_meta/double_wildcard_after.test.mjs +0 -68
- package/test/meta/get_url_meta/double_wildcard_around.test.mjs +0 -42
- package/test/meta/get_url_meta/double_wildcard_before.test.mjs +0 -55
- package/test/meta/get_url_meta/inheritance.test.mjs +0 -59
- package/test/meta/is_plain_object.test.mjs +0 -27
- package/test/meta/pattern_matching/basic.test.mjs +0 -100
- package/test/meta/pattern_matching/common.test.mjs +0 -145
- package/test/meta/pattern_matching/complex.test.mjs +0 -159
- package/test/meta/pattern_matching/contains.test.mjs +0 -46
- package/test/meta/pattern_matching/doublewildcard_after.test.mjs +0 -81
- package/test/meta/pattern_matching/doublewildcard_around.test.mjs +0 -42
- package/test/meta/pattern_matching/doublewildcard_before.test.mjs +0 -68
- package/test/meta/pattern_matching/doublewildcard_inside.test.mjs +0 -42
- package/test/meta/pattern_matching/trailing_slash.test.mjs +0 -55
- package/test/meta/pattern_matching/wildcard_after.test.mjs +0 -68
- package/test/meta/pattern_matching/wildcard_around.test.mjs +0 -94
- package/test/meta/pattern_matching/wildcard_before.test.mjs +0 -55
- package/test/meta/pattern_matching/wildcard_inside.test.mjs +0 -68
- package/test/meta/resolve_associations/basic.test.mjs +0 -42
- package/test/meta/resolve_associations/http_pattern.test.mjs +0 -35
- package/test/meta/url_child_may_match/inheritance.test.mjs +0 -71
- package/test/meta/url_child_may_match/url_child_may_match.test.mjs +0 -166
- package/test/url_trace.test.mjs +0 -224
- package/test.mjs +0 -13
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import { assert } from "@jsenv/assert"
|
|
2
|
-
|
|
3
|
-
import { URL_META } from "@jsenv/urls"
|
|
4
|
-
|
|
5
|
-
{
|
|
6
|
-
const actual = URL_META.applyAssociations({
|
|
7
|
-
url: "file:///file.es5.js/file.es5.js.map",
|
|
8
|
-
associations: {
|
|
9
|
-
js: {
|
|
10
|
-
"file:///**/*.js": true,
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
})
|
|
14
|
-
const expected = {}
|
|
15
|
-
assert({ actual, expected })
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
{
|
|
19
|
-
const actual = URL_META.applyAssociations({
|
|
20
|
-
url: "file:///file.es5.js/file.es5.js.map",
|
|
21
|
-
associations: {
|
|
22
|
-
js: {
|
|
23
|
-
"file:///**/*.js": true,
|
|
24
|
-
"file:///**/*.js/**": false,
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
})
|
|
28
|
-
const expected = { js: false }
|
|
29
|
-
assert({ actual, expected })
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
{
|
|
33
|
-
const actual = URL_META.applyAssociations({
|
|
34
|
-
url: "file:///file.js.map",
|
|
35
|
-
associations: {
|
|
36
|
-
js: {
|
|
37
|
-
"file:///**/*.js": true,
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
})
|
|
41
|
-
const expected = {}
|
|
42
|
-
assert({ actual, expected })
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
{
|
|
46
|
-
const associations = {
|
|
47
|
-
format: {
|
|
48
|
-
"file:///**/*.js": true,
|
|
49
|
-
"file:///**/*.jsx": true,
|
|
50
|
-
"file:///build": false,
|
|
51
|
-
"file:///src/exception.js": false,
|
|
52
|
-
},
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
{
|
|
56
|
-
const actual = URL_META.applyAssociations({
|
|
57
|
-
url: "file:///index.js",
|
|
58
|
-
associations,
|
|
59
|
-
})
|
|
60
|
-
const expected = { format: true }
|
|
61
|
-
assert({ actual, expected })
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
{
|
|
65
|
-
const actual = URL_META.applyAssociations({
|
|
66
|
-
url: "file:///src/file.js",
|
|
67
|
-
associations,
|
|
68
|
-
})
|
|
69
|
-
const expected = { format: true }
|
|
70
|
-
assert({ actual, expected })
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
{
|
|
74
|
-
const actual = URL_META.applyAssociations({
|
|
75
|
-
url: "file:///src/folder/file.js",
|
|
76
|
-
associations,
|
|
77
|
-
})
|
|
78
|
-
const expected = { format: true }
|
|
79
|
-
assert({ actual, expected })
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
{
|
|
83
|
-
const actual = URL_META.applyAssociations({
|
|
84
|
-
url: "file:///index.test.js",
|
|
85
|
-
associations,
|
|
86
|
-
})
|
|
87
|
-
const expected = { format: true }
|
|
88
|
-
assert({ actual, expected })
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
{
|
|
92
|
-
const actual = URL_META.applyAssociations({
|
|
93
|
-
url: "file:///src/file.test.js",
|
|
94
|
-
associations,
|
|
95
|
-
})
|
|
96
|
-
const expected = { format: true }
|
|
97
|
-
assert({ actual, expected })
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
{
|
|
101
|
-
const actual = URL_META.applyAssociations({
|
|
102
|
-
url: "file:///src/folder/file.test.js",
|
|
103
|
-
associations,
|
|
104
|
-
})
|
|
105
|
-
const expected = { format: true }
|
|
106
|
-
assert({ actual, expected })
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
{
|
|
110
|
-
const actual = URL_META.applyAssociations({
|
|
111
|
-
url: "file:///src/exception.js",
|
|
112
|
-
associations,
|
|
113
|
-
})
|
|
114
|
-
const expected = { format: false }
|
|
115
|
-
assert({ actual, expected })
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
{
|
|
120
|
-
const associations = {
|
|
121
|
-
cover: {
|
|
122
|
-
"file:///index.js": true,
|
|
123
|
-
"file:///src/**/*.js": true,
|
|
124
|
-
"file:///src/**/*.jsx": true,
|
|
125
|
-
"file:///**/*.test.js": false,
|
|
126
|
-
"file:///**/*.test.jsx": false,
|
|
127
|
-
"file:///build/": false,
|
|
128
|
-
"file:///src/exception.js": false,
|
|
129
|
-
},
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
{
|
|
133
|
-
const actual = URL_META.applyAssociations({
|
|
134
|
-
associations,
|
|
135
|
-
url: "file:///index.js",
|
|
136
|
-
})
|
|
137
|
-
const expected = { cover: true }
|
|
138
|
-
assert({ actual, expected })
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
{
|
|
142
|
-
const actual = URL_META.applyAssociations({
|
|
143
|
-
associations,
|
|
144
|
-
url: "file:///src/file.js",
|
|
145
|
-
})
|
|
146
|
-
const expected = { cover: true }
|
|
147
|
-
assert({ actual, expected })
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
{
|
|
151
|
-
const actual = URL_META.applyAssociations({
|
|
152
|
-
associations,
|
|
153
|
-
url: "file:///src/folder/file.js",
|
|
154
|
-
})
|
|
155
|
-
const expected = { cover: true }
|
|
156
|
-
assert({ actual, expected })
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
{
|
|
160
|
-
const actual = URL_META.applyAssociations({
|
|
161
|
-
associations,
|
|
162
|
-
url: "file:///index.test.js",
|
|
163
|
-
})
|
|
164
|
-
const expected = { cover: false }
|
|
165
|
-
assert({ actual, expected })
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
{
|
|
169
|
-
const actual = URL_META.applyAssociations({
|
|
170
|
-
associations,
|
|
171
|
-
url: "file:///src/file.test.js",
|
|
172
|
-
})
|
|
173
|
-
const expected = { cover: false }
|
|
174
|
-
assert({ actual, expected })
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
{
|
|
178
|
-
const actual = URL_META.applyAssociations({
|
|
179
|
-
associations,
|
|
180
|
-
url: "file:///src/folder/file.test.js",
|
|
181
|
-
})
|
|
182
|
-
const expected = { cover: false }
|
|
183
|
-
assert({ actual, expected })
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
{
|
|
187
|
-
const actual = URL_META.applyAssociations({
|
|
188
|
-
associations,
|
|
189
|
-
url: "file:///build/index.js",
|
|
190
|
-
})
|
|
191
|
-
const expected = { cover: false }
|
|
192
|
-
assert({ actual, expected })
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
{
|
|
196
|
-
const actual = URL_META.applyAssociations({
|
|
197
|
-
associations,
|
|
198
|
-
url: "file:///src/exception.js",
|
|
199
|
-
})
|
|
200
|
-
const expected = { cover: false }
|
|
201
|
-
assert({ actual, expected })
|
|
202
|
-
}
|
|
203
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { assert } from "@jsenv/assert"
|
|
2
|
-
|
|
3
|
-
import { URL_META } from "@jsenv/urls"
|
|
4
|
-
|
|
5
|
-
{
|
|
6
|
-
const actual = URL_META.applyAssociations({
|
|
7
|
-
url: "file:///a",
|
|
8
|
-
associations: {
|
|
9
|
-
a: {
|
|
10
|
-
"file:///a/**": true,
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
})
|
|
14
|
-
const expected = {}
|
|
15
|
-
assert({ actual, expected })
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
{
|
|
19
|
-
const actual = URL_META.applyAssociations({
|
|
20
|
-
url: "file:///a/b",
|
|
21
|
-
associations: {
|
|
22
|
-
a: {
|
|
23
|
-
"file:///a/**": true,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
})
|
|
27
|
-
const expected = { a: true }
|
|
28
|
-
assert({ actual, expected })
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
{
|
|
32
|
-
const actual = URL_META.applyAssociations({
|
|
33
|
-
url: "file:///a/b/c",
|
|
34
|
-
associations: {
|
|
35
|
-
a: {
|
|
36
|
-
"file:///a/**": true,
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
})
|
|
40
|
-
const expected = { a: true }
|
|
41
|
-
assert({ actual, expected })
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
{
|
|
45
|
-
const actual = URL_META.applyAssociations({
|
|
46
|
-
url: "file:///a/a.js",
|
|
47
|
-
associations: {
|
|
48
|
-
a: {
|
|
49
|
-
"file:///a/**": true,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
})
|
|
53
|
-
const expected = { a: true }
|
|
54
|
-
assert({ actual, expected })
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
{
|
|
58
|
-
const actual = URL_META.applyAssociations({
|
|
59
|
-
url: "file:///a.js",
|
|
60
|
-
associations: {
|
|
61
|
-
a: {
|
|
62
|
-
"file:///a/**": true,
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
})
|
|
66
|
-
const expected = {}
|
|
67
|
-
assert({ actual, expected })
|
|
68
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { assert } from "@jsenv/assert"
|
|
2
|
-
|
|
3
|
-
import { URL_META } from "@jsenv/urls"
|
|
4
|
-
|
|
5
|
-
{
|
|
6
|
-
const actual = URL_META.applyAssociations({
|
|
7
|
-
url: "file:///a",
|
|
8
|
-
associations: {
|
|
9
|
-
a: {
|
|
10
|
-
"file:///**/a/**": true,
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
})
|
|
14
|
-
const expected = {}
|
|
15
|
-
assert({ actual, expected })
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
{
|
|
19
|
-
const actual = URL_META.applyAssociations({
|
|
20
|
-
url: "file:///a/b",
|
|
21
|
-
associations: {
|
|
22
|
-
a: {
|
|
23
|
-
"file:///**/a/**": true,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
})
|
|
27
|
-
const expected = { a: true }
|
|
28
|
-
assert({ actual, expected })
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
{
|
|
32
|
-
const actual = URL_META.applyAssociations({
|
|
33
|
-
url: "file:///b/a/c",
|
|
34
|
-
associations: {
|
|
35
|
-
a: {
|
|
36
|
-
"file:///**/a/**": true,
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
})
|
|
40
|
-
const expected = { a: true }
|
|
41
|
-
assert({ actual, expected })
|
|
42
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { assert } from "@jsenv/assert"
|
|
2
|
-
|
|
3
|
-
import { URL_META } from "@jsenv/urls"
|
|
4
|
-
|
|
5
|
-
{
|
|
6
|
-
const actual = URL_META.applyAssociations({
|
|
7
|
-
url: "file:///a",
|
|
8
|
-
associations: {
|
|
9
|
-
a: {
|
|
10
|
-
"file:///**/a": true,
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
})
|
|
14
|
-
const expected = { a: true }
|
|
15
|
-
assert({ actual, expected })
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
{
|
|
19
|
-
const actual = URL_META.applyAssociations({
|
|
20
|
-
url: "file:///b/a",
|
|
21
|
-
associations: {
|
|
22
|
-
a: {
|
|
23
|
-
"file:///**/a": true,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
})
|
|
27
|
-
const expected = { a: true }
|
|
28
|
-
assert({ actual, expected })
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
{
|
|
32
|
-
const actual = URL_META.applyAssociations({
|
|
33
|
-
url: "file:///c/b/a",
|
|
34
|
-
associations: {
|
|
35
|
-
a: {
|
|
36
|
-
"file:///**/a": true,
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
})
|
|
40
|
-
const expected = { a: true }
|
|
41
|
-
assert({ actual, expected })
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
{
|
|
45
|
-
const actual = URL_META.applyAssociations({
|
|
46
|
-
url: "file:///a.js",
|
|
47
|
-
associations: {
|
|
48
|
-
a: {
|
|
49
|
-
"file:///**/a": true,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
})
|
|
53
|
-
const expected = {}
|
|
54
|
-
assert({ actual, expected })
|
|
55
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { assert } from "@jsenv/assert"
|
|
2
|
-
|
|
3
|
-
import { URL_META } from "@jsenv/urls"
|
|
4
|
-
|
|
5
|
-
{
|
|
6
|
-
const actual = URL_META.applyAssociations({
|
|
7
|
-
url: "file:///file.js",
|
|
8
|
-
associations: {
|
|
9
|
-
whatever: {
|
|
10
|
-
"file:///**/*": true,
|
|
11
|
-
"file:///.git/": false,
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
})
|
|
15
|
-
const expected = { whatever: true }
|
|
16
|
-
assert({ actual, expected })
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
{
|
|
20
|
-
const actual = URL_META.applyAssociations({
|
|
21
|
-
url: "file:///.git/file.js",
|
|
22
|
-
associations: {
|
|
23
|
-
whatever: {
|
|
24
|
-
"file:///**/*": true,
|
|
25
|
-
"file:///.git/": false,
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
})
|
|
29
|
-
const expected = { whatever: false }
|
|
30
|
-
assert({ actual, expected })
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
{
|
|
34
|
-
const actual = URL_META.applyAssociations({
|
|
35
|
-
url: "file:///file.js",
|
|
36
|
-
associations: {
|
|
37
|
-
whatever: {
|
|
38
|
-
"file:///**/*": false,
|
|
39
|
-
"file:///*": true,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
})
|
|
43
|
-
const expected = { whatever: true }
|
|
44
|
-
assert({ actual, expected })
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
{
|
|
48
|
-
const actual = URL_META.applyAssociations({
|
|
49
|
-
url: "file:///.git/file.js",
|
|
50
|
-
associations: {
|
|
51
|
-
whatever: {
|
|
52
|
-
"file:///**/*": false,
|
|
53
|
-
"file:///*": true,
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
})
|
|
57
|
-
const expected = { whatever: false }
|
|
58
|
-
assert({ actual, expected })
|
|
59
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { assert } from "@jsenv/assert"
|
|
2
|
-
|
|
3
|
-
import { isPlainObject } from "@jsenv/urls/src/meta/assertions.js"
|
|
4
|
-
|
|
5
|
-
{
|
|
6
|
-
const actual = isPlainObject({})
|
|
7
|
-
const expected = true
|
|
8
|
-
assert({ actual, expected })
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
{
|
|
12
|
-
const actual = isPlainObject(null)
|
|
13
|
-
const expected = false
|
|
14
|
-
assert({ actual, expected })
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
{
|
|
18
|
-
const actual = isPlainObject([])
|
|
19
|
-
const expected = false
|
|
20
|
-
assert({ actual, expected })
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
{
|
|
24
|
-
const actual = isPlainObject("whatever")
|
|
25
|
-
const expected = false
|
|
26
|
-
assert({ actual, expected })
|
|
27
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { assert } from "@jsenv/assert"
|
|
2
|
-
|
|
3
|
-
import { URL_META } from "@jsenv/urls"
|
|
4
|
-
|
|
5
|
-
{
|
|
6
|
-
const pattern = "file:///.git/"
|
|
7
|
-
const url = "file:///.github/"
|
|
8
|
-
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
9
|
-
const expected = {
|
|
10
|
-
matched: false,
|
|
11
|
-
patternIndex: pattern.lastIndexOf("/"),
|
|
12
|
-
urlIndex: url.indexOf("hub"),
|
|
13
|
-
matchGroups: [],
|
|
14
|
-
}
|
|
15
|
-
assert({ actual, expected })
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
URL_META.applyPatternMatching({
|
|
20
|
-
pattern: 10,
|
|
21
|
-
})
|
|
22
|
-
throw new Error("should throw")
|
|
23
|
-
} catch (actual) {
|
|
24
|
-
const expected = new TypeError("pattern must be a url string, got 10")
|
|
25
|
-
assert({ actual, expected })
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
URL_META.applyPatternMatching({
|
|
30
|
-
pattern: "C://Users/folder/file.js",
|
|
31
|
-
})
|
|
32
|
-
throw new Error("should throw")
|
|
33
|
-
} catch (actual) {
|
|
34
|
-
const expected = new TypeError(
|
|
35
|
-
"pattern must be a url but looks like a windows pathname, got C://Users/folder/file.js",
|
|
36
|
-
)
|
|
37
|
-
assert({ actual, expected })
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
URL_META.applyPatternMatching({
|
|
42
|
-
pattern: "hello",
|
|
43
|
-
})
|
|
44
|
-
throw new Error("should throw")
|
|
45
|
-
} catch (actual) {
|
|
46
|
-
const expected = new TypeError(
|
|
47
|
-
"pattern must be a url and no scheme found, got hello",
|
|
48
|
-
)
|
|
49
|
-
assert({ actual, expected })
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
URL_META.applyPatternMatching({
|
|
54
|
-
pattern: "http://",
|
|
55
|
-
url: 10,
|
|
56
|
-
})
|
|
57
|
-
throw new Error("should throw")
|
|
58
|
-
} catch (actual) {
|
|
59
|
-
const expected = new TypeError("url must be a url string, got 10")
|
|
60
|
-
assert({ actual, expected })
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
{
|
|
64
|
-
const pattern = "file:///foo.js"
|
|
65
|
-
const url = "file:///foo.js"
|
|
66
|
-
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
67
|
-
const expected = {
|
|
68
|
-
matched: true,
|
|
69
|
-
patternIndex: pattern.length,
|
|
70
|
-
urlIndex: url.length,
|
|
71
|
-
matchGroups: [],
|
|
72
|
-
}
|
|
73
|
-
assert({ actual, expected })
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
{
|
|
77
|
-
const pattern = "http:///foo.js"
|
|
78
|
-
const url = "file:///foo.js"
|
|
79
|
-
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
80
|
-
const expected = {
|
|
81
|
-
matched: false,
|
|
82
|
-
patternIndex: 0,
|
|
83
|
-
urlIndex: 0,
|
|
84
|
-
matchGroups: [],
|
|
85
|
-
}
|
|
86
|
-
assert({ actual, expected })
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
{
|
|
90
|
-
const pattern = "file:///bar.js"
|
|
91
|
-
const url = "file:///foo.js"
|
|
92
|
-
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
93
|
-
const expected = {
|
|
94
|
-
matched: false,
|
|
95
|
-
patternIndex: pattern.indexOf("bar.js"),
|
|
96
|
-
urlIndex: url.indexOf("foo.js"),
|
|
97
|
-
matchGroups: [],
|
|
98
|
-
}
|
|
99
|
-
assert({ actual, expected })
|
|
100
|
-
}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { assert } from "@jsenv/assert"
|
|
2
|
-
|
|
3
|
-
import { URL_META } from "@jsenv/urls"
|
|
4
|
-
|
|
5
|
-
// any file
|
|
6
|
-
{
|
|
7
|
-
const pattern = "file:///**/"
|
|
8
|
-
{
|
|
9
|
-
const { matched: actual } = URL_META.applyPatternMatching({
|
|
10
|
-
pattern,
|
|
11
|
-
url: "file:///file.js",
|
|
12
|
-
})
|
|
13
|
-
const expected = true
|
|
14
|
-
assert({ actual, expected })
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
{
|
|
18
|
-
const { matched: actual } = URL_META.applyPatternMatching({
|
|
19
|
-
pattern,
|
|
20
|
-
url: "file:///dir/file.js",
|
|
21
|
-
})
|
|
22
|
-
const expected = true
|
|
23
|
-
assert({ actual, expected })
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
{
|
|
27
|
-
const { matched: actual } = URL_META.applyPatternMatching({
|
|
28
|
-
pattern,
|
|
29
|
-
url: "file:///.git/dir/file.js",
|
|
30
|
-
})
|
|
31
|
-
const expected = true
|
|
32
|
-
assert({ actual, expected })
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// only root files
|
|
37
|
-
{
|
|
38
|
-
const pattern = "file:///*"
|
|
39
|
-
{
|
|
40
|
-
const { matched: actual } = URL_META.applyPatternMatching({
|
|
41
|
-
pattern,
|
|
42
|
-
url: "file:///file.js",
|
|
43
|
-
})
|
|
44
|
-
const expected = true
|
|
45
|
-
assert({ actual, expected })
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
{
|
|
49
|
-
const { matched: actual } = URL_META.applyPatternMatching({
|
|
50
|
-
pattern,
|
|
51
|
-
url: "file:///dir/file.js",
|
|
52
|
-
})
|
|
53
|
-
const expected = false
|
|
54
|
-
assert({ actual, expected })
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
{
|
|
58
|
-
const { matched: actual } = URL_META.applyPatternMatching({
|
|
59
|
-
pattern,
|
|
60
|
-
url: "file:///dir/foo/file.js",
|
|
61
|
-
})
|
|
62
|
-
const expected = false
|
|
63
|
-
assert({ actual, expected })
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// only files inside directory
|
|
68
|
-
{
|
|
69
|
-
const pattern = "file:///*/**"
|
|
70
|
-
{
|
|
71
|
-
const { matched: actual } = URL_META.applyPatternMatching({
|
|
72
|
-
pattern,
|
|
73
|
-
url: "file:///file.js",
|
|
74
|
-
})
|
|
75
|
-
const expected = false
|
|
76
|
-
assert({ actual, expected })
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
{
|
|
80
|
-
const { matched: actual } = URL_META.applyPatternMatching({
|
|
81
|
-
pattern,
|
|
82
|
-
url: "file:///dir/file.js",
|
|
83
|
-
})
|
|
84
|
-
const expected = true
|
|
85
|
-
assert({ actual, expected })
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
{
|
|
89
|
-
const { matched: actual } = URL_META.applyPatternMatching({
|
|
90
|
-
pattern,
|
|
91
|
-
url: "file:///dir/foo/file.js",
|
|
92
|
-
})
|
|
93
|
-
const expected = true
|
|
94
|
-
assert({ actual, expected })
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// only files inside directory starting with .
|
|
99
|
-
{
|
|
100
|
-
const pattern = "file:///**/.*/*"
|
|
101
|
-
{
|
|
102
|
-
const { matched: actual } = URL_META.applyPatternMatching({
|
|
103
|
-
pattern,
|
|
104
|
-
url: "file:///.git/file.js",
|
|
105
|
-
})
|
|
106
|
-
const expected = true
|
|
107
|
-
assert({ actual, expected })
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
{
|
|
111
|
-
const { matched: actual } = URL_META.applyPatternMatching({
|
|
112
|
-
pattern,
|
|
113
|
-
url: "file:///dir/.git/file.js",
|
|
114
|
-
})
|
|
115
|
-
const expected = true
|
|
116
|
-
assert({ actual, expected })
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
{
|
|
120
|
-
const { matched: actual } = URL_META.applyPatternMatching({
|
|
121
|
-
pattern,
|
|
122
|
-
url: "file:///file.js",
|
|
123
|
-
})
|
|
124
|
-
const expected = false
|
|
125
|
-
assert({ actual, expected })
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
{
|
|
129
|
-
const { matched: actual } = URL_META.applyPatternMatching({
|
|
130
|
-
pattern,
|
|
131
|
-
url: "file:///dir/file.js",
|
|
132
|
-
})
|
|
133
|
-
const expected = false
|
|
134
|
-
assert({ actual, expected })
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
{
|
|
138
|
-
const { matched: actual } = URL_META.applyPatternMatching({
|
|
139
|
-
pattern,
|
|
140
|
-
url: "file:///.file.js",
|
|
141
|
-
})
|
|
142
|
-
const expected = false
|
|
143
|
-
assert({ actual, expected })
|
|
144
|
-
}
|
|
145
|
-
}
|