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

fix: allow use in bundlers #10

Closed

Conversation

achingbrain
Copy link
Contributor

@achingbrain achingbrain commented Mar 25, 2021

We can't use the ** operator as right now it gets transpiled to Math.pow which only takes Numbers.

Similarly, trying to avoid referencing node globals to get a Buffer instance causes similar problems now that bundlers don't tend to come with node polyfills any more.

Swaps the use of ** for the BigInt literal result of the calculation and uses the Buffer module to ensure compatibility.

Fixes #7
Fixes #8

Please publish with a main field that points to a cjs version of this module to also fix #9.

We can't use the `**` operator as right now it gets transpiled to `Math.pow`
which only takes Numbers.

Similarly, trying to avoid referencing node globals to get a `Buffer` instance
causes similar problems now that bundlers don't tend to come with node polyfills
any more.

Swaps the use of `**` for the BigInt literal result of the calculation and uses
the `Buffer` module to ensure compatibility.

Fixes #7
Fixes #8

Please publish with a `main` field to also fix #9.
@achingbrain
Copy link
Contributor Author

These are the changes I have to make to get the examples passing in ipfs/js-ipfs#3550

2 ** 16,
2 ** 32,
// BigInt(2) ** BigInt(64) gets transpiled to Math.pow(BigInt(2), BigInt(64)) so use the literal value
18446744073709551616n
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't use literals though, I started off with all literals but it breaks with some version of something, I can't recall which, but literals are a bit too new compared to the constructor, BigInt('18446744073709551616') might be acceptable though.

@rvagg rvagg mentioned this pull request Mar 26, 2021
@achingbrain
Copy link
Contributor Author

Superseded by #11

@achingbrain achingbrain deleted the fix/allow-use-in-bundlers branch March 26, 2021 12:03
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

Successfully merging this pull request may close these issues.

Needs a main entry in package.json ** operator Buffer detection
2 participants