bom
This produces BOM characters for the charset specified in the parameter.
Created by: hackvertor
Installed 1 times
Category: Charsets
Created on: Friday, November 1, 2024 at 11:36:46 AM
Updated on: Wednesday, November 6, 2024 at 2:17:27 PM
Tag arguments
[
{
"type": "string",
"help": "This provides the charset - Supported charsets are: UTF-8,UTF16BE,UTF16LE,UTF32BE,UTF32LE,UTF-7,SCSU,BOCU1,GB18030,UTF1,UTF-EBCDIC,UTF-7Modified",
"defaultValue": "UTF-8"
}
]
Code
class bom {
encode(input, charset) {
const boms = {
__proto__: null,
"UTF-8": String.fromCodePoint(0xef, 0xbb, 0xbf),
UTF16BE: String.fromCodePoint(0xfe, 0xff),
UTF16LE: String.fromCodePoint(0xff, 0xfe),
UTF32BE: String.fromCodePoint(0x00, 0x00, 0xfe, 0xff),
UTF32LE: String.fromCodePoint(0xff, 0xfe, 0x00, 0x00),
"UTF-7": String.fromCodePoint(0x2b, 0x2f, 0x76, 0x38, 0x2d),
SCSU: String.fromCodePoint(0x0e, 0xfe, 0xff),
BOCU1: String.fromCodePoint(0xfb, 0xee, 0x28),
GB18030: String.fromCodePoint(0x84, 0x31, 0x95, 0x33),
UTF1: String.fromCodePoint(0xf7, 0x64, 0x4c),
CESU8: String.fromCodePoint(0xef, 0xbb, 0xbf),
"UTF-EBCDIC": String.fromCodePoint(0xdd, 0x73, 0x66, 0x73),
"UTF-7MODIFIED": String.fromCodePoint(0x2b, 0x2f, 0x76, 0x38),
};
return boms[charset.toUpperCase()];
}
}