hildjj / node-cbor

Encode and decode CBOR documents, with both easy mode, streaming mode, and SAX-style evented mode.
MIT License
357 stars 73 forks source link

It would be helpful if you'd document whether this works on browser #117

Closed mcclure closed 3 years ago

mcclure commented 3 years ago

Hi, I came across this project for the first time today. I'm trying to incorporate it into a project (targeting web initially and possibly node cli later). The README says:

This package now requires node.js 8.3 or higher

And the main cbor website seems to suggest node-cbor is for use with node exclusively.

However, other things (like issues talking about websocket) seem to suggest this works with browser.

Because the existing language is potentially misleading, it would be helpful if your landing page made it explicit you work in the browser. And if you don't work in browser, it would be helpful to make that explicit.

(I see there is a separate cbor-js package, but (1) I want to write my own code in such a way it works in both node and browser, and (2) the cbor-js package is five years old and seems to rely on five-year-old technologies such as Bower.)

rivertam commented 3 years ago

I'm pretty sure it works for the most part in browser, though there are hiccups.

As a heads-up, there are node implementations of WebSockets as well.

hildjj commented 3 years ago

OK, I'm finally getting around to this. Would a simple demo using webpack be enough?

hildjj commented 3 years ago

OK, see the source and running code of an example. I'll link to this in the README eventually. If someone has a better way of doing this, I'd appreciate it, because webpack isn't my favorite.

mcclure commented 3 years ago

If you actively want to replace webpack with something I think people are using "parcel" now more these days, but I think the demo is fine! (I still use webpack.)

hildjj commented 3 years ago

I also got browserify+babelify to work pretty easily. I'll give parcel a shot, then provide examples of all three.

hildjj commented 3 years ago

OK, that feels like plenty of examples. Moral of the story: you can't just use this library with import, you need to bundle up polyfills for Buffer, process, util, and stream (at least), along with nofilter and bignumber.js.

The easiest of these to use, BY FAR, was parcel.

mcclure commented 3 years ago

Getting offtopic here but is there a specific reason you use bignumber.js instead of ES2020 BigInt? Being able to rely on the browser BigInt implementation instead of including bignumber would significantly lower the browser footprint of the node-cbor library.

hildjj commented 3 years ago

Using BigInts is now the default in v6.0.0. BigNumber is still needed for large fractional numbers, at least until https://github.com/tc39/proposal-decimal lands.

hildjj commented 3 years ago

@mcclure see #131