feat: add debounce function

This commit is contained in:
Sebin Nyshkim 2023-01-22 16:45:14 +01:00
parent 2c4c07441b
commit c77854667b

View file

@ -1,3 +1,17 @@
const debounce = (fn: Function, delay: number = 300): any => {
let timer = 0;
const debounced = (...args: Array<any>): void => {
if (!args) args = [];
clearTimeout(timer);
timer = setTimeout(() => {
fn.apply(fn, args);
}, delay);
};
return debounced;
};
const getClientLocale = (): string => {
return navigator.languages.length > 0 ? navigator.languages[0] : "en-US";
};
@ -51,6 +65,7 @@ const dateFormat = new Intl.DateTimeFormat(getClientLocale(), {
});
export {
debounce,
getClientLocale,
getAge,
toImperial,