@jsenv/urls 1.0.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/docs/url_meta/advanced.md +28 -0
- package/docs/url_meta/demo/apply_associations.mjs +27 -0
- package/docs/url_meta/demo/full_match.mjs +7 -0
- package/docs/url_meta/demo/partial_match.mjs +7 -0
- package/docs/url_meta/demo/resolve_associations.mjs +12 -0
- package/docs/url_meta/notes.md +26 -0
- package/docs/url_meta/pattern_matching.md +71 -0
- package/docs/url_meta/readme.md +87 -0
- package/main.js +27 -0
- package/package.json +28 -0
- package/src/caller_position.js +20 -0
- package/src/data_url.js +50 -0
- package/src/inline_content_url_generator.js +21 -0
- package/src/meta/aliases.js +28 -0
- package/src/meta/as_flat_associations.js +28 -0
- package/src/meta/assertions.js +57 -0
- package/src/meta/associations.js +25 -0
- package/src/meta/pattern_matching.js +245 -0
- package/src/meta/resolve_associations.js +25 -0
- package/src/meta/url_child_may_match.js +47 -0
- package/src/meta/url_meta.js +13 -0
- package/src/url_trace.js +229 -0
- package/src/url_utils.js +107 -0
- package/src/windows_file_path_utils.js +16 -0
- package/test/data_url.test.mjs +57 -0
- package/test/meta/aliasing.test.mjs +47 -0
- package/test/meta/as_flat_associations/basic.test.mjs +64 -0
- package/test/meta/assertions.test.mjs +23 -0
- package/test/meta/get_url_meta/any.test.mjs +94 -0
- package/test/meta/get_url_meta/basic.test.mjs +226 -0
- package/test/meta/get_url_meta/complex.test.mjs +203 -0
- package/test/meta/get_url_meta/double_wildcard_after.test.mjs +68 -0
- package/test/meta/get_url_meta/double_wildcard_around.test.mjs +42 -0
- package/test/meta/get_url_meta/double_wildcard_before.test.mjs +55 -0
- package/test/meta/get_url_meta/inheritance.test.mjs +59 -0
- package/test/meta/is_plain_object.test.mjs +27 -0
- package/test/meta/pattern_matching/basic.test.mjs +100 -0
- package/test/meta/pattern_matching/common.test.mjs +145 -0
- package/test/meta/pattern_matching/complex.test.mjs +159 -0
- package/test/meta/pattern_matching/contains.test.mjs +46 -0
- package/test/meta/pattern_matching/doublewildcard_after.test.mjs +81 -0
- package/test/meta/pattern_matching/doublewildcard_around.test.mjs +42 -0
- package/test/meta/pattern_matching/doublewildcard_before.test.mjs +68 -0
- package/test/meta/pattern_matching/doublewildcard_inside.test.mjs +42 -0
- package/test/meta/pattern_matching/trailing_slash.test.mjs +55 -0
- package/test/meta/pattern_matching/wildcard_after.test.mjs +68 -0
- package/test/meta/pattern_matching/wildcard_around.test.mjs +94 -0
- package/test/meta/pattern_matching/wildcard_before.test.mjs +55 -0
- package/test/meta/pattern_matching/wildcard_inside.test.mjs +68 -0
- package/test/meta/resolve_associations/basic.test.mjs +42 -0
- package/test/meta/resolve_associations/http_pattern.test.mjs +35 -0
- package/test/meta/url_child_may_match/inheritance.test.mjs +71 -0
- package/test/meta/url_child_may_match/url_child_may_match.test.mjs +166 -0
- package/test/url_trace.test.mjs +224 -0
- package/test.mjs +13 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { assert } from "@jsenv/assert"
|
|
2
|
+
|
|
3
|
+
import { URL_META } from "@jsenv/urls"
|
|
4
|
+
|
|
5
|
+
{
|
|
6
|
+
const pattern = "file:///a/**"
|
|
7
|
+
const url = "file:///a"
|
|
8
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
9
|
+
const expected = {
|
|
10
|
+
matched: false,
|
|
11
|
+
patternIndex: pattern.indexOf("/**"),
|
|
12
|
+
urlIndex: url.length,
|
|
13
|
+
matchGroups: [],
|
|
14
|
+
}
|
|
15
|
+
assert({ actual, expected })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
{
|
|
19
|
+
const pattern = "file:///a/**"
|
|
20
|
+
const url = "file:///a/b"
|
|
21
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
22
|
+
const expected = {
|
|
23
|
+
matched: true,
|
|
24
|
+
patternIndex: pattern.length,
|
|
25
|
+
urlIndex: url.length,
|
|
26
|
+
matchGroups: [],
|
|
27
|
+
}
|
|
28
|
+
assert({ actual, expected })
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
{
|
|
32
|
+
const pattern = "file:///a/**"
|
|
33
|
+
const url = "file:///a/b/c"
|
|
34
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
35
|
+
const expected = {
|
|
36
|
+
matched: true,
|
|
37
|
+
patternIndex: pattern.length,
|
|
38
|
+
urlIndex: url.length,
|
|
39
|
+
matchGroups: [],
|
|
40
|
+
}
|
|
41
|
+
assert({ actual, expected })
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
const pattern = "file:///a/**"
|
|
46
|
+
const url = "file:///a/a.js"
|
|
47
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
48
|
+
const expected = {
|
|
49
|
+
matched: true,
|
|
50
|
+
patternIndex: pattern.length,
|
|
51
|
+
urlIndex: url.length,
|
|
52
|
+
matchGroups: [],
|
|
53
|
+
}
|
|
54
|
+
assert({ actual, expected })
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
{
|
|
58
|
+
const pattern = "file:///a/**"
|
|
59
|
+
const url = "file:///a.js"
|
|
60
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
61
|
+
const expected = {
|
|
62
|
+
matched: false,
|
|
63
|
+
patternIndex: pattern.indexOf("/**"),
|
|
64
|
+
urlIndex: url.indexOf(".js"),
|
|
65
|
+
matchGroups: [],
|
|
66
|
+
}
|
|
67
|
+
assert({ actual, expected })
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
{
|
|
71
|
+
const pattern = "file:///**"
|
|
72
|
+
const url = "file:///"
|
|
73
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
74
|
+
const expected = {
|
|
75
|
+
matched: true,
|
|
76
|
+
patternIndex: pattern.length,
|
|
77
|
+
urlIndex: url.length,
|
|
78
|
+
matchGroups: [],
|
|
79
|
+
}
|
|
80
|
+
assert({ actual, expected })
|
|
81
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { assert } from "@jsenv/assert"
|
|
2
|
+
|
|
3
|
+
import { URL_META } from "@jsenv/urls"
|
|
4
|
+
|
|
5
|
+
{
|
|
6
|
+
const pattern = "file:///**/a/**/"
|
|
7
|
+
const url = "file:///a"
|
|
8
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
9
|
+
const expected = {
|
|
10
|
+
matched: false,
|
|
11
|
+
patternIndex: pattern.lastIndexOf("/**/"),
|
|
12
|
+
urlIndex: url.length,
|
|
13
|
+
matchGroups: [],
|
|
14
|
+
}
|
|
15
|
+
assert({ actual, expected })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
{
|
|
19
|
+
const pattern = "file:///**/a/**/"
|
|
20
|
+
const url = "file:///a/b/c.js"
|
|
21
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
22
|
+
const expected = {
|
|
23
|
+
matched: true,
|
|
24
|
+
patternIndex: pattern.length,
|
|
25
|
+
urlIndex: url.length,
|
|
26
|
+
matchGroups: [],
|
|
27
|
+
}
|
|
28
|
+
assert({ actual, expected })
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
{
|
|
32
|
+
const pattern = "file:///**/a/**/"
|
|
33
|
+
const url = "file:///b/a/c.js"
|
|
34
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
35
|
+
const expected = {
|
|
36
|
+
matched: true,
|
|
37
|
+
patternIndex: pattern.length,
|
|
38
|
+
urlIndex: url.length,
|
|
39
|
+
matchGroups: [],
|
|
40
|
+
}
|
|
41
|
+
assert({ actual, expected })
|
|
42
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { assert } from "@jsenv/assert"
|
|
2
|
+
|
|
3
|
+
import { URL_META } from "@jsenv/urls"
|
|
4
|
+
|
|
5
|
+
{
|
|
6
|
+
const pattern = "file:///**/a"
|
|
7
|
+
const url = "file:///a"
|
|
8
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
9
|
+
const expected = {
|
|
10
|
+
matched: true,
|
|
11
|
+
patternIndex: pattern.length,
|
|
12
|
+
urlIndex: url.length,
|
|
13
|
+
matchGroups: [],
|
|
14
|
+
}
|
|
15
|
+
assert({ actual, expected })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
{
|
|
19
|
+
const pattern = "file:///**/a/"
|
|
20
|
+
const url = "file:///a"
|
|
21
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
22
|
+
const expected = {
|
|
23
|
+
matched: false,
|
|
24
|
+
patternIndex: pattern.lastIndexOf("/"),
|
|
25
|
+
urlIndex: url.length,
|
|
26
|
+
matchGroups: [],
|
|
27
|
+
}
|
|
28
|
+
assert({ actual, expected })
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
{
|
|
32
|
+
const pattern = "file:///**/a"
|
|
33
|
+
const url = "file:///b/a"
|
|
34
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
35
|
+
const expected = {
|
|
36
|
+
matched: true,
|
|
37
|
+
patternIndex: pattern.length,
|
|
38
|
+
urlIndex: url.length,
|
|
39
|
+
matchGroups: [],
|
|
40
|
+
}
|
|
41
|
+
assert({ actual, expected })
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
const pattern = "file:///**/a"
|
|
46
|
+
const url = "file:///c/b/a"
|
|
47
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
48
|
+
const expected = {
|
|
49
|
+
matched: true,
|
|
50
|
+
patternIndex: pattern.length,
|
|
51
|
+
urlIndex: url.length,
|
|
52
|
+
matchGroups: [],
|
|
53
|
+
}
|
|
54
|
+
assert({ actual, expected })
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
{
|
|
58
|
+
const pattern = "file:///**/a"
|
|
59
|
+
const url = "file:///a.js"
|
|
60
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
61
|
+
const expected = {
|
|
62
|
+
matched: false,
|
|
63
|
+
patternIndex: pattern.length,
|
|
64
|
+
urlIndex: url.length,
|
|
65
|
+
matchGroups: [],
|
|
66
|
+
}
|
|
67
|
+
assert({ actual, expected })
|
|
68
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { assert } from "@jsenv/assert"
|
|
2
|
+
|
|
3
|
+
import { URL_META } from "@jsenv/urls"
|
|
4
|
+
|
|
5
|
+
{
|
|
6
|
+
const pattern = "file:///a/**/b/c"
|
|
7
|
+
const url = "file:///a/b/c"
|
|
8
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
9
|
+
const expected = {
|
|
10
|
+
matched: true,
|
|
11
|
+
patternIndex: pattern.length,
|
|
12
|
+
urlIndex: url.length,
|
|
13
|
+
matchGroups: [],
|
|
14
|
+
}
|
|
15
|
+
assert({ actual, expected })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
{
|
|
19
|
+
const pattern = "file:///**.js"
|
|
20
|
+
const url = "file:///a.js"
|
|
21
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
22
|
+
const expected = {
|
|
23
|
+
matched: true,
|
|
24
|
+
patternIndex: pattern.length,
|
|
25
|
+
urlIndex: url.length,
|
|
26
|
+
matchGroups: [],
|
|
27
|
+
}
|
|
28
|
+
assert({ actual, expected })
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
{
|
|
32
|
+
const pattern = "file:///**.js"
|
|
33
|
+
const url = "file:///.js"
|
|
34
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
35
|
+
const expected = {
|
|
36
|
+
matched: true,
|
|
37
|
+
patternIndex: pattern.length,
|
|
38
|
+
urlIndex: url.length,
|
|
39
|
+
matchGroups: [],
|
|
40
|
+
}
|
|
41
|
+
assert({ actual, expected })
|
|
42
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { assert } from "@jsenv/assert"
|
|
2
|
+
|
|
3
|
+
import { URL_META } from "@jsenv/urls"
|
|
4
|
+
|
|
5
|
+
{
|
|
6
|
+
const pattern = "file:///a/"
|
|
7
|
+
const url = "file:///a/"
|
|
8
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
9
|
+
const expected = {
|
|
10
|
+
matched: true,
|
|
11
|
+
patternIndex: pattern.length,
|
|
12
|
+
urlIndex: url.length,
|
|
13
|
+
matchGroups: ["/"],
|
|
14
|
+
}
|
|
15
|
+
assert({ actual, expected })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
{
|
|
19
|
+
const pattern = "file:///a/"
|
|
20
|
+
const url = "file:///a/b"
|
|
21
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
22
|
+
const expected = {
|
|
23
|
+
matched: true,
|
|
24
|
+
patternIndex: pattern.length,
|
|
25
|
+
urlIndex: url.length,
|
|
26
|
+
matchGroups: ["/b"],
|
|
27
|
+
}
|
|
28
|
+
assert({ actual, expected })
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
{
|
|
32
|
+
const pattern = "file:///a/"
|
|
33
|
+
const url = "file:///a"
|
|
34
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
35
|
+
const expected = {
|
|
36
|
+
matched: false,
|
|
37
|
+
patternIndex: pattern.lastIndexOf("/"),
|
|
38
|
+
urlIndex: url.length,
|
|
39
|
+
matchGroups: [],
|
|
40
|
+
}
|
|
41
|
+
assert({ actual, expected })
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
const pattern = "file:///a"
|
|
46
|
+
const url = "file:///a/b.js"
|
|
47
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
48
|
+
const expected = {
|
|
49
|
+
matched: false,
|
|
50
|
+
patternIndex: pattern.length,
|
|
51
|
+
urlIndex: url.indexOf("/b.js"),
|
|
52
|
+
matchGroups: [],
|
|
53
|
+
}
|
|
54
|
+
assert({ actual, expected })
|
|
55
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { assert } from "@jsenv/assert"
|
|
2
|
+
|
|
3
|
+
import { URL_META } from "@jsenv/urls"
|
|
4
|
+
|
|
5
|
+
{
|
|
6
|
+
const pattern = "file:///a*"
|
|
7
|
+
const url = "file:///a"
|
|
8
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
9
|
+
const expected = {
|
|
10
|
+
matched: false,
|
|
11
|
+
patternIndex: pattern.indexOf("*"),
|
|
12
|
+
urlIndex: url.length,
|
|
13
|
+
matchGroups: [""],
|
|
14
|
+
}
|
|
15
|
+
assert({ actual, expected })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
{
|
|
19
|
+
const pattern = "file:///a*"
|
|
20
|
+
const url = "file:///aZ"
|
|
21
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
22
|
+
const expected = {
|
|
23
|
+
matched: true,
|
|
24
|
+
patternIndex: pattern.length,
|
|
25
|
+
urlIndex: url.length,
|
|
26
|
+
matchGroups: ["Z"],
|
|
27
|
+
}
|
|
28
|
+
assert({ actual, expected })
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
{
|
|
32
|
+
const pattern = "file:///a*"
|
|
33
|
+
const url = "file:///aZZZ"
|
|
34
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
35
|
+
const expected = {
|
|
36
|
+
matched: true,
|
|
37
|
+
patternIndex: pattern.length,
|
|
38
|
+
urlIndex: url.length,
|
|
39
|
+
matchGroups: ["ZZZ"],
|
|
40
|
+
}
|
|
41
|
+
assert({ actual, expected })
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
const pattern = "file:///a*"
|
|
46
|
+
const url = "file:///Za"
|
|
47
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
48
|
+
const expected = {
|
|
49
|
+
matched: false,
|
|
50
|
+
patternIndex: pattern.indexOf("a*"),
|
|
51
|
+
urlIndex: url.indexOf("Za"),
|
|
52
|
+
matchGroups: [],
|
|
53
|
+
}
|
|
54
|
+
assert({ actual, expected })
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
{
|
|
58
|
+
const pattern = "file:///a*"
|
|
59
|
+
const url = "file:///a/"
|
|
60
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
61
|
+
const expected = {
|
|
62
|
+
matched: false,
|
|
63
|
+
patternIndex: pattern.indexOf("*"),
|
|
64
|
+
urlIndex: url.lastIndexOf("/"),
|
|
65
|
+
matchGroups: [""],
|
|
66
|
+
}
|
|
67
|
+
assert({ actual, expected })
|
|
68
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { assert } from "@jsenv/assert"
|
|
2
|
+
|
|
3
|
+
import { URL_META } from "@jsenv/urls"
|
|
4
|
+
|
|
5
|
+
{
|
|
6
|
+
const pattern = "file:///*a*"
|
|
7
|
+
const url = "file:///abc"
|
|
8
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
9
|
+
const expected = {
|
|
10
|
+
matched: false,
|
|
11
|
+
patternIndex: pattern.indexOf("*a*"),
|
|
12
|
+
urlIndex: url.indexOf("abc"),
|
|
13
|
+
matchGroups: [""],
|
|
14
|
+
}
|
|
15
|
+
assert({ actual, expected })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
{
|
|
19
|
+
const pattern = "file:///*a*"
|
|
20
|
+
const url = "file:///Za"
|
|
21
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
22
|
+
const expected = {
|
|
23
|
+
matched: false,
|
|
24
|
+
patternIndex: pattern.lastIndexOf("*"),
|
|
25
|
+
urlIndex: url.length,
|
|
26
|
+
matchGroups: ["Z", ""],
|
|
27
|
+
}
|
|
28
|
+
assert({ actual, expected })
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
{
|
|
32
|
+
const pattern = "file:///*a*"
|
|
33
|
+
const url = "file:///aZ"
|
|
34
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
35
|
+
const expected = {
|
|
36
|
+
matched: false,
|
|
37
|
+
patternIndex: pattern.indexOf("*a*"),
|
|
38
|
+
urlIndex: url.indexOf("aZ"),
|
|
39
|
+
matchGroups: [""],
|
|
40
|
+
}
|
|
41
|
+
assert({ actual, expected })
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
const pattern = "file:///*a*"
|
|
46
|
+
const url = "file:///ZZa"
|
|
47
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
48
|
+
const expected = {
|
|
49
|
+
matched: false,
|
|
50
|
+
patternIndex: pattern.lastIndexOf("*"),
|
|
51
|
+
urlIndex: url.length,
|
|
52
|
+
matchGroups: ["ZZ", ""],
|
|
53
|
+
}
|
|
54
|
+
assert({ actual, expected })
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
{
|
|
58
|
+
const pattern = "file:///*a*"
|
|
59
|
+
const url = "file:///aZZ"
|
|
60
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
61
|
+
const expected = {
|
|
62
|
+
matched: false,
|
|
63
|
+
patternIndex: pattern.indexOf("*a*"),
|
|
64
|
+
urlIndex: url.indexOf("aZZ"),
|
|
65
|
+
matchGroups: [""],
|
|
66
|
+
}
|
|
67
|
+
assert({ actual, expected })
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
{
|
|
71
|
+
const pattern = "file:///*a*"
|
|
72
|
+
const url = "file:///ZaY"
|
|
73
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
74
|
+
const expected = {
|
|
75
|
+
matched: true,
|
|
76
|
+
patternIndex: pattern.length,
|
|
77
|
+
urlIndex: url.length,
|
|
78
|
+
matchGroups: ["Z", "Y"],
|
|
79
|
+
}
|
|
80
|
+
assert({ actual, expected })
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
{
|
|
84
|
+
const pattern = "file:///*a*"
|
|
85
|
+
const url = "file:///ZZaYY"
|
|
86
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
87
|
+
const expected = {
|
|
88
|
+
matched: true,
|
|
89
|
+
patternIndex: pattern.length,
|
|
90
|
+
urlIndex: url.length,
|
|
91
|
+
matchGroups: ["ZZ", "YY"],
|
|
92
|
+
}
|
|
93
|
+
assert({ actual, expected })
|
|
94
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { assert } from "@jsenv/assert"
|
|
2
|
+
|
|
3
|
+
import { URL_META } from "@jsenv/urls"
|
|
4
|
+
|
|
5
|
+
{
|
|
6
|
+
const pattern = "file:///*a"
|
|
7
|
+
const url = "file:///a"
|
|
8
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
9
|
+
const expected = {
|
|
10
|
+
matched: false,
|
|
11
|
+
patternIndex: pattern.indexOf("*"),
|
|
12
|
+
urlIndex: url.indexOf("a"),
|
|
13
|
+
matchGroups: [""],
|
|
14
|
+
}
|
|
15
|
+
assert({ actual, expected })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
{
|
|
19
|
+
const pattern = "file:///*a"
|
|
20
|
+
const url = "file:///Za"
|
|
21
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
22
|
+
const expected = {
|
|
23
|
+
matched: true,
|
|
24
|
+
patternIndex: pattern.length,
|
|
25
|
+
urlIndex: url.length,
|
|
26
|
+
matchGroups: ["Z"],
|
|
27
|
+
}
|
|
28
|
+
assert({ actual, expected })
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
{
|
|
32
|
+
const pattern = "file:///*a"
|
|
33
|
+
const url = "file:///ZZZa"
|
|
34
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
35
|
+
const expected = {
|
|
36
|
+
matched: true,
|
|
37
|
+
patternIndex: pattern.length,
|
|
38
|
+
urlIndex: url.length,
|
|
39
|
+
matchGroups: ["ZZZ"],
|
|
40
|
+
}
|
|
41
|
+
assert({ actual, expected })
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
const pattern = "file:///*a"
|
|
46
|
+
const url = "file:///aZ"
|
|
47
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
48
|
+
const expected = {
|
|
49
|
+
matched: false,
|
|
50
|
+
patternIndex: pattern.indexOf("*"),
|
|
51
|
+
urlIndex: url.indexOf("a"),
|
|
52
|
+
matchGroups: [""],
|
|
53
|
+
}
|
|
54
|
+
assert({ actual, expected })
|
|
55
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { assert } from "@jsenv/assert"
|
|
2
|
+
|
|
3
|
+
import { URL_META } from "@jsenv/urls"
|
|
4
|
+
|
|
5
|
+
{
|
|
6
|
+
const pattern = "file:///a*bc"
|
|
7
|
+
const url = "file:///abc"
|
|
8
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
9
|
+
const expected = {
|
|
10
|
+
matched: false,
|
|
11
|
+
patternIndex: pattern.indexOf("*"),
|
|
12
|
+
urlIndex: url.indexOf("b"),
|
|
13
|
+
matchGroups: [""],
|
|
14
|
+
}
|
|
15
|
+
assert({ actual, expected })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
{
|
|
19
|
+
const pattern = "file:///a*bc"
|
|
20
|
+
const url = "file:///aZZbc"
|
|
21
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
22
|
+
const expected = {
|
|
23
|
+
matched: true,
|
|
24
|
+
patternIndex: pattern.length,
|
|
25
|
+
urlIndex: url.length,
|
|
26
|
+
matchGroups: ["ZZ"],
|
|
27
|
+
}
|
|
28
|
+
assert({ actual, expected })
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
{
|
|
32
|
+
const pattern = "file:///a*bc"
|
|
33
|
+
const url = "file:///aZZbd"
|
|
34
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
35
|
+
const expected = {
|
|
36
|
+
matched: false,
|
|
37
|
+
patternIndex: pattern.lastIndexOf("c"),
|
|
38
|
+
urlIndex: url.lastIndexOf("d"),
|
|
39
|
+
matchGroups: ["ZZ"],
|
|
40
|
+
}
|
|
41
|
+
assert({ actual, expected })
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
const pattern = "file:///a/b*/c"
|
|
46
|
+
const url = "file:///a/bZ/c"
|
|
47
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
48
|
+
const expected = {
|
|
49
|
+
matched: true,
|
|
50
|
+
patternIndex: pattern.length,
|
|
51
|
+
urlIndex: url.length,
|
|
52
|
+
matchGroups: ["Z"],
|
|
53
|
+
}
|
|
54
|
+
assert({ actual, expected })
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
{
|
|
58
|
+
const pattern = "file:///a/b*/c"
|
|
59
|
+
const url = "file:///a/b/c"
|
|
60
|
+
const actual = URL_META.applyPatternMatching({ pattern, url })
|
|
61
|
+
const expected = {
|
|
62
|
+
matched: false,
|
|
63
|
+
patternIndex: pattern.indexOf("*"),
|
|
64
|
+
urlIndex: url.indexOf("/c"),
|
|
65
|
+
matchGroups: [""],
|
|
66
|
+
}
|
|
67
|
+
assert({ actual, expected })
|
|
68
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { assert } from "@jsenv/assert"
|
|
2
|
+
|
|
3
|
+
import { URL_META } from "@jsenv/urls"
|
|
4
|
+
|
|
5
|
+
{
|
|
6
|
+
const actual = URL_META.resolveAssociations(
|
|
7
|
+
{
|
|
8
|
+
whatever: {
|
|
9
|
+
"./a.js": true,
|
|
10
|
+
"http://example.com/file.js": true,
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
"file:///User/name/directory/",
|
|
14
|
+
)
|
|
15
|
+
const expected = {
|
|
16
|
+
whatever: {
|
|
17
|
+
"file:///User/name/directory/a.js": true,
|
|
18
|
+
"http://example.com/file.js": true,
|
|
19
|
+
},
|
|
20
|
+
}
|
|
21
|
+
assert({ actual, expected })
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// ensure resolveAssociations does not sort by length
|
|
25
|
+
{
|
|
26
|
+
const actual = URL_META.resolveAssociations(
|
|
27
|
+
{
|
|
28
|
+
whatever: {
|
|
29
|
+
"./a.js": 42,
|
|
30
|
+
"./long.js": 42,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
"file:///",
|
|
34
|
+
)
|
|
35
|
+
const expected = {
|
|
36
|
+
whatever: {
|
|
37
|
+
"file:///a.js": 42,
|
|
38
|
+
"file:///long.js": 42,
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
assert({ actual, expected })
|
|
42
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { assert } from "@jsenv/assert"
|
|
2
|
+
|
|
3
|
+
import { URL_META } from "@jsenv/urls"
|
|
4
|
+
|
|
5
|
+
const associations = URL_META.resolveAssociations(
|
|
6
|
+
{
|
|
7
|
+
whatever: {
|
|
8
|
+
"file://": false,
|
|
9
|
+
"http://": true,
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
"file:///User/name/directory/",
|
|
13
|
+
)
|
|
14
|
+
const fileUrlMeta = URL_META.applyAssociations({
|
|
15
|
+
url: "file:///dir/file.js",
|
|
16
|
+
associations,
|
|
17
|
+
})
|
|
18
|
+
const httpUrlMeta = URL_META.applyAssociations({
|
|
19
|
+
url: "http://example.com",
|
|
20
|
+
associations,
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const actual = {
|
|
24
|
+
fileUrlMeta,
|
|
25
|
+
httpUrlMeta,
|
|
26
|
+
}
|
|
27
|
+
const expected = {
|
|
28
|
+
fileUrlMeta: {
|
|
29
|
+
whatever: false,
|
|
30
|
+
},
|
|
31
|
+
httpUrlMeta: {
|
|
32
|
+
whatever: true,
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
assert({ actual, expected })
|