fix(utils): share clamp helpers

Co-authored-by: Gustavo Madeira Santana <gumadeiras@gmail.com>
This commit is contained in:
Gustavo Madeira Santana
2026-01-18 06:18:05 -05:00
committed by Peter Steinberger
parent 810394f43b
commit 7252938339
3 changed files with 11 additions and 5 deletions

View File

@@ -8,6 +8,14 @@ export async function ensureDir(dir: string) {
await fs.promises.mkdir(dir, { recursive: true });
}
export function clampNumber(value: number, min: number, max: number): number {
return Math.max(min, Math.min(max, value));
}
export function clampInt(value: number, min: number, max: number): number {
return clampNumber(Math.floor(value), min, max);
}
export type WebChannel = "web";
export function assertWebChannel(input: string): asserts input is WebChannel {