1

I have the following code in Nodejs:

Buffer.from(`${pwd}`, 'base64').toString('utf8')

I have to do the same thing in Javascript for React-native.

How can I do some advice?

Paul
  • 3,644
  • 9
  • 47
  • 113
  • Which part? `Buffer` or the string conversion? – Diodeus - James MacFarlane May 21 '19 at 16:50
  • Do what webpack and browserify do and polyfill it: [Other node core libraries](https://webpack.js.org/configuration/node/#other-node-core-libraries) which uses [node-libs-browser](https://github.com/webpack/node-libs-browser#readme). – zero298 May 21 '19 at 16:52
  • If you just need to convert a string between base64 and utf8, you can probably just use [`btoa`](https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Appendix.3A_Decode_a_Base64_string_to_Uint8Array_or_ArrayBuffer). – zero298 May 21 '19 at 16:53
  • @Diodeus-JamesMacFarlane: You know the code I wrote in the post, I have to do the same but in react-native, what Buffer.from does not find it for react-native, but I presume that if I remember the toString (...) function well, it accepts only numerical parameters in js. So I have to do everything. – Paul May 21 '19 at 17:07
  • @zero298: What do you think of this could go: https://stackoverflow.com/a/42833475/8024296 – Paul May 21 '19 at 17:08

0 Answers0