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

Support for react-native/non-node environments #92

Closed
DT-1236 opened this issue Jun 10, 2021 · 5 comments
Closed

Support for react-native/non-node environments #92

DT-1236 opened this issue Jun 10, 2021 · 5 comments
Labels

Comments

@DT-1236
Copy link
Contributor

DT-1236 commented Jun 10, 2021

Are there plans to support this package in a non-node environment? I was able to get this working in react-native by adding the "buffer" package, but I'm not sure if there's a good way to conditionally add dependencies based on environment

@patrickhulce
Copy link
Collaborator

Are there plans to support this package in a non-node environment?

This already works in the non-node environments with useTArray option.

I was able to get this working in react-native by adding the "buffer" package

FWIW, you don't need to do this if you're comfortable working with Uint8Array output instead of a Buffer.

Happy to accept a PR with a "Working in Non-Node Environments" example pointing this out to the README.

@DT-1236
Copy link
Contributor Author

DT-1236 commented Jun 10, 2021

Ah, yes, it does work in react-native simply by adding the option. Thank you very much for your fast response. Any thoughts on adjusting the catch block for that section with something like this?

    if (err instanceof ReferenceError) {
      if (err.message === "Buffer is not defined") {
        err.message += " in this environment. Consider setting useTArray to true."
      }
    } 
    
    throw err;

Throwing an entirely new error might be more stylistically in-line with everything else

@patrickhulce
Copy link
Collaborator

patrickhulce commented Jun 10, 2021

Sure SGTM, PR welcome :)

(I'd even be up for automatically enabling useTArray if Buffer is not defined)

@DT-1236
Copy link
Contributor Author

DT-1236 commented Jun 10, 2021

(I'd even be up for automatically enabling useTArray if Buffer is not defined)

Hmm, that could potentially result in an unexpected return type. Granted I experienced that the other way around where I was trying to concat a Buffer onto an array 😆

I don't think there's going to be an easy way to get encoder to work in a non-node environment though

@patrickhulce
Copy link
Collaborator

thanks @DT-1236 ! we'll consider this closed by #93

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

No branches or pull requests

2 participants