feat: new /stats

This commit is contained in:
TresAbhi committed 2023-06-28 17:58:36 +00:00
1 parent 5fb36352d2
commit 64fd15c0a5
11 files changed
+510 -3

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
const numberRegex = /\d+(\.\d+)?/g;
/**
* Thanks to icl7126!
* https://stackoverflow.com/a/44134328/12294756
*/
export default function hslToHex(hsl: string) {
let [h, s, l] = Array.from(hsl.matchAll(numberRegex)).map((m) =>
parseFloat(m[0]),
);
l /= 100;
const a = (s * Math.min(l, 1 - l)) / 100;
const f = (n: number) => {
const k = (n + h / 30) % 12;
const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
return Math.round(255 * color)
.toString(16)
.padStart(2, '0'); // convert to Hex and prefix "0" if needed
};
return `#${f(0)}${f(8)}${f(4)}`;
}