mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-19 16:38:23 +00:00
* Inertia p1? * Inertia'fied signed out homepage? * Split up signed in page * WIP signed in v2? * Better signed in? * Clean up extensions page! * Fix currently hacking * Better docs page? * Docs update 2 * Clean up "What is Hackatime?" + get rid of that godawful green dev mode * Better nav? * Cleaner settings? * Fix commit times * Fix flashes + OS improv * Setup v2 * Readd some of the syncers? * Remove stray emdash * Clean up Step 3 * Oops, remove .vite * bye bye, /inertia-example * bin/rubocop -A * Fix docs vuln
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
export const pluralize = (count: number, singular: string, plural: string) =>
|
|
count === 1 ? singular : plural;
|
|
|
|
export const toSentence = (items: string[]) => {
|
|
if (items.length === 0) return "";
|
|
if (items.length === 1) return items[0];
|
|
if (items.length === 2) return `${items[0]} and ${items[1]}`;
|
|
return `${items.slice(0, -1).join(", ")}, and ${items[items.length - 1]}`;
|
|
};
|
|
|
|
export const secondsToDisplay = (seconds?: number) => {
|
|
if (!seconds) return "0m";
|
|
const hours = Math.floor(seconds / 3600);
|
|
const minutes = Math.floor((seconds % 3600) / 60);
|
|
return hours > 0 ? `${hours}h ${minutes}m` : `${minutes}m`;
|
|
};
|
|
|
|
export const percentOf = (value: number, max: number) => {
|
|
if (!max || max === 0) return 0;
|
|
return Math.max(2, Math.round((value / max) * 100));
|
|
};
|
|
|
|
export const logScale = (value: number, maxVal: number): number => {
|
|
if (value === 0) return 0;
|
|
const minPercent = 5;
|
|
const maxPercent = 100;
|
|
const linearRatio = value / maxVal;
|
|
const logRatio = Math.log(value + 1) / Math.log(maxVal + 1);
|
|
const linearWeight = 0.8;
|
|
const logWeight = 0.2;
|
|
const scaled =
|
|
minPercent +
|
|
(linearWeight * linearRatio + logWeight * logRatio) *
|
|
(maxPercent - minPercent);
|
|
return Math.min(Math.round(scaled), maxPercent);
|
|
};
|