const btoa = data => Buffer.from(data).toString("base64");
const atob = data => Buffer.from(data, "base64").toString();
function iterate(iterable) {
if(iterable === undefined || iterable === null) return [];
if(iterable instanceof Array || typeof iterable === "string" && (iterable = [...iterable])) return iterable.entries();
else {
const iterator = Object.entries(iterable).map((value, i) => [i, ...value]);
return iterator.length || iterable.constructor === Object ? iterator : [[0, iterable]];
}
}
Object.reduce = function(object, callbackfn, initialValue = Object.values(object)[0]) {
const keys = Object.keys(object);
let previousValue = initialValue;
let currentIndex;
if(typeof callbackfn !== "function")
throw new TypeError(callbackfn + " is not a function");
if(typeof initialValue === "undefined" && !keys.length)
throw new TypeError("Reduce of empty object with no initial value");
for(currentIndex = +(initialValue == Object.values(object)[0]); currentIndex < keys.length; currentIndex++) {
var key = keys[currentIndex];
var value = object[key];
previousValue = callbackfn(
previousValue,
{key, value},
currentIndex,
object
);
}
return previousValue;
};
module.exports = {
btoa,
atob,
iterate
};