nothingrandom / u8array

Create Uint8Array from string
MIT License
1 stars 1 forks source link

Not even worth it... #8

Open jimmywarting opened 3 years ago

jimmywarting commented 3 years ago

https://github.com/nothingrandom/u8array/blob/178cb30e1fde5474d05b61079b42172d61a6f75a/index.js#L1-L18

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 commented 3 years ago

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 commented 3 years ago

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