wcwidth-o1
Version:
Unicode text width calculation (wcwidth/wcswidth) for Node.js and TypeScript, optimized to O(1), based on Markus Kuhn's reference.
266 lines (265 loc) • 4.95 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.combiningMap = exports.combining = void 0;
/**
* Bitset accessor for combining/zero-width characters (Unicode 17.0.0).
*
* - Uses `combiningMap` for sparse bitset lookups.
* - Returns 0 if a block has no zero-width characters, or -1 for carve-outs.
*
* @param idx Codepoint block index (ucs >> 5)
* @returns 32-bit mask of zero-width characters for this block, or -1
*/
const combining = (idx) => 28672 <= idx && idx <= 28799 ? -1 : (exports.combiningMap[idx] ?? 0);
exports.combining = combining;
exports.combiningMap = {
24: -1,
25: -1,
26: -1,
27: 65535,
36: 1016,
44: -131072,
45: -1073741825,
46: 182,
48: 402587711,
50: -2048,
51: 65536,
54: -1077936128,
55: 15775,
56: 163840,
57: -65536,
58: 2047,
61: 131008,
63: 537917440,
64: -71303168,
65: 16111,
66: 234881024,
68: -8192000,
70: -1024,
71: -1,
72: 7,
73: 335544320,
74: 16654846,
75: 12,
76: 2,
77: 1342177280,
78: 8396830,
79: 1073741836,
80: 6,
81: 268435456,
82: 145798,
83: 2293760,
84: 6,
85: 268435456,
86: 8638,
87: -67108852,
88: 2,
89: -805306368,
90: 14688286,
91: 12,
92: 4,
93: 1073741824,
94: 8396801,
96: 17,
97: -805306368,
98: 6307265,
99: 12,
100: 2,
101: -1879048192,
102: 6307269,
103: 12,
104: 3,
105: 1476395008,
106: 8396830,
107: 12,
108: 2,
110: -2141420544,
113: 133300224,
114: 32640,
117: 535953408,
118: 32512,
120: 50331648,
121: 44040192,
123: 2147352576,
124: -16785185,
125: 536870911,
126: 64,
129: 1727913984,
130: -1023410176,
131: 1966081,
132: 536879204,
139: -1,
140: -1,
141: -1,
142: -1,
143: -1,
154: -536870912,
184: 3932160,
185: 1835008,
186: 786432,
187: 786432,
189: 1068498944,
190: 537919040,
192: 63488,
196: 96,
197: 512,
201: 235143559,
208: 159383552,
210: 2134900736,
211: -1611128859,
213: -65536,
214: 1073741823,
215: 4095,
216: 15,
217: 1072693248,
218: 28,
219: 1046528,
220: 3,
221: 16188,
223: 1024832,
225: 13627392,
230: -589824,
231: 51388925,
238: -1,
239: -1,
256: 63488,
257: 31744,
259: 65535,
262: -65536,
263: 131071,
359: 229376,
363: -2147483648,
367: -1,
385: 64512,
388: 100663296,
1331: 1073184768,
1332: -1073741824,
1335: 196608,
1344: 2116,
1345: 4192,
1350: 48,
1351: -2147221505,
1353: 16320,
1354: 786304,
1356: 7,
1357: 868745216,
1358: 1,
1359: 32,
1361: 6716928,
1362: 4104,
1363: 268435456,
1365: -1046675456,
1366: 2,
1367: 4206592,
1375: 8480,
1725: -65536,
1726: -1921,
1727: 268435455,
2008: 1073741824,
2032: 65535,
2033: 65535,
2039: -2147483648,
2044: -1073741824,
2047: 33488896,
2063: 536870912,
2071: 1,
2075: 130023424,
2128: 61550,
2129: -2030043136,
2135: 96,
2153: 240,
2155: 15872,
2165: 6144,
2167: -67108864,
2170: 131008,
2172: 60,
2176: 2,
2177: -16777216,
2178: 127,
2179: -2145845248,
2180: 3,
2181: 645398528,
2182: 8196,
2184: 7,
2185: 2092928,
2187: 524288,
2188: 3,
2189: 2143289344,
2190: 40449,
2193: 1089699840,
2194: 2,
2198: -2147483648,
2199: 2040,
2200: 3,
2201: 1476395008,
2202: 8396801,
2203: 2039744,
2205: -117440512,
2206: 377765,
2207: 6,
2209: -16777216,
2210: 1073741916,
2213: -1510408192,
2214: 13,
2221: -1338212352,
2222: 805306369,
2225: -1476919296,
2226: 1,
2229: 16721920,
2232: -1610612736,
2233: 4028,
2241: 117407744,
2249: 2013331456,
2250: 8,
2254: 217055232,
2255: 1,
2256: 2046,
2257: 2046296064,
2258: 243138688,
2260: 58719232,
2267: 93,
2273: -1082195968,
2276: -262144,
2277: 7208191,
2281: -1266810880,
2282: 191,
2284: 10682368,
2295: 1572864,
2296: 3,
2297: 130023424,
2298: 67108871,
2466: 4194177,
2824: -1073741824,
2825: 58367,
2903: 2031616,
2905: 8323072,
2938: 32768,
2940: 491520,
2943: 196624,
3556: 1610612736,
3557: 15,
3704: -1,
3705: -49153,
3706: 127,
3723: -7200,
3724: 4071,
3725: 15360,
3730: 28,
3792: -1,
3793: -125829121,
3794: -1,
3795: 2105343,
3796: -134217712,
3797: 65534,
3840: -100663425,
3841: 2011,
3844: 32768,
3849: 8323072,
3861: 16384,
3863: 61440,
3879: 61440,
3887: 49152,
3895: 2146376,
3910: 8323072,
3914: 2032
};