macintosh

macintosh is a robust JavaScript implementation of the macintosh character encoding as defined by the Encoding Standard.
This encoding is known under the following names: csmacintosh, mac, macintosh, and x-mac-roman.
Installation
Via npm:
npm install macintosh
In a browser or in Node.js:
import {encode, decode, labels} from 'macintosh';
import * as macintosh from 'macintosh';
API
macintosh.labels
An array of strings, each representing a label for this encoding.
macintosh.encode(input, options)
This function takes a plain text string (the input parameter) and encodes it according to macintosh. The return value is a ‘byte string’, i.e. a string of which each item represents an octet as per macintosh.
const encodedData = macintosh.encode(text);
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'.
const encodedData = macintosh.encode(text, {
mode: 'html'
});
macintosh.decode(input, options)
This function takes a byte string (the input parameter) and decodes it according to macintosh.
const text = macintosh.decode(encodedData);
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'.
const text = macintosh.decode(encodedData, {
mode: 'fatal'
});
For decoding a buffer (e.g. from fs.readFile) use buffer.toString('binary') to get the byte string which decode takes.
Notes
Similar modules for other single-byte legacy encodings are available.
Author
License
macintosh is available under the MIT license.