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

Not even worth it... #8

Open
jimmywarting opened this issue Jul 3, 2021 · 2 comments
Open

Not even worth it... #8

jimmywarting opened this issue Jul 3, 2021 · 2 comments

Comments

@jimmywarting
Copy link

u8array/index.js

Lines 1 to 18 in 178cb30

const u8 = (src) => {
let string = '';
if (typeof src !== 'string') {
string = src.toString();
} else {
string = src;
}
const arrayBuffer = new ArrayBuffer(string.length * 1);
const newUint = new Uint8Array(arrayBuffer);
newUint.forEach((_, i) => {
newUint[i] = string.charCodeAt(i);
});
return newUint;
};
module.exports = u8;

Can all be replaced by this:

var e = new TextEncoder()
module.exports = x => e.encode(x)

Would discourage use of this package and instead encourage ppl to use TextEncoder instead

@nothingrandom
Copy link
Owner

I do agree that the use of this node package is diminishing, I would like to note that the implementation of TextEncoder is still experimental, and requires a polyfill for IE.

Further, this package does a string check, which can be useful for when a number gets passed in instead.

@jimmywarting
Copy link
Author

jimmywarting commented Jul 8, 2021

webidl have stuff that makes sure everything you pass to encode() is transformed into a string first by doing more magic than just String(obj)
you can pass in boolean, numbers, null, whatever...

and IE is pretty much dead now... think it would just be better to conditionally load in a pollyfill if TextEncoder isn't available

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

2 participants