icydraw/src/common/helper.ts

14 lines
331 B
TypeScript
Raw Normal View History

2022-04-02 13:45:07 +00:00
export function clamp(x: number, min: number, max: number): number {
return Math.min(Math.max(x, min), max);
}
2022-04-03 12:25:29 +00:00
export function debounce(func: Function, timeout = 300) {
let timer: any;
return (...args: any[]) => {
clearTimeout(timer);
timer = setTimeout(() => {
func.apply(this, args);
}, timeout);
};
}