@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.
Files changed (63) hide show
  1. package/main.js +17 -0
  2. package/package.json +13 -5
  3. package/src/caller_position.js +1 -1
  4. package/src/common_pathname.js +42 -0
  5. package/src/ensure_url_trailing_slash.js +3 -0
  6. package/src/filesystem_path_to_url.js +10 -0
  7. package/src/inline_content_url_generator.js +1 -1
  8. package/src/is_filesystem_path.js +21 -0
  9. package/src/move_url.js +10 -0
  10. package/src/resolve_directory_url.js +7 -0
  11. package/src/resolve_url.js +6 -0
  12. package/src/url_is_inside_of.js +17 -0
  13. package/src/url_to_basename.js +9 -0
  14. package/src/url_to_extension.js +19 -0
  15. package/src/url_to_filename.js +14 -0
  16. package/src/url_to_filesystem_path.js +12 -0
  17. package/src/url_to_origin.js +7 -0
  18. package/src/url_to_parent_url.js +31 -0
  19. package/src/url_to_pathname.js +19 -0
  20. package/src/url_to_relative_url.js +56 -0
  21. package/src/url_to_ressource.js +21 -0
  22. package/src/url_to_scheme.js +10 -0
  23. package/src/url_trace.js +1 -1
  24. package/src/url_utils.js +3 -1
  25. package/docs/url_meta/advanced.md +0 -28
  26. package/docs/url_meta/demo/apply_associations.mjs +0 -27
  27. package/docs/url_meta/demo/full_match.mjs +0 -7
  28. package/docs/url_meta/demo/partial_match.mjs +0 -7
  29. package/docs/url_meta/demo/resolve_associations.mjs +0 -12
  30. package/docs/url_meta/notes.md +0 -26
  31. package/docs/url_meta/pattern_matching.md +0 -71
  32. package/docs/url_meta/readme.md +0 -87
  33. package/test/data_url.test.mjs +0 -57
  34. package/test/meta/aliasing.test.mjs +0 -47
  35. package/test/meta/as_flat_associations/basic.test.mjs +0 -64
  36. package/test/meta/assertions.test.mjs +0 -23
  37. package/test/meta/get_url_meta/any.test.mjs +0 -94
  38. package/test/meta/get_url_meta/basic.test.mjs +0 -226
  39. package/test/meta/get_url_meta/complex.test.mjs +0 -203
  40. package/test/meta/get_url_meta/double_wildcard_after.test.mjs +0 -68
  41. package/test/meta/get_url_meta/double_wildcard_around.test.mjs +0 -42
  42. package/test/meta/get_url_meta/double_wildcard_before.test.mjs +0 -55
  43. package/test/meta/get_url_meta/inheritance.test.mjs +0 -59
  44. package/test/meta/is_plain_object.test.mjs +0 -27
  45. package/test/meta/pattern_matching/basic.test.mjs +0 -100
  46. package/test/meta/pattern_matching/common.test.mjs +0 -145
  47. package/test/meta/pattern_matching/complex.test.mjs +0 -159
  48. package/test/meta/pattern_matching/contains.test.mjs +0 -46
  49. package/test/meta/pattern_matching/doublewildcard_after.test.mjs +0 -81
  50. package/test/meta/pattern_matching/doublewildcard_around.test.mjs +0 -42
  51. package/test/meta/pattern_matching/doublewildcard_before.test.mjs +0 -68
  52. package/test/meta/pattern_matching/doublewildcard_inside.test.mjs +0 -42
  53. package/test/meta/pattern_matching/trailing_slash.test.mjs +0 -55
  54. package/test/meta/pattern_matching/wildcard_after.test.mjs +0 -68
  55. package/test/meta/pattern_matching/wildcard_around.test.mjs +0 -94
  56. package/test/meta/pattern_matching/wildcard_before.test.mjs +0 -55
  57. package/test/meta/pattern_matching/wildcard_inside.test.mjs +0 -68
  58. package/test/meta/resolve_associations/basic.test.mjs +0 -42
  59. package/test/meta/resolve_associations/http_pattern.test.mjs +0 -35
  60. package/test/meta/url_child_may_match/inheritance.test.mjs +0 -71
  61. package/test/meta/url_child_may_match/url_child_may_match.test.mjs +0 -166
  62. package/test/url_trace.test.mjs +0 -224
  63. package/test.mjs +0 -13
