punycode-esm 1.0.6 → 1.0.8

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 (44) hide show
  1. package/.c8rc.json +46 -0
  2. package/.eslintcache/punycode-esm +1 -0
  3. package/CHANGELOG.md +10 -0
  4. package/LICENSE +1 -1
  5. package/README.md +9 -9
  6. package/coverage/base.css +224 -0
  7. package/coverage/block-navigation.js +87 -0
  8. package/coverage/favicon.png +0 -0
  9. package/coverage/index.html +131 -0
  10. package/coverage/prettify.css +1 -0
  11. package/coverage/prettify.js +2 -0
  12. package/coverage/sort-arrow-sprite.png +0 -0
  13. package/coverage/sorter.js +196 -0
  14. package/coverage/src/index.html +116 -0
  15. package/coverage/src/lib/errors.ts.html +181 -0
  16. package/coverage/src/lib/index.html +116 -0
  17. package/coverage/src/punycode.ts.html +1198 -0
  18. package/coverage/tmp/coverage-159909-1722832351784-0.json +1 -0
  19. package/coverage/tmp/coverage-159914-1722832351615-0.json +1 -0
  20. package/dist/lib/errors.d.ts +4 -3
  21. package/dist/lib/errors.d.ts.map +1 -0
  22. package/dist/lib/errors.js +4 -9
  23. package/dist/lib/errors.js.map +1 -0
  24. package/dist/punycode.d.ts +14 -13
  25. package/dist/punycode.d.ts.map +1 -0
  26. package/dist/punycode.js +46 -185
  27. package/dist/punycode.js.map +1 -0
  28. package/dist/tests/unit/lib/errors.spec.d.ts +2 -0
  29. package/dist/tests/unit/lib/errors.spec.d.ts.map +1 -0
  30. package/dist/tests/unit/lib/errors.spec.js +43 -0
  31. package/dist/tests/unit/lib/errors.spec.js.map +1 -0
  32. package/dist/tests/unit/punycode.spec.d.ts +2 -0
  33. package/dist/tests/unit/punycode.spec.d.ts.map +1 -0
  34. package/dist/tests/unit/punycode.spec.js +331 -0
  35. package/dist/tests/unit/punycode.spec.js.map +1 -0
  36. package/dist/tsconfig.tsbuildinfo +1 -0
  37. package/eslint.config.js +4 -0
  38. package/package.json +21 -21
  39. package/project.json +27 -0
  40. package/src/lib/errors.ts +32 -0
  41. package/src/punycode.ts +371 -0
  42. package/src/tests/unit/lib/errors.spec.ts +44 -0
  43. package/src/tests/unit/punycode.spec.ts +343 -0
  44. package/tsconfig.json +22 -0
