gumyen
Guess My Encoding. Small module that originated as a scratch to a personal itch around opening files which may be utf8/16, but which is now a more useful (though still small) utility for dealing with these encodings.
caveats
Currently this is optimised for the (rather specific) case of determining the encoding of XML and JSON files which may be any of UTF8/16-LE/16-BE. Gumyen works by reading the first 10 octets of a file and then (a) checking for a byte order mark, then if not found (b) checking for '{' encoded in utf16le or be as the first character of the file, and then (c) the string <?xml in each of the three encodings utf8, utf16le, utf16be. Additionally has utilities for stripping UTF BOM from buffers, strings and files, and writing strings and buffers to files with prepended BOMs.
usage
var gumyen = gumyenencodingfilename { // encoding is 'utf8', 'utf16le', 'utf16be'}; var encoding = ;// sync version of above gumyen; var data = gumyen;// sync version of above var clean = gumyen; gumyen; gumyen; // sync version of above var bufferWithBOM = gumyen;
dependencies
if you're wanting to work with utf16be, you'll need a module such as iconv-lite
install
npm install gumyen
test
npm test