forked from abner/for-legacy-web
Port settings.
This commit is contained in:
9
src/lib/conversion.ts
Normal file
9
src/lib/conversion.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export function urlBase64ToUint8Array(base64String: string) {
|
||||
const padding = "=".repeat((4 - (base64String.length % 4)) % 4);
|
||||
const base64 = (base64String + padding)
|
||||
.replace(/\-/g, "+")
|
||||
.replace(/_/g, "/");
|
||||
const rawData = window.atob(base64);
|
||||
|
||||
return Uint8Array.from([...rawData].map(char => char.charCodeAt(0)));
|
||||
}
|
||||
15
src/lib/debounce.ts
Normal file
15
src/lib/debounce.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export function debounce(cb: Function, duration: number) {
|
||||
// Store the timer variable.
|
||||
let timer: number;
|
||||
// This function is given to React.
|
||||
return (...args: any[]) => {
|
||||
// Get rid of the old timer.
|
||||
clearTimeout(timer);
|
||||
// Set a new timer.
|
||||
timer = setTimeout(() => {
|
||||
// Instead calling the new function.
|
||||
// (with the newer data)
|
||||
cb(...args);
|
||||
}, duration);
|
||||
};
|
||||
}
|
||||
9
src/lib/fileSize.ts
Normal file
9
src/lib/fileSize.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export function determineFileSize(size: number) {
|
||||
if (size > 1e6) {
|
||||
return `${(size / 1e6).toFixed(2)} MB`;
|
||||
} else if (size > 1e3) {
|
||||
return `${(size / 1e3).toFixed(2)} KB`;
|
||||
}
|
||||
|
||||
return `${size} B`;
|
||||
}
|
||||
Reference in New Issue
Block a user