$ npm install legacy-encodingSupport as many legacy encodings as possible
npm install legacy-encoding
legacy.encode(input, encoding, options)This function takes a plain text string (the input parameter) and encodes it acording the encoding. The return value is a Buffer.
var legacy = require('legacy-encoding');
var buffer = legacy.encode(text, encoding);
The optional options object and its mode property can be used to set the error mode. For encoding, the error mode can be 'fatal' (the default) or 'html'.
var legacy = require('legacy-encoding');
var buffer = legacy.encode(text, encoding, {
'mode': 'html'
});
// If `text` contains a symbol that cannot be represented in the encoding,
// instead of throwing an error, it will return an HTML entity for the symbol.
legacy.decode(input, encoding, options)This function takes a Buffer (the input parameter) and decodes it according to encoding.
var legacy = require('legacy-encoding');
var text = legacy.decode(buffer, encoding);
The optional options object and its mode property can be used to set the error mode. For decoding, the error mode can be 'replacement' (the default) or 'fatal'.
var text = windows1255.decode(buffer, encoding, {
'mode': 'fatal'
});
// If `encodedData` contains an invalid byte for the encoding,
// instead of replacing it with U+FFFD in the output, an error is thrown.
MIT