identifier-js 0.0.13 → 0.0.15

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.
@@ -1,278 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import id from '../index.js';
3
-
4
- describe('isUri – IPv4 host validation', () => {
5
- test('Valid full IPv4 address', () => {
6
- expect(id.isUri('https://1.2.3.4')).to.equal(true);
7
- });
8
-
9
- test('Invalid IPv4 address, but valid as hostname', () => {
10
- expect(id.isUri('https://999.999.999.999')).to.equal(true);
11
- });
12
- });
13
-
14
- describe('isIri – IPv4 host validation', () => {
15
- test('Valid full IPv4 address', () => {
16
- expect(id.isIri('https://1.2.3.4')).to.equal(true);
17
- });
18
-
19
- test('Invalid IPv4 address, but valid as hostname', () => {
20
- expect(id.isIri('https://999.999.999.999')).to.equal(true);
21
- });
22
- });
23
-
24
- describe('isUri – IPv6 host validation', () => {
25
- test('Valid full (uncompressed) IPv6 address', () => {
26
- expect(id.isUri('https://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]')).to.equal(true);
27
- });
28
-
29
- test('Valid full IPv6 address (no zero compression)', () => {
30
- expect(id.isUri('https://[2001:db8:85a3:0:0:8a2e:370:7334]')).to.equal(true);
31
- });
32
-
33
- test('Valid IPv6 address with zero compression (::)', () => {
34
- expect(id.isUri('https://[2001:db8:85a3::8a2e:370:7334]')).to.equal(true);
35
- });
36
-
37
- test('Valid loopback IPv6 address (::1)', () => {
38
- expect(id.isUri('https://[::1]')).to.equal(true);
39
- });
40
-
41
- test('Valid unspecified IPv6 address (::)', () => {
42
- expect(id.isUri('https://[::]')).to.equal(true);
43
- });
44
-
45
- test('Valid compressed IPv6 address (trailing compression)', () => {
46
- expect(id.isUri('https://[2001:db8::]')).to.equal(true);
47
- });
48
-
49
- test('Valid IPv6 with embedded IPv4 (IPv4-mapped)', () => {
50
- expect(id.isUri('https://[::ffff:192.168.1.1]')).to.equal(true);
51
- });
52
-
53
- test('Valid IPv6 with embedded IPv4 (mixed notation)', () => {
54
- expect(id.isUri('https://[2001:db8::192.168.1.1]')).to.equal(true);
55
- });
56
-
57
- test('Valid link-local IPv6 address', () => {
58
- expect(id.isUri('https://[fe80::1]')).to.equal(true);
59
- });
60
-
61
- test('Valid maximum-length IPv6 address', () => {
62
- expect(id.isUri('https://[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]')).to.equal(true);
63
- });
64
-
65
- test('Invalid IPv6 – excessive colon sequence', () => {
66
- expect(() => id.isUri('https://[2001:db8:85a3:::8a2e:370:7334]')).to.throw(Error, 'Invalid URI: https://[2001:db8:85a3:::8a2e:370:7334]');
67
- });
68
-
69
- test('Invalid IPv6 – multiple zero compressions (::)', () => {
70
- expect(() => id.isUri('https://[2001:db8:85a3::8a2e::7334]')).to.throw(Error, 'Invalid URI: https://[2001:db8:85a3::8a2e::7334]');
71
- });
72
-
73
- test('Invalid IPv6 – segment exceeds 16-bit limit', () => {
74
- expect(() => id.isUri('https://[12345::]')).to.throw(Error, 'Invalid URI: https://[12345::]');
75
- });
76
-
77
- test('Invalid IPv6 – insufficient segments without compression', () => {
78
- expect(() => id.isUri('https://[2001:db8:85a3:8a2e:370:7334]')).to.throw(Error, 'Invalid URI: https://[2001:db8:85a3:8a2e:370:7334]');
79
- });
80
-
81
- test('Invalid IPv6 – too many segments', () => {
82
- expect(() => id.isUri('https://[2001:db8:85a3:0000:0000:8a2e:0370:7334:1234]')).to.throw(Error, 'Invalid URI: https://[2001:db8:85a3:0000:0000:8a2e:0370:7334:1234]');
83
- });
84
-
85
- test('Invalid IPv6 – embedded IPv4 out of range', () => {
86
- expect(() => id.isUri('https://[::ffff:999.168.1.1]')).to.throw(Error, 'Invalid URI: https://[::ffff:999.168.1.1]');
87
- });
88
-
89
- test('Invalid IPv6 – non-hexadecimal character in segment', () => {
90
- expect(() => id.isUri('https://[2001:db8::g1]')).to.throw(Error, 'Invalid URI: https://[2001:db8::g1]');
91
- });
92
-
93
- test('Invalid IPv6 – leading colon without compression', () => {
94
- expect(() => id.isUri('https://[:2001:db8::1]')).to.throw(Error, 'Invalid URI: https://[:2001:db8::1]');
95
- });
96
-
97
- test('Invalid IPv6 – trailing colon without compression', () => {
98
- expect(() => id.isUri('https://[2001:db8::1:]')).to.throw(Error, 'Invalid URI: https://[2001:db8::1:]');
99
- });
100
-
101
- test('Invalid IPv6 – empty address literal', () => {
102
- expect(() => id.isUri('https://[]')).to.throw(Error, 'Invalid URI: https://[]');
103
- });
104
-
105
- test('Invalid IPv6 – address literal with missing opening bracket', () => {
106
- expect(() => id.isUri('https://::1]')).to.throw(Error, 'Invalid URI: https://::1]');
107
- });
108
-
109
- test('Invalid IPv6 – address literal with missing closing bracket', () => {
110
- expect(() => id.isUri('https://[::1')).to.throw(Error, 'Invalid URI: https://[::1');
111
- });
112
- });
113
-
114
- describe('isIri – IPv6 host validation', () => {
115
- test('Valid full (uncompressed) IPv6 address', () => {
116
- expect(id.isIri('https://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]')).to.equal(true);
117
- });
118
-
119
- test('Valid full IPv6 address (no zero compression)', () => {
120
- expect(id.isIri('https://[2001:db8:85a3:0:0:8a2e:370:7334]')).to.equal(true);
121
- });
122
-
123
- test('Valid IPv6 address with zero compression (::)', () => {
124
- expect(id.isIri('https://[2001:db8:85a3::8a2e:370:7334]')).to.equal(true);
125
- });
126
-
127
- test('Valid loopback IPv6 address (::1)', () => {
128
- expect(id.isIri('https://[::1]')).to.equal(true);
129
- });
130
-
131
- test('Valid unspecified IPv6 address (::)', () => {
132
- expect(id.isIri('https://[::]')).to.equal(true);
133
- });
134
-
135
- test('Valid compressed IPv6 address (trailing compression)', () => {
136
- expect(id.isIri('https://[2001:db8::]')).to.equal(true);
137
- });
138
-
139
- test('Valid IPv6 with embedded IPv4 (IPv4-mapped)', () => {
140
- expect(id.isIri('https://[::ffff:192.168.1.1]')).to.equal(true);
141
- });
142
-
143
- test('Valid IPv6 with embedded IPv4 (mixed notation)', () => {
144
- expect(id.isIri('https://[2001:db8::192.168.1.1]')).to.equal(true);
145
- });
146
-
147
- test('Valid link-local IPv6 address', () => {
148
- expect(id.isIri('https://[fe80::1]')).to.equal(true);
149
- });
150
-
151
- test('Valid maximum-length IPv6 address', () => {
152
- expect(id.isIri('https://[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]')).to.equal(true);
153
- });
154
-
155
- test('Invalid IPv6 – excessive colon sequence', () => {
156
- expect(() => id.isIri('https://[2001:db8:85a3:::8a2e:370:7334]')).to.throw(Error, 'Invalid IRI: https://[2001:db8:85a3:::8a2e:370:7334]');
157
- });
158
-
159
- test('Invalid IPv6 – multiple zero compressions (::)', () => {
160
- expect(() => id.isIri('https://[2001:db8:85a3::8a2e::7334]')).to.throw(Error, 'Invalid IRI: https://[2001:db8:85a3::8a2e::7334]');
161
- });
162
-
163
- test('Invalid IPv6 – segment exceeds 16-bit limit', () => {
164
- expect(() => id.isIri('https://[12345::]')).to.throw(Error, 'Invalid IRI: https://[12345::]');
165
- });
166
-
167
- test('Invalid IPv6 – insufficient segments without compression', () => {
168
- expect(() => id.isIri('https://[2001:db8:85a3:8a2e:370:7334]')).to.throw(Error, 'Invalid IRI: https://[2001:db8:85a3:8a2e:370:7334]');
169
- });
170
-
171
- test('Invalid IPv6 – too many segments', () => {
172
- expect(() => id.isIri('https://[2001:db8:85a3:0000:0000:8a2e:0370:7334:1234]')).to.throw(Error, 'Invalid IRI: https://[2001:db8:85a3:0000:0000:8a2e:0370:7334:1234]');
173
- });
174
-
175
- test('Invalid IPv6 – embedded IPv4 out of range', () => {
176
- expect(() => id.isIri('https://[::ffff:999.168.1.1]')).to.throw(Error, 'Invalid IRI: https://[::ffff:999.168.1.1]');
177
- });
178
-
179
- test('Invalid IPv6 – non-hexadecimal character in segment', () => {
180
- expect(() => id.isIri('https://[2001:db8::g1]')).to.throw(Error, 'Invalid IRI: https://[2001:db8::g1]');
181
- });
182
-
183
- test('Invalid IPv6 – leading colon without compression', () => {
184
- expect(() => id.isIri('https://[:2001:db8::1]')).to.throw(Error, 'Invalid IRI: https://[:2001:db8::1]');
185
- });
186
-
187
- test('Invalid IPv6 – trailing colon without compression', () => {
188
- expect(() => id.isIri('https://[2001:db8::1:]')).to.throw(Error, 'Invalid IRI: https://[2001:db8::1:]');
189
- });
190
-
191
- test('Invalid IPv6 – empty address literal', () => {
192
- expect(() => id.isIri('https://[]')).to.throw(Error, 'Invalid IRI: https://[]');
193
- });
194
-
195
- test('Invalid IPv6 – address literal with missing opening bracket', () => {
196
- expect(() => id.isIri('https://::1]')).to.throw(Error, 'Invalid IRI: https://::1]');
197
- });
198
-
199
- test('Invalid IPv6 – address literal with missing closing bracket', () => {
200
- expect(() => id.isIri('https://[::1')).to.throw(Error, 'Invalid IRI: https://[::1');
201
- });
202
- });
203
-
204
- describe('isUri – port validation', () => {
205
- test('Valid port', () => {
206
- expect(id.isUri('https://example.com:80')).to.equal(true);
207
- });
208
-
209
- test('Valid port zero', () => {
210
- expect(id.isUri('https://example.com:0')).to.equal(true);
211
- });
212
-
213
- test('Valid port at max edge', () => {
214
- expect(id.isUri('https://example.com:65535')).to.equal(true);
215
- });
216
-
217
- test('Valid port empty', () => {
218
- expect(id.isUri('https://example.com:/')).to.equal(true);
219
- });
220
-
221
- test('Invalid "space" port', () => {
222
- expect(() => id.isUri('https://example.com: /')).to.throw(Error, 'Invalid URI: https://example.com: /');
223
- });
224
-
225
- test('Invalid "space" before port', () => {
226
- expect(() => id.isUri('https://example.com: 80/')).to.throw(Error, 'Invalid URI: https://example.com: 80/');
227
- });
228
-
229
- test('Invalid "space" after port', () => {
230
- expect(() => id.isUri('https://example.com:80 /')).to.throw(Error, 'Invalid URI: https://example.com:80 /');
231
- });
232
-
233
- test('Invalid port char', () => {
234
- expect(() => id.isUri('https://example.com:ff')).to.throw(Error, 'Invalid URI: https://example.com:ff');
235
- });
236
-
237
- test('Invalid port beyond edge', () => {
238
- expect(() => id.isUri('https://example.com:65536')).to.throw(Error, 'Invalid URI: https://example.com:65536');
239
- });
240
- });
241
-
242
- describe('isIri – port validation', () => {
243
- test('Valid port', () => {
244
- expect(id.isIri('https://example.com:80')).to.equal(true);
245
- });
246
-
247
- test('Valid port zero', () => {
248
- expect(id.isIri('https://example.com:0')).to.equal(true);
249
- });
250
-
251
- test('Valid port at max edge', () => {
252
- expect(id.isIri('https://example.com:65535')).to.equal(true);
253
- });
254
-
255
- test('Valid port empty', () => {
256
- expect(id.isIri('https://example.com:/')).to.equal(true);
257
- });
258
-
259
- test('Invalid "space" port', () => {
260
- expect(() => id.isIri('https://example.com: /')).to.throw(Error, 'Invalid IRI: https://example.com: /');
261
- });
262
-
263
- test('Invalid "space" before port', () => {
264
- expect(() => id.isIri('https://example.com: 80/')).to.throw(Error, 'Invalid IRI: https://example.com: 80/');
265
- });
266
-
267
- test('Invalid "space" after port', () => {
268
- expect(() => id.isIri('https://example.com:80 /')).to.throw(Error, 'Invalid IRI: https://example.com:80 /');
269
- });
270
-
271
- test('Invalid port char', () => {
272
- expect(() => id.isIri('https://example.com:ff')).to.throw(Error, 'Invalid IRI: https://example.com:ff');
273
- });
274
-
275
- test('Invalid port beyond edge', () => {
276
- expect(() => id.isIri('https://example.com:65536')).to.throw(Error, 'Invalid IRI: https://example.com:65536');
277
- });
278
- });