encoding-japanese is a JavaScript library designed for detecting and converting various character encodings, with a strong focus on Japanese encodings like Shift_JIS, EUC-JP, and ISO-2022-JP, alongside common Unicode formats like UTF-8 and UTF-16. Unlike standard JavaScript string handling, which is internally UTF-16, this library processes encodings as arrays of character code values, allowing for conversions between diverse character sets. The current stable version is 2.2.0, with releases occurring infrequently, often driven by feature additions or maintenance updates. Its key differentiator is robust support for a wide range of Japanese encodings and its ability to handle character codes as arrays, making it suitable for binary data manipulation (e.g., with `Uint8Array` or Node.js `Buffer`).
npm install encoding-japaneseVerified import paths — ran on the pinned version, not inferred.
Demonstrates converting Shift_JIS byte array to UTF-8 string, detecting encoding, and URL encoding, highlighting core library functionalities.
Review calls to `Encoding.convert` and explicitly define a `fallback` option (e.g., `fallback: 'html-entity'`, `fallback: 'ignore'`, or `fallback: 'error'`) to match desired behavior for unrepresentable characters.
Always convert JavaScript strings to character code arrays (e.g., `Encoding.stringToCode(myString)`) before passing them to `Encoding.convert` or `Encoding.detect` if you intend to specify a non-UTF-16 'from' encoding. Similarly, convert the resulting code arrays back to strings using `Encoding.codeToString`.
Be explicit about the `type` option in `Encoding.convert` (e.g., `type: 'Uint8Array'`) if you expect a TypedArray. Ensure consistency in data types when chaining operations or explicitly convert between plain arrays and TypedArrays as needed.
Ensure that if you need to serialize character code arrays, you convert them to a JSON-compatible format first, such as a regular array of numbers (`Array.from(uint8Array)`), or directly to a string via `Encoding.codeToString` before stringifying.
Verify the package is installed (`npm install encoding-japanese`) and ensure your import statement is `import * as Encoding from 'encoding-japanese';` for ESM or `const Encoding = require('encoding-japanese');` for CommonJS. Check your bundler or TypeScript configuration if paths are being resolved incorrectly.Use the `fallback` option in `Encoding.convert` (e.g., `fallback: 'html-entity'`, `fallback: 'ignore'`, or `fallback: 'error'`) to explicitly define how unrepresentable characters should be handled. If 'error' is used, wrap the conversion in a `try...catch` block to gracefully handle the error.
No dependency data recorded yet.