forked from BRETT/BRETT
Initial Commit
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { randomInt } from 'node:crypto'
|
||||
|
||||
export function randomUserColor() {
|
||||
const h = randomInt(360)
|
||||
const s = 60 + randomInt(30)
|
||||
const l = 50 + randomInt(15)
|
||||
const a = s * Math.min(l, 100 - l) / 100
|
||||
const f = (n: number) => {
|
||||
const k = (n + h / 30) % 12
|
||||
const v = l / 100 - a * Math.max(-1, Math.min(k - 3, 9 - k, 1))
|
||||
return Math.round(Math.min(1, Math.max(0, v)) * 255)
|
||||
}
|
||||
return `#${[f(0), f(8), f(4)].map(v => v.toString(16).padStart(2, '0')).join('')}`
|
||||
}
|
||||
|
||||
export function avatarUrl(avatar: string | null) {
|
||||
return avatar ? `/uploads/avatars/${avatar}` : null
|
||||
}
|
||||
Reference in New Issue
Block a user