@@ -0,0 +1,343 @@
1
+ import { expect } from 'chai';
2
+ import { suite, test } from 'mocha-chain';
3
+ import * as Punycode from 'punycode-esm';
4
+
5
+ const testData = {
6
+ strings: {
7
+ 'a single basic code point': {
8
+ decoded: 'Bach',
9
+ encoded: 'Bach-',
10
+ },
11
+ 'a single non-ASCII character': {
12
+ decoded: '\u00FC',
13
+ encoded: 'tda',
14
+ },
15
+ 'multiple non-ASCII characters': {
16
+ decoded: '\u00FC\u00EB\u00E4\u00F6\u2665',
17
+ encoded: '4can8av2009b',
18
+ },
19
+ 'mix of ASCII and non-ASCII characters': {
20
+ decoded: 'b\u00FCcher',
21
+ encoded: 'bcher-kva',
22
+ },
23
+ 'long string with both ASCII and non-ASCII characters': {
24
+ decoded:
25
+ 'Willst du die Bl\u00FCthe des fr\u00FChen, die Fr\u00FCchte des sp\u00E4teren Jahres',
26
+ encoded: 'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal',
27
+ },
28
+ // https://tools.ietf.org/html/rfc3492#section-7.1
29
+ 'Arabic (Egyptian)': {
30
+ decoded:
31
+ '\u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644\u0645\u0648\u0634\u0639\u0631\u0628\u064A\u061F',
32
+ encoded: 'egbpdaj6bu4bxfgehfvwxn',
33
+ },
34
+ 'Chinese (simplified)': {
35
+ decoded: '\u4ED6\u4EEC\u4E3A\u4EC0\u4E48\u4E0D\u8BF4\u4E2D\u6587',
36
+ encoded: 'ihqwcrb4cv8a8dqg056pqjye',
37
+ },
38
+ 'Chinese (traditional)': {
39
+ decoded: '\u4ED6\u5011\u7232\u4EC0\u9EBD\u4E0D\u8AAA\u4E2D\u6587',
40
+ encoded: 'ihqwctvzc91f659drss3x8bo0yb',
41
+ },
42
+ Czech: {
43
+ decoded: 'Pro\u010Dprost\u011Bnemluv\u00ED\u010Desky',
44
+ encoded: 'Proprostnemluvesky-uyb24dma41a',
45
+ },
46
+ Hebrew: {
47
+ decoded:
48
+ '\u05DC\u05DE\u05D4\u05D4\u05DD\u05E4\u05E9\u05D5\u05D8\u05DC\u05D0\u05DE\u05D3\u05D1\u05E8\u05D9\u05DD\u05E2\u05D1\u05E8\u05D9\u05EA',
49
+ encoded: '4dbcagdahymbxekheh6e0a7fei0b',
50
+ },
51
+ 'Hindi (Devanagari)': {
52
+ decoded:
53
+ '\u092F\u0939\u0932\u094B\u0917\u0939\u093F\u0928\u094D\u0926\u0940\u0915\u094D\u092F\u094B\u0902\u0928\u0939\u0940\u0902\u092C\u094B\u0932\u0938\u0915\u0924\u0947\u0939\u0948\u0902',
54
+ encoded: 'i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd',
55
+ },
56
+ 'Japanese (kanji and hiragana)': {
57
+ decoded:
58
+ '\u306A\u305C\u307F\u3093\u306A\u65E5\u672C\u8A9E\u3092\u8A71\u3057\u3066\u304F\u308C\u306A\u3044\u306E\u304B',
59
+ encoded: 'n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa',
60
+ },
61
+ 'Korean (Hangul syllables)': {
62
+ decoded:
63
+ '\uC138\uACC4\uC758\uBAA8\uB4E0\uC0AC\uB78C\uB4E4\uC774\uD55C\uAD6D\uC5B4\uB97C\uC774\uD574\uD55C\uB2E4\uBA74\uC5BC\uB9C8\uB098\uC88B\uC744\uAE4C',
64
+ encoded: '989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879ccm6fea98c',
65
+ },
66
+ /**
67
+ * As there's no way to do it in JavaScript, Punycode.js doesn't support
68
+ * mixed-case annotation (which is entirely optional as per the RFC).
69
+ * So, while the RFC sample string encodes to:
70
+ * `b1abfaaepdrnnbgefbaDotcwatmq2g4l`
71
+ * Without mixed-case annotation it has to encode to:
72
+ * `b1abfaaepdrnnbgefbadotcwatmq2g4l`
73
+ * https://github.com/bestiejs/punycode.js/issues/3
74
+ */
75
+ 'Russian (Cyrillic)': {
76
+ decoded:
77
+ '\u043F\u043E\u0447\u0435\u043C\u0443\u0436\u0435\u043E\u043D\u0438\u043D\u0435\u0433\u043E\u0432\u043E\u0440\u044F\u0442\u043F\u043E\u0440\u0443\u0441\u0441\u043A\u0438',
78
+ encoded: 'b1abfaaepdrnnbgefbadotcwatmq2g4l',
79
+ },
80
+ Spanish: {
81
+ decoded: 'Porqu\u00E9nopuedensimplementehablarenEspa\u00F1ol',
82
+ encoded: 'PorqunopuedensimplementehablarenEspaol-fmd56a',
83
+ },
84
+ Vietnamese: {
85
+ decoded: 'T\u1EA1isaoh\u1ECDkh\u00F4ngth\u1EC3ch\u1EC9n\u00F3iti\u1EBFngVi\u1EC7t',
86
+ encoded: 'TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g',
87
+ },
88
+ '3B-ww4c5e180e575a65lsy2b': {
89
+ decoded: '3\u5E74B\u7D44\u91D1\u516B\u5148\u751F',
90
+ encoded: '3B-ww4c5e180e575a65lsy2b',
91
+ },
92
+ '-with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n': {
93
+ decoded: '\u5B89\u5BA4\u5948\u7F8E\u6075-with-SUPER-MONKEYS',
94
+ encoded: '-with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n',
95
+ },
96
+ 'Hello-Another-Way--fc4qua05auwb3674vfr0b': {
97
+ decoded: 'Hello-Another-Way-\u305D\u308C\u305E\u308C\u306E\u5834\u6240',
98
+ encoded: 'Hello-Another-Way--fc4qua05auwb3674vfr0b',
99
+ },
100
+ '2-u9tlzr9756bt3uc0v': {
101
+ decoded: '\u3072\u3068\u3064\u5C4B\u6839\u306E\u4E0B2',
102
+ encoded: '2-u9tlzr9756bt3uc0v',
103
+ },
104
+ 'MajiKoi5-783gue6qz075azm5e': {
105
+ decoded: 'Maji\u3067Koi\u3059\u308B5\u79D2\u524D',
106
+ encoded: 'MajiKoi5-783gue6qz075azm5e',
107
+ },
108
+ 'de-jg4avhby1noc0d': {
109
+ decoded: '\u30D1\u30D5\u30A3\u30FCde\u30EB\u30F3\u30D0',
110
+ encoded: 'de-jg4avhby1noc0d',
111
+ },
112
+ d9juau41awczczp: {
113
+ decoded: '\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067',
114
+ encoded: 'd9juau41awczczp',
115
+ },
116
+ /**
117
+ * This example is an ASCII string that breaks the existing rules for host
118
+ * name labels. (It's not a realistic example for IDNA, because IDNA never
119
+ * encodes pure ASCII labels.)
120
+ */
121
+ 'ASCII string that breaks the existing rules for host-name labels': {
122
+ decoded: '-> $1.00 <-',
123
+ encoded: '-> $1.00 <--',
124
+ },
125
+ },
126
+ ucs2: {
127
+ // Every Unicode symbol is tested separately. These are just the extra
128
+ // tests for symbol combinations:
129
+ 'Consecutive astral symbols': {
130
+ decoded: [127_829, 119_808, 119_558, 119_638],
131
+ encoded: '\uD83C\uDF55\uD835\uDC00\uD834\uDF06\uD834\uDF56',
132
+ },
133
+ 'U+D800 (high surrogate) followed by non-surrogates': {
134
+ decoded: [55_296, 97, 98],
135
+ encoded: '\uD800ab',
136
+ },
137
+ 'U+DC00 (low surrogate) followed by non-surrogates': {
138
+ decoded: [56_320, 97, 98],
139
+ encoded: '\uDC00ab',
140
+ },
141
+ 'High surrogate followed by another high surrogate': {
142
+ decoded: [0xd800, 0xd800],
143
+ encoded: '\uD800\uD800',
144
+ },
145
+ 'Unmatched high surrogate, followed by a surrogate pair, followed by an unmatched high surrogate':
146
+ {
147
+ decoded: [0xd800, 0x1d306, 0xd800],
148
+ encoded: '\uD800\uD834\uDF06\uD800',
149
+ },
150
+ 'Low surrogate followed by another low surrogate': {
151
+ decoded: [0xdc00, 0xdc00],
152
+ encoded: '\uDC00\uDC00',
153
+ },
154
+ 'Unmatched low surrogate, followed by a surrogate pair, followed by an unmatched low surrogate':
155
+ {
156
+ decoded: [0xdc00, 0x1d306, 0xdc00],
157
+ encoded: '\uDC00\uD834\uDF06\uDC00',
158
+ },
159
+ },
160
+ domains: {
161
+ 'xn--maana-pta.com': {
162
+ decoded: 'ma\u00F1ana.com',
163
+ encoded: 'xn--maana-pta.com',
164
+ },
165
+ // https://github.com/bestiejs/punycode.js/issues/17
166
+ 'example.com.': {
167
+ decoded: 'example.com.',
168
+ encoded: 'example.com.',
169
+ },
170
+ 'xn--bcher-kva.com': {
171
+ decoded: 'b\u00FCcher.com',
172
+ encoded: 'xn--bcher-kva.com',
173
+ },
174
+ 'xn--caf-dma.com': {
175
+ decoded: 'caf\u00E9.com',
176
+ encoded: 'xn--caf-dma.com',
177
+ },
178
+ 'xn----dqo34k.com': {
179
+ decoded: '\u2603-\u2318.com',
180
+ encoded: 'xn----dqo34k.com',
181
+ },
182
+ 'xn----dqo34kn65z.com': {
183
+ decoded: '\uD400\u2603-\u2318.com',
184
+ encoded: 'xn----dqo34kn65z.com',
185
+ },
186
+ emoji: {
187
+ decoded: '\uD83D\uDCA9.la',
188
+ encoded: 'xn--ls8h.la',
189
+ },
190
+ 'Non-printable ASCII': {
191
+ decoded: '\0\u0001\u0002foo.bar',
192
+ encoded: '\0\u0001\u0002foo.bar',
193
+ },
194
+ 'Email address': {
195
+ decoded:
196
+ '\u0434\u0436\u0443\u043C\u043B\u0430@\u0434\u0436p\u0443\u043C\u043B\u0430\u0442\u0435\u0441\u0442.b\u0440\u0444a',
197
+ encoded: '\u0434\u0436\u0443\u043C\u043B\u0430@xn--p-8sbkgc5ag7bhce.xn--ba-lmcq',
198
+ },
199
+ },
200
+ separators: {
201
+ 'Using U+002E as separator': {
202
+ decoded: 'ma\u00F1ana\u002Ecom',
203
+ encoded: 'xn--maana-pta.com',
204
+ },
205
+ 'Using U+3002 as separator': {
206
+ decoded: 'ma\u00F1ana\u3002com',
207
+ encoded: 'xn--maana-pta.com',
208
+ },
209
+ 'Using U+FF0E as separator': {
210
+ decoded: 'ma\u00F1ana\uFF0Ecom',
211
+ encoded: 'xn--maana-pta.com',
212
+ },
213
+ 'Using U+FF61 as separator': {
214
+ decoded: 'ma\u00F1ana\uFF61com',
215
+ encoded: 'xn--maana-pta.com',
216
+ },
217
+ },
218
+ } as const;
219
+
220
+ suite('punycode', () => {
221
+ suite('ucs2Decode', () => {
222
+ for (const [description, { decoded, encoded }] of Object.entries(testData.ucs2)) {
223
+ suite(description, () => {
224
+ test('success', () => {
225
+ expect(Punycode.ucs2Decode(encoded)).to.deep.equal(decoded);
226
+ });
227
+
228
+ test('idempotent', () => {
229
+ expect(Punycode.ucs2Decode(String.fromCodePoint(...decoded))).to.deep.equal(
230
+ decoded
231
+ );
232
+ });
233
+ });
234
+ }
235
+ });
236
+
237
+ suite('ucs2Encode', () => {
238
+ for (const [description, { decoded, encoded }] of Object.entries(testData.ucs2)) {
239
+ suite(description, () => {
240
+ test('success', () => {
241
+ expect(Punycode.ucs2Encode(decoded)).to.equal(encoded);
242
+ });
243
+
244
+ test('idempotent', () => {
245
+ expect(
246
+ Punycode.ucs2Encode([...encoded].map(txt => txt.codePointAt(0)!))
247
+ ).to.equal(encoded);
248
+ });
249
+ });
250
+ }
251
+
252
+ test('Does not mutate argument array', () => {
253
+ const codePoints = [0x61, 0x62, 0x63];
254
+ expect(Punycode.ucs2Encode(codePoints)).to.equal('abc');
255
+ expect(codePoints).to.deep.equal([0x61, 0x62, 0x63]);
256
+ });
257
+ });
258
+
259
+ suite('decode', () => {
260
+ for (const [description, { decoded, encoded }] of Object.entries(testData.strings)) {
261
+ test(description, () => {
262
+ expect(Punycode.decode(encoded)).to.equal(decoded);
263
+ });
264
+ }
265
+
266
+ test('Handles uppercase Z', () => {
267
+ expect(Punycode.decode('ZZZ')).to.equal('\u7BA5');
268
+ });
269
+
270
+ test('Throws RangeError: Illegal input >= 0x80 (not a basic code point)', () => {
271
+ expect(() => Punycode.decode('\u0081-')).to.throw(RangeError);
272
+ });
273
+ test('Throws RangeError: Overflow: input needs wider integers to process', () => {
274
+ expect(() => Punycode.decode('\u0081')).to.throw(RangeError);
275
+ });
276
+ });
277
+
278
+ suite('encode', () => {
279
+ for (const [description, { decoded, encoded }] of Object.entries(testData.strings)) {
280
+ test(description, () => {
281
+ expect(Punycode.encode(decoded)).to.equal(encoded);
282
+ });
283
+ }
284
+ });
285
+
286
+ suite('toUnicode', () => {
287
+ for (const [description, { decoded, encoded }] of Object.entries(testData.domains)) {
288
+ suite(description, () => {
289
+ test('success', () => {
290
+ expect(Punycode.toUnicode(encoded)).to.equal(decoded);
291
+ });
292
+
293
+ test('idempotent', () => {
294
+ expect(Punycode.toUnicode(decoded)).to.equal(decoded);
295
+ });
296
+ });
297
+ }
298
+
299
+ suite("Does not convert names (or other strings) that don't start with `xn--`", () => {
300
+ for (const [description, { decoded, encoded }] of Object.entries(testData.strings)) {
301
+ suite(description, () => {
302
+ test('decoded', () => {
303
+ expect(Punycode.toUnicode(decoded)).to.equal(decoded);
304
+ });
305
+
306
+ test('encoded', () => {
307
+ expect(Punycode.toUnicode(encoded)).to.equal(encoded);
308
+ });
309
+ });
310
+ }
311
+ });
312
+ });
313
+
314
+ suite('toASCII', () => {
315
+ for (const [description, { decoded, encoded }] of Object.entries(testData.domains)) {
316
+ suite(description, () => {
317
+ test('success', () => {
318
+ expect(Punycode.toASCII(decoded)).to.equal(encoded);
319
+ });
320
+
321
+ test('idempotent', () => {
322
+ expect(Punycode.toASCII(encoded)).to.equal(encoded);
323
+ });
324
+ });
325
+ }
326
+
327
+ suite('Does not convert domain names (or other strings) that are already in ASCII', () => {
328
+ for (const [description, { encoded }] of Object.entries(testData.strings)) {
329
+ test(description, () => {
330
+ expect(Punycode.toASCII(encoded)).to.equal(encoded);
331
+ });
332
+ }
333
+ });
334
+
335
+ suite('Supports IDNA2003 separators for backwards compatibility', () => {
336
+ for (const [description, { decoded, encoded }] of Object.entries(testData.separators)) {
337
+ test(description, () => {
338
+ expect(Punycode.toASCII(decoded)).to.equal(encoded);
339
+ });
340
+ }
341
+ });
342
+ });
343
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "extends": "../../tsconfig.build.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "rootDir": "src",
6
+ "tsBuildInfoFile": "dist/tsconfig.tsbuildinfo"
7
+ },
8
+ "references": [
9
+ {
10
+ "path": "../../apps/nx-update-ts-references"
11
+ },
12
+ {
13
+ "path": "../../leyman/eslint-config"
14
+ },
15
+ {
16
+ "path": "../mocha-chain"
17
+ },
18
+ {
19
+ "path": "../nx-tsc"
20
+ }
21
+ ]
22
+ }