@@ -1,159 +0,0 @@
1
- import { assert } from "@jsenv/assert"
2
-
3
- import { URL_META } from "@jsenv/urls"
4
-
5
- {
6
- const pattern = "file:///*.js"
7
- const url = "file:///file.js"
8
- const actual = URL_META.applyPatternMatching({ pattern, url })
9
- const expected = {
10
- matched: true,
11
- patternIndex: pattern.length,
12
- urlIndex: url.length,
13
- matchGroups: ["file"],
14
- }
15
- assert({ actual, expected })
16
- }
17
-
18
- {
19
- const pattern = "file:///*.js"
20
- const url = "file:///file.json"
21
- const actual = URL_META.applyPatternMatching({ pattern, url })
22
- const expected = {
23
- matched: false,
24
- patternIndex: pattern.length,
25
- urlIndex: url.indexOf("o"),
26
- matchGroups: ["file"],
27
- }
28
- assert({ actual, expected })
29
- }
30
-
31
- {
32
- const pattern = "file:///**/*.js"
33
- const url = "file:///folder/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: ["file"],
40
- }
41
- assert({ actual, expected })
42
- }
43
-
44
- {
45
- const pattern = "file:///**/*.js"
46
- const url = "file:///folder/file.json"
47
- const actual = URL_META.applyPatternMatching({ pattern, url })
48
- const expected = {
49
- matched: false,
50
- patternIndex: pattern.length,
51
- urlIndex: url.length,
52
- matchGroups: ["file"],
53
- }
54
- assert({ actual, expected })
55
- }
56
-
57
- {
58
- const pattern = "file:///a/b*/c"
59
- const url = "file:///a/bZ"
60
- const actual = URL_META.applyPatternMatching({ pattern, url })
61
- const expected = {
62
- matched: false,
63
- patternIndex: pattern.indexOf("c") - 1,
64
- urlIndex: url.indexOf("Z"),
65
- matchGroups: [""],
66
- }
67
- assert({ actual, expected })
68
- }
69
-
70
- {
71
- const pattern = "file:///**/*"
72
- const url = "file:///Users/directory/file.js"
73
- const actual = URL_META.applyPatternMatching({ pattern, url })
74
- const expected = {
75
- matched: true,
76
- patternIndex: pattern.length,
77
- urlIndex: url.length,
78
- matchGroups: ["file.js"],
79
- }
80
- assert({ actual, expected })
81
- }
82
-
83
- {
84
- const pattern = "file:///**/*.test.*"
85
- const url = "file:///folder/file.test.js"
86
- const actual = URL_META.applyPatternMatching({ pattern, url })
87
- const expected = {
88
- matched: true,
89
- patternIndex: pattern.length,
90
- urlIndex: url.length,
91
- matchGroups: ["file", "js"],
92
- }
93
- assert({ actual, expected })
94
- }
95
-
96
- {
97
- const pattern = "file:///**/*.js"
98
- const url = "file:///file.es5.js/file.es5.js.map"
99
- const actual = URL_META.applyPatternMatching({ pattern, url })
100
- const expected = {
101
- matched: false,
102
- patternIndex: pattern.length,
103
- urlIndex: url.length,
104
- matchGroups: ["file.es5"],
105
- }
106
- assert({ actual, expected })
107
- }
108
-
109
- {
110
- const pattern = "file:///src/**/*.js"
111
- const url = "file:///src/folder/file"
112
- const actual = URL_META.applyPatternMatching({ pattern, url })
113
- const expected = {
114
- matched: false,
115
- patternIndex: pattern.indexOf("."),
116
- urlIndex: url.length,
117
- matchGroups: [""],
118
- }
119
- assert({ actual, expected })
120
- }
121
-
122
- {
123
- const pattern = "file:///src/**/*.js"
124
- const url = "file:///src/folder/file.js"
125
- const actual = URL_META.applyPatternMatching({ pattern, url })
126
- const expected = {
127
- matched: true,
128
- patternIndex: pattern.length,
129
- urlIndex: url.length,
130
- matchGroups: ["file"],
131
- }
132
- assert({ actual, expected })
133
- }
134
-
135
- {
136
- const pattern = "file:///src/**/*.js"
137
- const url = "file:///src/folder/file.json"
138
- const actual = URL_META.applyPatternMatching({ pattern, url })
139
- const expected = {
140
- matched: false,
141
- patternIndex: pattern.length,
142
- urlIndex: url.length,
143
- matchGroups: ["file"],
144
- }
145
- assert({ actual, expected })
146
- }
147
-
148
- {
149
- const pattern = "file:///src/**/*.js"
150
- const url = "file:///src/folder"
151
- const actual = URL_META.applyPatternMatching({ pattern, url })
152
- const expected = {
153
- matched: false,
154
- patternIndex: pattern.indexOf("."),
155
- urlIndex: url.length,
156
- matchGroups: [""],
157
- }
158
- assert({ actual, expected })
159
- }
@@ -1,46 +0,0 @@
1
- import { assert } from "@jsenv/assert"
2
-
3
- import { URL_META } from "@jsenv/urls"
4
-
5
- const test = ({ pattern, url }) => {
6
- return URL_META.applyPatternMatching({
7
- pattern: new URL(pattern, "file:///").href,
8
- url: new URL(url, "file:///").href,
9
- }).matched
10
- }
11
-
12
- {
13
- const actual = test({
14
- pattern: "./dist/cdn/*photon.*.js",
15
- url: "./dist/cdn/photon.hash.js",
16
- })
17
- const expected = false
18
- assert({ actual, expected })
19
- }
20
-
21
- {
22
- const actual = test({
23
- pattern: "./dist/cdn/*photon.*.js",
24
- url: "./dist/cdn/photon_startscreen.hash.js",
25
- })
26
- const expected = false
27
- assert({ actual, expected })
28
- }
29
-
30
- {
31
- const actual = test({
32
- pattern: "file:///dist/cdn/**photon**.*.js",
33
- url: "./dist/cdn/photon.hash.js",
34
- })
35
- const expected = true
36
- assert({ actual, expected })
37
- }
38
-
39
- {
40
- const actual = test({
41
- pattern: "file:///dist/cdn/**photon**.*.js",
42
- url: "./dist/cdn/photon_startscreen.hash.js",
43
- })
44
- const expected = true
45
- assert({ actual, expected })
46
- }
@@ -1,81 +0,0 @@
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
- }
@@ -1,42 +0,0 @@
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
- }
@@ -1,68 +0,0 @@
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
- }
@@ -1,42 +0,0 @@
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
- }
@@ -1,55 +0,0 @@
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
- }
@@ -1,68 +0,0 @@
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
- }
@@ -1,94 +0,0 @@
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
- }