diff options
author | RaindropsSys <raindrops@equestria.dev> | 2024-06-29 20:59:16 +0200 |
---|---|---|
committer | RaindropsSys <raindrops@equestria.dev> | 2024-06-29 20:59:16 +0200 |
commit | 914bcbb474f6f186c212b2da0d9d864b5e75d8e4 (patch) | |
tree | b77a3e341f87e7a9c4ad9e1f9d4928f5b2495329 /src/PrisbeamUtilities.ts | |
parent | 1c94bd658c2469f9ca9f465db82e71b6f7d2bfe8 (diff) | |
download | faunerie-914bcbb474f6f186c212b2da0d9d864b5e75d8e4.tar.gz faunerie-914bcbb474f6f186c212b2da0d9d864b5e75d8e4.tar.bz2 faunerie-914bcbb474f6f186c212b2da0d9d864b5e75d8e4.zip |
Rename to Faunerie
Diffstat (limited to 'src/PrisbeamUtilities.ts')
-rwxr-xr-x | src/PrisbeamUtilities.ts | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/src/PrisbeamUtilities.ts b/src/PrisbeamUtilities.ts deleted file mode 100755 index 455a4d7..0000000 --- a/src/PrisbeamUtilities.ts +++ /dev/null @@ -1,75 +0,0 @@ -export class PrisbeamUtilities { - static timeAgo(time: number | Date | string) { - if (!isNaN(parseInt(time as string))) { - time = new Date(time).getTime(); - } - - let periods = ["second", "minute", "hour", "day", "week", "month", "year", "age"]; - - let lengths = [60, 60, 24, 7, 4.35, 12, 100]; - - let now = new Date().getTime(); - - let difference = Math.round((now - (time as number)) / 1000); - let tense: string; - let period: string; - - if (difference <= 10 && difference >= 0) { - return "now"; - } else if (difference > 0) { - tense = "ago"; - } else { - tense = "later"; - } - - let j: number; - - for (j = 0; difference >= lengths[j] && j < lengths.length - 1; j++) { - difference /= lengths[j]; - } - - difference = Math.round(difference); - - period = periods[j]; - - return `${difference} ${period}${difference > 1 ? "s" : ""} ${tense}`; - } - - static formatSize(size: number) { - let sizeString: string; - - if (size > 1024 ** 3) { - sizeString = (size / 1024 ** 3).toFixed(1) + " GB"; - } else if (size > 1024 ** 2) { - sizeString = (size / 1024 ** 2).toFixed(1) + " MB"; - } else if (size > 1024) { - sizeString = (size / 1024).toFixed(0) + " KB"; - } else { - sizeString = size + " B"; - } - - return sizeString ?? size; - } - - static getMimeBadge(type: string) { - switch (type) { - case "image/gif": - return `<span style='float: right; margin-right: 10px; font-size: 1rem; margin-top: 5px;' class='badge bg-danger'>GIF</span>`; - - case "image/jpeg": - return `<span style='float: right; margin-right: 10px; font-size: 1rem; margin-top: 5px;' class='badge bg-warning'>JPEG</span>`; - - case "image/png": - return `<span style='float: right; margin-right: 10px; font-size: 1rem; margin-top: 5px;' class='badge bg-primary'>PNG</span>`; - - case "image/svg+xml": - return `<span style='float: right; margin-right: 10px; font-size: 1rem; margin-top: 5px;' class='badge bg-light'>SVG</span>`; - - case "video/webm": - return `<span style='float: right; margin-right: 10px; font-size: 1rem; margin-top: 5px;' class='badge bg-info'>WebM</span>`; - - default: - return `<span style='float: right; margin-right: 10px; font-size: 1rem; margin-top: 5px;' class='badge bg-secondary'>Unknown</span>`; - } - } -} |