Node.js module to fix ISO-8859-1 (Latin-1) and Windows-1252 (CP1252) mojibake in UTF-8 strings
Decoding UTF-8 bytes as ISO-8859-1 (Latin-1) or Windows-1252 (CP1252) leaves ASCII intact but turns every non-ASCII character into mojibake, where ’ becomes ’.
The fix-latin1-to-utf8 module restores the original characters for both character encodings, including text garbled more than once.
Text resembling mojibake is left unchanged, so some Cyrillic and Chinese text may not be restored.
Install using npm:
npm i fix-latin1-to-utf8Please refer to the JSDoc comments in the source code or the generated type definitions for information on the available options.
"use strict";
const fixLatin1ToUtf8 = require("fix-latin1-to-utf8");
const mojibakeString = "The café’s sign was garbled.";
const fixedString = fixLatin1ToUtf8(mojibakeString);
console.log(fixedString);
// The café’s sign was garbled.Contributions are welcome, and any help is greatly appreciated!
See the contributing guide for details on how to get started. Please adhere to this project's Code of Conduct when contributing.
fix-latin1-to-utf8 is licensed under the MIT license.