3 examples of 'btoa nodejs' in JavaScript

Every line of 'btoa nodejs' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
6function btoa(str) {
7 let buffer;
8
9 if (str instanceof Buffer) {
10 buffer = str;
11 } else {
12 buffer = new Buffer(str.toString(), 'binary');
13 }
14
15 return buffer.toString('base64');
16}
6function atob(str) {
7 // normal window
8 if ('function' === typeof a2b) {
9 return a2b(str);
10 }
11 // browserify (web worker)
12 else if ('function' === typeof Buffer) {
13 return new Buffer(str, 'base64').toString('binary');
14 }
15 // ios web worker with base64js
16 else if ('object' === typeof w.base64js) {
17 // bufferToBinaryString
18 // https://github.com/coolaj86/unibabel-js/blob/master/index.js#L50
19 var buf = w.base64js.b64ToByteArray(str);
20
21 return Array.prototype.map.call(buf, function (ch) {
22 return String.fromCharCode(ch);
23 }).join('');
24 }
25 // ios web worker without base64js
26 else {
27 throw new Error("you're probably in an ios webworker. please include use beatgammit's base64-js");
28 }
29}
10function browserAtob(input) {
11 try {
12 return window.atob(input);
13 } catch (e) {
14 return null;
15 }
16}

Related snippets