atob.js/node-atob.js

13 lines
347 B
JavaScript
Raw Normal View History

"use strict";
2021-03-04 05:08:29 +00:00
const b64Alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
function atob(str) {
2021-03-04 05:08:29 +00:00
for (const ch of str)
if (!b64Alphabet.includes(ch))
throw new Error(`Invalid character '${ch}' in base64 String`);
2018-03-28 04:26:00 +00:00
return Buffer.from(str, 'base64').toString('binary');
}
module.exports = atob.atob = atob;