Created
August 21, 2022 03:07
-
-
Save zazaulola/1ac89647b2326724153e5efb4a62d8dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cp1251ToUtf8(buf){ | |
if(buf instanceof ArrayBuffer) buf = new Uint8Array(buf); | |
if(!Array.isArray(buf)) buf = [...buf]; | |
const map = new Map([ | |
[128,1026], [129,1027], [130,8218], [131,1107], | |
[132,8222], [133,8230], [134,8224], [135,8225], | |
[136,8364], [137,8240], [138,1033], [139,8249], | |
[140,1034], [141,1036], [142,1035], [143,1039], | |
[144,1106], [145,8216], [146,8217], [147,8220], | |
[148,8221], [149,8226], [150,8211], [151,8212], | |
[152,null], [153,8482], [154,1113], [155,8250], | |
[156,1114], [157,1116], [158,1115], [159,1119], | |
[160, 160], [161,1038], [162,1118], [163,1032], | |
[164, 164], [165,1168], [166, 166], [167, 167], | |
[168,1025], [169, 169], [170,1028], [171, 171], | |
[172, 172], [173, 173], [174, 174], [175,1031], | |
[176, 176], [177, 177], [178,1030], [179,1110], | |
[180,1169], [181, 181], [182, 182], [183, 183], | |
[184,1105], [185,8470], [186,1108], [187, 187], | |
[188,1112], [189,1029], [190,1109], [191,1111] | |
]); | |
return buf.map(c=>c<127?c:c>191?c+848:map.get(c)||0) | |
.map(c=>String.fromCharCode(c)).join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment