File size: 1,611 Bytes
8766bc5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | // import mime from "mime-types";
export const playable = (): boolean => {
// let video_element = document.createElement("video");
// let mime_type = mime.lookup(filename);
// return video_element.canPlayType(mime_type) != "";
return true; // FIX BEFORE COMMIT - mime import causing issues
};
export const deepCopy = <T>(obj: T): T => {
return JSON.parse(JSON.stringify(obj));
};
export function randInt(min: number, max: number): number {
return Math.floor(Math.random() * (max - min) + min);
}
export const getNextColor = (index: number, alpha = 1): string => {
let default_colors = [
[255, 99, 132],
[54, 162, 235],
[240, 176, 26],
[153, 102, 255],
[75, 192, 192],
[255, 159, 64],
[194, 88, 74],
[44, 102, 219],
[44, 163, 23],
[191, 46, 217],
[160, 162, 162],
[163, 151, 27]
];
if (index < default_colors.length) {
var color_set = default_colors[index];
} else {
var color_set = [randInt(64, 196), randInt(64, 196), randInt(64, 196)];
}
return (
"rgba(" +
color_set[0] +
", " +
color_set[1] +
", " +
color_set[2] +
", " +
alpha +
")"
);
};
export const prettyBytes = (bytes: number): string => {
let units = ["B", "KB", "MB", "GB", "PB"];
let i = 0;
while (bytes > 1024) {
bytes /= 1024;
i++;
}
let unit = units[i];
return bytes.toFixed(1) + " " + unit;
};
export const prettySI = (num: number): string => {
let units = ["", "k", "M", "G", "T", "P", "E", "Z"];
let i = 0;
while (num > 1000 && i < units.length - 1) {
num /= 1000;
i++;
}
let unit = units[i];
return (Number.isInteger(num) ? num : num.toFixed(1)) + unit;
};
|