Skip to content

Commit 6492e00

Browse files
committed
size: smaller single-byte map
1 parent de29ae8 commit 6492e00

File tree

4 files changed

+84
-68
lines changed

4 files changed

+84
-68
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Applications (including React Native apps) are advised to load either `@exodus/b
120120

121121
If you don't need support for legacy multi-byte encodings.
122122

123-
Reduces the bundle size 10x, while still keeping `utf-8`, `utf-16le`, `utf-16be` and all single-byte encodings specified by the spec.
123+
Reduces the bundle size 11x, while still keeping `utf-8`, `utf-16le`, `utf-16be` and all single-byte encodings specified by the spec.
124124
The only difference is support for legacy multi-byte encodings.
125125

126126
See [the list of encodings](https://encoding.spec.whatwg.org/#names-and-labels).

fallback/single-byte.encodings.js

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,47 @@
11
// See tests/encoding/fixtures/single-byte/dump.js for generator
22

33
const r = 0xff_fd
4-
const e = (x) => new Array(x).fill(1)
5-
const h = (x) => new Array(x).fill(r)
64

75
/* eslint-disable unicorn/numeric-separators-style, @exodus/export-default/named */
86

97
// Common ranges
108

119
// prettier-ignore
12-
const i2 = [-40,-147,1,64,-62,117,-51,-63,69,-67,79,-77,79,-77,1,64,2,51,4,-116,1,124,-122,1,129,22,-148,150,-148,1,133,-131,118,-116,1,33,-31,86,-51,-32,38,-36,48,-46,48,-46,1,33,2,51,4,-85,1,93,-91,1,98,22,-117,119,-117,1,102,374]
13-
const i4a = [-75, -63, e(5), 104, -34, -67, 79, -77, 75, -73, 1]
14-
const i4b = [34, -32, e(5), 73, -34, -36, 48, -46, 44, -42, 1]
15-
const i7 = [721, 1, 1, -719, 721, -719, 721, e(19), r, 2, e(43), r]
16-
const i8 = [e(26), r, r, 6692, 1, r]
17-
const i9 = [79, -77, e(11), 84, 46, -127, e(16), 48, -46, e(11), 53, 46]
18-
const iB = [3425, e(57), h(4), 5, e(28), h(4)]
19-
const p2 = [-99, 12, 20, -12, 17, 37, -29, 2]
20-
const p1 = [8237, -8235, 8089, -7816, 7820, 8, -6, 1]
21-
const w0 = [8237, -8235, 8089, -8087, 8091, 8, -6, 1, -8089, 8104]
22-
const w8 = [8072, 1, 3, 1, 5, -15, 1]
23-
const w1 = [w8, -7480, 7750, -8129, 7897, -7911, -182]
24-
const w3 = [w8, -8060, 8330, -8328, 8096, -8094]
25-
const m0 = [8558, -8328, 8374, -66, -8539, 16, 8043, -8070]
10+
const i2 = [189,148,0,0,63,0,116,64,0,68,0,78,0,78,0,0,63,64,114,117,0,0,123,0,0,128,149,0,149,0,0,132,0,117,0,0,32,0,85,33,0,37,0,47,0,47,0,0,32,33,83,86,0,0,92,0,0,97,118,0,118,0,0,101,474]
11+
const iB = [[58,3424],[4,r],[29,3424],[4,r]]
12+
const i9 = [[47],78,[12],83,128,[17],47,[12],52,97]
13+
const w1 = [8236, 0, 8088, 0, 8090, 8097, 8090, 8090, 0, 8103]
14+
const w2 = [8236, 0, 8088, 271, 8090, 8097, 8090, 8090, 574, 8103]
2615
// prettier-ignore
27-
const p3 = [1,1,65,-63,158,-156,1,1,1,40,30,42,-46,6,-66,1,83,-6,-6,-67,176,p2,-114,121,-119,1,1,155,-49,25,16,-142,159,2,-158,38,42,-46,6,-35,1,52,-6,-6,-36,145,p2,-83,90,-88,1,1,124,-49,25,16,-111,128,2]
16+
const w7 = [64,0,157,[4],39,68,109,62,67,0,0,82,75,68,0,175,75,86,105,92,108,144,114,115,0,120,[3],154,104,128,143,0,158,159,0,37,78,31,36,0,0,51,44,37,0,144,44,55,74,61,77,113,83,84,0,89,[3],123,73,97,112,0,127,128]
17+
const w8 = [8071, 8071, 8073, 8073, 8077, 8061, 8061]
2818
// prettier-ignore
29-
const k8a = [9345,2,10,4,4,4,4,8,8,8,8,68,4,4,4,4,1,1,1,-627,640,-903,1,46,28,1,-8645,8833,-8817,2,5,64,9305,1,1,-8449]
19+
const k8b = [-22,910,879,879,899,880,880,894,876,893,[8,879],894,[4,878],864,859,884,882,861,877,881,876,873,875,846,815,815,835,816,816,830,812,829,[8,815],830,[4,814],800,795,820,818,797,813,817,812,809,811]
3020
// prettier-ignore
31-
const k8b = [-30,1,21,-18,1,15,-17,18,-13,e(7),16,-15,1,1,1,-13,-4,26,-1,-20,17,5,-4,-2,3]
21+
const k8a = [9344,9345,9354,9357,9360,9363,9366,9373,9380,9387,9394,9461,9464,9467,9470,[4,9473],8845,9484,8580,8580,8625,8652,8652,6,8838,20,21,25,88,[3,9392],942]
3222

3323
// prettier-ignore
3424
const maps = {
35-
ibm866: [913,e(47),8530,1,1,-145,34,61,1,-12,-1,14,-18,6,6,-1,-1,-75,4,32,-8,-16,-28,60,34,1,-5,-6,21,-3,-6,-16,28,-5,1,-4,1,-12,-1,-6,1,24,-1,-82,-12,124,-4,8,4,-16,-8512,e(15),-78,80,-77,80,-77,80,-73,80,-942,8553,-8546,8547,-260,-8306,9468,-9472],
36-
'koi8-r': [k8a,8450,e(14),-8544,8545,e(10),-9411,933,k8b,-28,k8b],
37-
'koi8-u': [k8a,3,8448,-8446,1,8448,1,1,1,1,-8394,-51,8448,1,1,1,-8544,3,8543,-8541,1,8543,1,1,1,1,-8410,-130,-869,933,k8b,-28,k8b],
38-
'x-mac-cyrillic': [913,e(31),7153,-8048,992,-1005,4,8059,-8044,848,-856,-5,8313,-7456,80,7694,-7773,80,7627,-8557,8627,1,-7695,-929,988,-137,-4,80,-77,80,-78,80,-79,80,-2,-83,-857,m0,875,80,-79,80,-7,7102,1,8,1,-5,1,-7970,7975,-7184,80,-79,80,7351,-7445,80,-2,-31,e(30),7262],
39-
macintosh: [69,1,2,2,8,5,6,5,-1,2,2,-1,2,2,2,-1,2,1,2,-1,2,1,2,2,-1,2,2,-1,5,-1,2,1,7972,-8048,-14,1,4,8059,-8044,41,-49,-5,8313,-8302,-12,8632,-8602,18,8518,-8557,8627,1,-8640,16,8525,15,-2,-7759,7787,-8577,16,751,-707,18,-57,-30,11,m0,32,3,18,125,1,7872,1,8,1,-5,1,-7970,9427,-9419,121,7884,104,-115,1,56007,1,-56033,-8042,8035,4,18,-8046,8,-9,10,-3,5,1,1,-3,7,1,63531,-63533,8,1,-2,88,405,22,-557,553,1,1,-546,549,-2,-20],
40-
'windows-874': [8237,-8235,1,1,1,8098,-8096,e(10),w8,-8060,e(8),iB],
25+
ibm866: [[48,912],[3,9441],9295,9328,9388,9388,9375,9373,9386,9367,9372,9377,9375,9373,9297,9300,9331,9322,9305,9276,9335,9368,9368,9362,9355,9375,9371,9364,9347,9374,9368,9368,9363,9363,9350,9348,9341,9341,9364,9362,9279,9266,9389,9384,9391,9394,9377,[16,864],785,864,786,865,787,866,792,871,-72,8480,-67,8479,8218,-89,9378,-95],
26+
'koi8-u': [...k8a,944,9391,944,944,[5,9391],996,944,[4,9391],846,848,9390,848,848,[5,9390],979,848,...k8b],
27+
'koi8-r': [...k8a,[15,9391],846,[11,9390],...k8b],
28+
macintosh: [68,68,69,70,77,81,86,90,88,89,90,88,89,90,91,89,90,90,91,89,90,90,91,92,90,91,92,90,94,92,93,93,8064,15,0,0,3,8061,16,56,6,0,8312,9,-4,8627,24,41,8558,0,8626,8626,-15,0,8524,8538,8535,775,8561,-17,-2,748,40,57,-1,-32,-22,8535,206,8579,8512,-28,-13,8029,-42,-11,-9,8,132,132,8003,8003,8010,8010,8004,8004,33,9459,39,159,8042,8145,8029,8029,64035,64035,8001,-42,7992,7995,8012,-35,-28,-38,-29,-33,[3,-29],-33,-27,-27,63503,-31,-24,-24,-27,60,464,485,-73,[3,479],-68,480,477,456],
29+
'x-mac-cyrillic': [[32,912],8064,15,1006,0,3,8061,16,863,6,0,8312,855,934,8627,853,932,8558,0,8626,8626,930,0,987,849,844,923,845,924,845,924,844,923,920,836,-22,8535,206,8579,8512,-28,-13,8029,-42,832,911,831,910,902,8003,8003,8010,8010,8004,8004,33,8007,822,901,821,900,8250,804,883,880,[31,848],8109],
30+
'windows-874': [8236,[4],8097,[11],...w8,[9],...iB],
4131
}
4232

4333
// windows-1250 - windows-1258
4434
// prettier-ignore
4535
;[
46-
[w0,-7888,7897,-7903,10,25,-4,-233,w8,-8060,8330,-8129,7897,-7903,10,25,-4,-218,551,17,-407,-157,96,-94,1,1,1,181,-179,1,1,1,205,-203,1,554,-409,-142,1,1,1,1,77,90,-164,130,416,-415,62,i2],
47-
[899,1,7191,-7111,7115,8,-6,1,139,-124,-7207,7216,-7215,2,-1,4,67,7110,1,3,1,5,-15,1,-8060,8330,-7369,7137,-7136,2,-1,4,-959,878,80,-86,-868,1004,-1002,1,858,-856,859,-857,1,1,1,857,-855,1,853,80,59,-988,1,1,922,7365,-7362,-921,925,-83,80,2,-71,e(63)],
48-
[p1,-7515,7530,-7888,7897,-7911,-197,240,-238,1,w1,225,-6],
49-
[p1,-8089,8104,-8102,8111,-8109,1,1,1,1,w3,1,1,1,1,741,1,-739,e(6),r,2,1,1,1,8039,-8037,1,1,1,721,-719,1,1,i7],
50-
[p1,-7515,7530,-7888,7897,-7911,-197,1,1,1,w1,1,218,-216,e(47),i9],
51-
[p1,-7515,7530,-8102,8111,-8109,1,1,1,1,w8,-7480,7750,-8328,8096,-8094,e(7),8199,-8197,1,1,1,1,46,-44,e(14),62,-60,1,1,1,1,1265,e(19),45,1,1,1,1,h(7),-36,i8],
52-
[8237,-6702,6556,-7816,7820,8,-6,1,-7515,7530,-6583,6592,-7911,1332,18,-16,39,6505,1,3,1,5,-15,1,-6507,6777,-6801,6569,-7911,7865,1,-6483,-1562,1388,-1386,e(7),1557,-1555,e(14),1378,-1376,1,1,1,1377,162,-160,e(21),-1375,1376,1,1,1,6,1,1,1,-1379,1380,-1378,1379,1,1,1,-1377,1,1,1,1,1374,1,-1372,1,1372,1,1,1,-1370,1371,1,-1369,1370,-1368,1369,-1367,1,7954,1,-6461],
53-
[w0,-8102,8111,-8109,28,543,-527,-40,w3,19,556,-572,1,r,2,1,1,r,2,1,49,-47,173,-171,1,1,1,24,-22,e(5),p3,347],
54-
[p1,-7515,7530,-8102,8111,-7911,-197,1,1,1,w8,-7480,7750,-8328,8096,-7911,-182,1,218,-216,e(34),64,-62,e(7),565,-563,1,1,65,-63,568,-566,1,204,-202,e(6),211,340,-548,1,1,1,33,-31,e(7),534,-532,1,1,34,-32,562,-560,1,173,-171,e(6),180,7931],
36+
[...w1,214,8110,206,215,239,234,0,...w8,0,8329,199,8095,191,200,224,219,0,550,566,158,0,95,[4],180,[4],204,0,0,553,143,[5],76,165,0,129,544,128,...i2],
37+
[898,898,8088,976,8090,8097,8090,8090,8228,8103,895,8110,894,895,893,896,962,...w8,0,8329,959,8095,958,959,957,960,0,877,956,869,0,1003,0,0,857,0,858,[4],856,0,0,852,931,989,[3],921,8285,922,0,924,840,919,920,[64,848]],
38+
[...w2,214,8110,198,0,239,0,0,...w8,580,8329,199,8095,183,0,224,217],
39+
[8236,0,8088,271,8090,8097,8090,8090,0,8103,0,8110,[5],...w8,0,8329,0,8095,[5],740,740,[7],r,[4],8038,[4],720,[3],[3,720],0,720,0,[20,720],r,[44,720],r],
40+
[...w2,214,8110,198,[4],...w8,580,8329,199,8095,183,0,0,217,0,...i9],
41+
[...w2,0,8110,[5],...w8,580,8329,0,8095,[8],8198,[5],45,[15],61,[5],[20,1264],[5,1308],[7,r],[27,1264],r,r,7953,7953,r],
42+
[8236,1533,8088,271,8090,8097,8090,8090,574,8103,1519,8110,198,1529,1546,1529,1567,...w8,1553,8329,1527,8095,183,8047,8047,1563,0,1387,[8],1556,[15],1377,[4],1376,1537,[22,1376],0,[4,1375],[4,1380],0,1379,0,[4,1378],[5],1373,1373,0,0,[4,1371],0,1370,1370,0,1369,0,1368,0,0,7953,7953,1491],
43+
[...w1,0,8110,0,27,569,41,0,...w8,0,8329,0,8095,0,18,573,0,0,r,[3],r,0,0,48,0,172,[4],23,[8],...w7,474],
44+
[...w2,0,8110,198,[4],...w8,580,8329,0,8095,183,0,0,217,[35],63,[8],564,[3],64,0,567,0,0,203,[7],210,549,[4],32,[8],533,[3],33,0,561,0,0,172,[7],179,8109],
5545
].forEach((m, i) => {
5646
maps[`windows-${i + 1250}`] = m
5747
});
@@ -60,23 +50,23 @@ const maps = {
6050
// prettier-ignore
6151
;[
6252
[], // Actual Latin1 / Unicode subset, non-WHATWG, which maps iso-8859-1 to windows-1252
63-
[100,468,-407,-157,153,29,-179,1,184,-2,6,21,-204,208,-2,-203,85,470,-409,-142,138,29,364,-527,169,-2,6,21,355,-351,-2,i2],
64-
[134,434,-565,1,r,128,-125,1,136,46,-64,22,-135,r,206,-203,119,-117,1,1,1,112,-110,1,121,46,-64,22,-120,r,191,-188,1,1,r,2,70,-2,-65,e(8),r,2,1,1,1,76,-74,1,69,-67,1,1,1,144,-16,-125,1,1,1,r,2,39,-2,-34,e(8),r,2,1,1,1,45,-43,1,38,-36,1,1,1,113,-16,380],
65-
[100,52,30,-178,132,19,-148,1,184,-78,16,68,-185,208,-206,1,85,470,-388,-163,117,19,395,-527,169,-78,16,68,-29,52,-51,i4a,92,-26,53,7,-22,-98,1,1,1,1,154,-152,1,1,140,2,-139,i4b,61,-26,53,7,-22,-67,1,1,1,1,123,-121,1,1,109,2,366],
66-
[865,e(11),-863,865,e(65),7367,-7365,e(11),-949,951,1],
67-
[r,r,r,4,h(7),1384,-1375,h(13),1390,r,r,r,4,r,2,e(25),h(5),6,e(18),h(13)],
68-
[8056,1,-8054,8201,3,-8201,1,1,1,721,-719,1,1,r,8040,-8037,1,1,1,721,1,1,-719,i7],
69-
[r,2,e(7),46,-44,e(14),62,-60,1,1,1,h(32),8025,-6727,i8],
70-
[e(47),i9], // non-WHATWG, which maps iso-8859-9 to windows-1254
71-
[100,14,16,8,-2,14,-143,148,-43,80,6,23,-208,189,-32,-154,85,14,16,8,-2,14,-128,133,-43,80,6,23,7831,-7850,-32,i4a,1,1,117,7,-121,1,1,1,146,-144,154,-152,e(5),i4b,1,1,86,7,-90,1,1,1,115,-113,123,-121,1,1,1,1,58],
53+
[99,566,158,0,152,180,0,0,183,180,185,205,0,207,204,0,84,553,143,0,137,165,528,0,168,165,170,190,544,192,...i2],
54+
[133,566,0,0,r,126,0,0,135,180,115,136,0,r,204,0,118,[4],111,0,0,120,165,100,121,0,r,189,[3],r,0,69,66,[9],r,[4],75,0,0,68,[4],143,126,[4],r,0,38,35,[9],r,[4],44,0,0,37,[4],112,95,474],
55+
[99,150,179,0,131,149,0,0,183,104,119,186,0,207,0,0,84,553,164,0,116,134,528,0,168,89,104,171,141,192,140,64,[6],103,68,0,78,0,74,0,0,91,64,116,122,99,[5],153,[3],139,140,0,33,[6],72,37,0,47,0,43,0,0,60,33,85,91,68,[5],122,[3],108,109,474],
56+
[[12,864],0,[66,864],8230,[12,864],-86,864,864],
57+
[[3,r],0,[7,r],1376,0,[13,r],1376,[3,r],1376,r,[26,1376],[5,r],[19,1376],[13,r]],
58+
[8055,8055,0,8200,8202,[4],720,[3],r,8038,[4],[3,720],0,[3,720],0,720,0,[20,720],r,[44,720],r],
59+
[r,[8],45,[15],61,[4],[32,r],7992,[27,1264],r,r,7953,7953,r],
60+
i9, // non-WHATWG, which maps iso-8859-9 to windows-1254
61+
[99,112,127,134,131,144,0,147,103,182,187,209,0,188,155,0,84,97,112,119,116,129,0,132,88,167,172,194,8024,173,140,64,[6],103,68,0,78,0,74,[4],116,122,[4],145,0,153,[6],33,[6],72,37,0,47,0,43,[4],85,91,[4],114,0,122,[5],57],
7262
iB, // non-WHATWG, which maps iso-8859-11 to windows-874
7363
null, // no 12
74-
[8061,-8059,1,1,8058,-8056,1,49,-47,173,-171,1,1,1,24,-22,1,1,1,8041,-8039,p3,7835],
75-
[7522,1,-7520,103,1,7423,-7523,7641,-7639,7641,-119,231,-7749,1,202,7334,1,-7423,1,7455,1,-7563,7584,43,-42,44,-35,147,-111,1,-36,-7585,e(15),165,-163,e(5),7572,-7570,e(5),153,-151,e(16),134,-132,e(5),7541,-7539,e(5),122],
76-
[1,1,1,8201,-8199,187,-185,186,-184,e(10),202,-200,1,1,199,-197,1,1,151,1,37],
77-
[100,1,60,8043,-142,-7870,-185,186,-184,367,-365,206,-204,205,1,-203,1,91,54,59,7840,-8039,1,199,-113,268,-350,151,1,37,4,-188,1,1,64,-62,66,-64,e(9),65,51,-113,1,1,124,-122,132,22,-151,1,1,1,60,258,-315,1,1,1,33,-31,35,-33,e(9),34,51,-82,1,1,93,-91,101,22,-120,1,1,1,29,258],
64+
[8060,[3],8057,0,0,48,0,172,[4],23,[4],8040,[3],...w7,7962],
65+
[7521,7521,0,102,102,7524,0,7640,0,7640,7520,7750,0,0,201,7534,7534,110,110,7564,7564,0,7583,7625,7582,7625,7589,7735,7623,7623,7586,[16],164,[6],7571,[6],152,[17],133,[6],7540,[6],121],
66+
[[3],8200,0,186,0,185,[11],201,[3],198,[3],150,150,186],
67+
[99,99,158,8200,8057,186,0,185,0,366,0,205,0,204,204,0,0,90,143,201,8040,0,0,198,84,351,0,150,150,186,189,[3],63,0,65,[10],64,114,[3],123,0,131,152,[4],59,316,[4],32,0,34,[10],33,83,[3],92,0,100,121,[4],28,285],
7868
].forEach((m, i) => {
79-
if (m) maps[`iso-8859-${i + 1}`] = [e(33), m]
80-
})
69+
if (m) maps[`iso-8859-${i + 1}`] = [[33], ...m]
70+
});
8171

8272
export default maps

fallback/single-byte.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export function getEncoding(encoding) {
1717
assertEncoding(encoding)
1818
if (encoding === xUserDefined) return Array.from({ length: 128 }, (_, i) => 0xf7_80 + i)
1919
if (encoding === iso8i) encoding = 'iso-8859-8'
20-
let prev = 127
21-
const enc = encodings[encoding].flat().flat().flat() // max depth is 3, rechecked by tests
22-
return enc.map((x) => (x === r ? x : (prev += x))) // eslint-disable-line no-return-assign
20+
const enc = encodings[encoding]
21+
const deltas = enc.flatMap((x) => (Array.isArray(x) ? new Array(x[0]).fill(x[1] ?? 0) : x))
22+
return deltas.map((x, i) => (x === r ? x : x + 128 + i))
2323
}
2424

2525
const mappers = new Map()

tests/encoding/fixtures/single-byte/dump.js

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,54 @@ for (const file of readdirSync(import.meta.dirname)) {
3535
}
3636

3737
while (chars[chars.length - 1] === 128 + chars.length - 1) chars.pop() // minify
38-
let last = 127
39-
const deltas = chars.map((x) => {
38+
encodings[encoding] = chars
39+
}
40+
41+
// Some encodings from Unicode
42+
/*
43+
{
44+
const r = 0xff_fd
45+
const z = (x) => new Array(x).fill(0)
46+
encodings['iso-8859-1'] = []
47+
encodings['iso-8859-9'] = [z(80),78,z(12),83,128,z(17),47,z(12),52,97].flat().map((x, i) => x === r ? r : x + i + 128)
48+
encodings['iso-8859-11'] = [z(33),3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,r,r,r,r,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,3424,r,r,r,r].flat().map((x, i) => x === r ? r : x + i + 128)
49+
}
50+
*/
51+
52+
for (const [encoding, chars] of Object.entries(encodings)) {
53+
const deltas = chars.map((x, i) => {
4054
if (x === 0xff_fd) return x
41-
x -= last
42-
last += x
43-
return x
55+
return x - 128 - i
4456
})
45-
encodings[encoding] = `[${deltas.join(',')}]`
57+
for (let i = 0; i < deltas.length; i++) {
58+
let j = i
59+
while (j < deltas.length && deltas[j] === deltas[i]) j++
60+
if (j - i > 2) {
61+
deltas.splice(i, j - i, deltas[i] === 0 ? [j - i] : [j - i, deltas[i]])
62+
}
63+
}
64+
65+
encodings[encoding] = JSON.stringify(deltas)
66+
}
67+
68+
const sorter = ([a], [b]) => {
69+
while (a[0] === b[0]) {
70+
a = a.slice(1)
71+
b = b.slice(1)
72+
}
73+
74+
if (a && b && `${Number(a)}` === a && `${Number(b)}` === b) return Number(a) < Number(b) ? -1 : 1
75+
return a < b ? -1 : 1
4676
}
4777

48-
const table = JSON.stringify(encodings, undefined, 2)
78+
const table = JSON.stringify(
79+
Object.fromEntries(Object.entries(encodings).sort(sorter)),
80+
undefined,
81+
2
82+
)
4983
.replaceAll(']"', ']')
5084
.replaceAll('"[', '[')
5185
.replaceAll('"', "'")
5286
.replaceAll(/(\D)65533/g, '$1r')
53-
.replaceAll(
54-
/([^\dr])(1(?:,1){4,})([^\dr])/g,
55-
(_, a, b, c) => `${a}...e(${(b.length + 1) / 2})${c}`
56-
)
57-
.replaceAll(
58-
/([^\dr])(r(?:,r){4,})([^\dr])/g,
59-
(_, a, b, c) => `${a}...h(${(b.length + 1) / 2})${c}`
60-
)
6187

6288
console.log(table)

0 commit comments

Comments
 (0)