Skip to content
This repository has been archived by the owner on Sep 28, 2018. It is now read-only.

Usage outside of Polyfill #62

Open
noahsilas opened this issue Dec 22, 2016 · 2 comments
Open

Usage outside of Polyfill #62

noahsilas opened this issue Dec 22, 2016 · 2 comments

Comments

@noahsilas
Copy link

noahsilas commented Dec 22, 2016

I'm working on a tool to generate a CSV export of some data in a browser, and unfortunately, the encoding situation is a bit of a mess. TL/DR, it seems that the best outcome results in a tab separated, utf-16-le encoded file. [1][2]

I'm interested in using this package not as a polyfill, but by directly loading it when I need to perform that encoding. Would you be open to a PR that moved the core encoding functionality into a standalone module, and implementing the polyfill as a consumer of that standalone library?

[1] https://donatstudios.com/CSV-An-Encoding-Nightmare
[2] http://terminaln00b.ghost.io/excel-just-save-it-as-a-csv-noooooooo/

@inexorabletash
Copy link
Owner

Whoops, sorry, meant to respond.

As long as the polyfill doesn't require any build steps or pulling in additional libraries (e.g. some "require" variant), then I'd consider it. You may want to sketch out your idea first to discuss in more detail.

@inexorabletash
Copy link
Owner

Also, I should mention that you can implement UTF-16 encoding far more efficiently than the polyfill does:

// assume bytes = Uint8Array of byte.
// also assumes array buffers are little endian - may need to byte-swap otherwise
var string = new Uint16Array(bytes.buffer).map(cp => String.fromChar(cp)).join('');

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

No branches or pull requests

2 participants