iconv-lite is a pure JavaScript library for converting character encodings without relying on native Node.js bindings or external dependencies for core functionality. It provides a robust solution for handling various text encodings, making it suitable for applications that need to process files, network streams, or user input in different character sets. The current stable version is `0.7.2`, with `v1.0.0-alpha.1` being an actively developed upcoming major release introducing significant breaking changes. While there isn't a strict release cadence, the project sees regular maintenance and improvements, including recent type definition enhancements and bug fixes. Its key differentiator is its pure JavaScript implementation, which avoids installation complexities associated with native modules like `node-iconv`.
npm install iconv-liteVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to encode a JavaScript string into a Buffer using different character sets (UTF-8, Windows-1251) and then decode those Buffers back into strings. It also shows how to check for supported encodings.
Upgrade your Node.js runtime to version 18 or higher, or pin `iconv-lite` to a `0.x` version using `npm install iconv-lite@0.x`.
Ensure your Node.js environment is v18+ where native Buffer methods are robust and `safe-buffer` is not needed. No direct code fix is typically required unless you had custom Buffer polyfills.
Thoroughly test decoding functionality if upgrading to `v1.x` and relying on specific, potentially non-standard decoding behaviors in `v0.x`.
Upgrade to `iconv-lite@0.7.2` or newer to get corrected TypeScript definitions for CommonJS exports. If stuck on an older version, manual type declarations (`declare module 'iconv-lite'`) might be necessary.
Upgrade to `iconv-lite@0.7.0` or newer to ensure correct handling of split surrogate pairs during UTF-8 streaming encoding. This is especially important for chunked data processing.
Use `iconv.encodingExists('encodingName')` to verify support. Refer to `iconv-lite` documentation or source for a list of supported encodings. Common errors include 'UTF8' instead of 'utf8'.Ensure the package is installed (`npm install iconv-lite`) and your `tsconfig.json` includes `node_modules/@types` or has `typeRoots` correctly configured. If using an older version that didn't ship types, install `@types/iconv-lite`.
For CommonJS in TypeScript (prior to v0.7.2), use `import * as iconv from 'iconv-lite'` or `const iconv = require('iconv-lite')`. For ESM, `import iconv from 'iconv-lite'` is correct. Ensure your `tsconfig.json`'s `module` and `esModuleInterop` settings are appropriate for your environment.No dependency data recorded yet.