@cjser/unicode-escapes
v1.0.0-cjser.2
Published
Encode and decode Unicode escapes in a string
Maintainers
Readme
unicode-escapes
Encode and decode Unicode escapes in a string
Can be useful when a tool or service returns text with encoded Unicode characters.
Install
npm install unicode-escapesUsage
import {encodeUnicodeEscapes, decodeUnicodeEscapes} from 'unicode-escapes';
console.log(encodeUnicodeEscapes('Hello, โลก'));
//=> 'Hello, \u{e42}\u{e25}\u{e01}'
console.log(decodeUnicodeEscapes('Hello, \\u{e42}\\u{e25}\\u{e01}'));
//=> 'Hello, โลก'API
encodeUnicodeEscapes(string)
Encode Unicode characters in a string to Unicode escapes.
decodeUnicodeEscapes(string)
Decode Unicode escapes in a string to Unicode characters.
Use-cases
- Debugging and logging: Encoding and decoding Unicode escapes can be valuable in debugging scenarios, where you might need to inspect strings with non-visible or special characters. It can assist in displaying logs, traces, or debug outputs that are human-readable.
- Data serialization and deserialization: Ensuring consistent representation of Unicode characters when saving and reading data, particularly in formats that may have special handling for certain escape sequences.
- Source code analysis and manipulation: For tooling that analyzes or manipulates source code, such as linters or code transformation tools, where representing characters in escape sequences might be necessary.
- Interoperability with legacy systems: When interacting with systems that expect a particular escape syntax for Unicode characters.
cjser
This package is a CommonJS-compatible build generated by cjser for projects that still need require() support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
Original repository: https://github.com/sindresorhus/unicode-escapes
