Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mechanism to add encodings from external npm packages #253

Open
5 tasks
ashtuchkin opened this issue Jul 14, 2020 · 0 comments
Open
5 tasks

Mechanism to add encodings from external npm packages #253

ashtuchkin opened this issue Jul 14, 2020 · 0 comments

Comments

@ashtuchkin
Copy link
Owner

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:

  • Solidify & publish codec interface.
  • Solidify & publish backend interface.
  • Add addEncoding() function. It will by default check that the new package does not override any existing encodings/aliases. This behavior can be disabled by passing {replace: true} as a second arg. Function should be idempotent.
  • Extract utf7 as an example.
  • Create a test harness that would help authors make sure their codecs work on the whole range of supported environments.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant