cloudcmd/common/base64.js
2021-12-15 12:21:28 +02:00

22 lines
395 B
JavaScript

'use strict';
const isFn = (a) => typeof a === 'function';
module.exports.btoa = (str) => {
if (typeof btoa === 'function')
return btoa(str);
return Buffer
.from(str)
.toString('base64');
};
module.exports.atob = (str) => {
if (isFn(atob))
return atob(str);
return Buffer
.from(str, 'base64')
.toString('binary');
};