ashtuchkin / iconv-lite

Convert character encodings in pure javascript.
MIT License
3.07k stars 282 forks source link

Mechanism to add encodings from external npm packages #253

Open ashtuchkin opened 4 years ago

ashtuchkin commented 4 years ago

Some encodings are very rare (e.g. utf7 and iso-2022-jp #60), so it's always a hard decision to include them in iconv-lite, as they add space and memory requirements. To make this choice simpler, it would be nice to add an extension mechanism that would make it easy to add them as separate npm packages.

Something like this:

const iconv = require("iconv-lite");
iconv.addEncoding(require("encoding-iso-2022-jp"));

What we'll need:

Question: would it be better to use immutable-like interface iconv = iconv.withEncoding(require('...'));? It would help with testability, but overall I think it's not worth it, as users will have to either do it in every file that needs iconv, or pass it around in some kind of a global.