4 examples of 'atob nodejs' in JavaScript

Every line of 'atob 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 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}
61function atob(input) {
62 input = String(input);
63 var position = 0,
64 output = [],
65 buffer = 0, bits = 0, n;
66
67 input = input.replace(/\s/g, '');
68 if ((input.length % 4) === 0) { input = input.replace(/=+$/, ''); }
69 if ((input.length % 4) === 1) { throw Error("InvalidCharacterError"); }
70 if (/[^+/0-9A-Za-z]/.test(input)) { throw Error("InvalidCharacterError"); }
71
72 while (position < input.length) {
73 n = B64_ALPHABET.indexOf(input.charAt(position));
74 buffer = (buffer << 6) | n;
75 bits += 6;
76
77 if (bits === 24) {
78 output.push(String.fromCharCode((buffer >> 16) & 0xFF));
79 output.push(String.fromCharCode((buffer >> 8) & 0xFF));
80 output.push(String.fromCharCode(buffer & 0xFF));
81 bits = 0;
82 buffer = 0;
83 }
84 position += 1;
85 }
86
87 if (bits === 12) {
88 buffer = buffer >> 4;
89 output.push(String.fromCharCode(buffer & 0xFF));
90 } else if (bits === 18) {
91 buffer = buffer >> 2;
92 output.push(String.fromCharCode((buffer >> 8) & 0xFF));
93 output.push(String.fromCharCode(buffer & 0xFF));
94 }
95
96 return output.join('');
97};
10function browserAtob(input) {
11 try {
12 return window.atob(input);
13 } catch (e) {
14 return null;
15 }
16}
94function atob( coded ) {
95 var i;
96
97 if ( ! c ) {
98 init();
99 }
100
101 coded = coded.replace( /[^A-Za-z0-9\+\/\=]/g, '' );
102 coded = String(coded).split('=');
103 i = coded.length;
104
105 do {
106 --i;
107 coded[i] = code( coded[i], true, r64, a256, 6, 8 );
108 } while ( i > 0 );
109
110 coded = coded.join('');
111 return coded;
112}

Related snippets