ggez-banking-sdk
Version:
A Node.js package to handle GGEZ Banking API endpoints, Simplify the process of managing CRUD operations with this efficient and easy-to-use package.
28 lines (27 loc) • 980 B
JavaScript
const pad = (number) => String(number).padStart(2, "0");
const padMilliseconds = (number) => String(number).padStart(3, "0");
const getBase64 = async (url) => {
try {
const response = await fetch(url);
const blob = await response.blob();
const base64 = new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => {
if (reader.result instanceof ArrayBuffer) {
const binaryData = new Uint8Array(reader.result);
const base64Data = btoa(String.fromCharCode(...binaryData));
resolve(base64Data);
}
else {
reject(new Error("Failed to read as ArrayBuffer"));
}
};
reader.readAsArrayBuffer(blob);
});
return await base64;
}
catch (error) {
return null;
}
};
export { pad, padMilliseconds, getBase64 };