Fdawgs/fix-latin1-to-utf8

Node.js module to fix ISO-8859-1 (Latin-1) and Windows-1252 (CP1252) mojibake in UTF-8 strings

★ 5Forks 0JavaScriptGitHub ↗Compare

Project website ↗

cp-1252cp1252encodingiso-8859-1iso8859-1latin-1latin1mojibakenodejsutf8windows-1252windows1252

README

fix-latin1-to-utf8

GitHub release npm version CI Coverage status code style: Prettier OSSF Scorecard

Node.js module to fix ISO-8859-1 (Latin-1) and Windows-1252 (CP1252) mojibake in UTF-8 strings

Overview

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.

Installation

Install using npm:

npm i fix-latin1-to-utf8

Example usage

Please 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.

Contributing

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.

License

fix-latin1-to-utf8 is licensed under the MIT license.

Contributors

Fdawgsdependabot[bot]github-actions[bot]

Issues