ascii-chr
Version:
ASCII character codes table
36 lines (28 loc) • 652 B
JavaScript
const charCode = String.fromCharCode;
const makeCharCodes = (n = 257) => {
const chr = new Array(n);
// 1 byte
while (n > 0) {
chr[n -= 1] = charCode(n & 0xff);
}
return chr;
};
const makeCharCodes2 = (n = 2048) => {
const chr = new Array(n);
chr[n] = '\x00';
// 2 bytes
while (n > 0x80) {
chr[n -= 1] = charCode(
0xc0 | n >> 6 & 0x1f,
0x80 | n & 0x3f);
}
// 1 byte
while (n > 0) {
chr[n -= 1] = charCode(n);
}
return chr;
};
const charCodes = makeCharCodes();
const charCodes2 = makeCharCodes2();
const codePoint = String.fromCodePoint;
export { charCode, charCodes, charCodes2, codePoint };