Skip to content

Commit

Permalink
feat: add some features
Browse files Browse the repository at this point in the history
  • Loading branch information
m-avagyan committed Mar 1, 2024
1 parent fc07a64 commit b50adcf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/helpers/debounce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let timeout: NodeJS.Timeout | null = null;

export const debounce = <F extends (...args: any[]) => any>(func: F, delay = 250) => {
return (...args: Parameters<F>) => {
if (timeout) {
clearTimeout(timeout);
}

timeout = setTimeout(() => {
func(...args);
}, delay);
};
};
29 changes: 29 additions & 0 deletions src/helpers/user-os.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export const getUserOS = () => {
const userAgent = navigator.userAgent || navigator.vendor;

if (/windows phone/i.test(userAgent)) {
return 'windows-phone';
}

if (/win/i.test(userAgent)) {
return 'windows';
}

if (/iPad|iPhone|iPod/.test(userAgent)) {
return 'ios';
}

if (/Mac/i.test(navigator.platform) && !('ontouchend' in document)) {
return 'macos';
}

if (/android/i.test(userAgent)) {
return 'android';
}

if (/linux/i.test(userAgent)) {
return 'linux';
}

return 'unknown';
};
3 changes: 3 additions & 0 deletions src/helpers/uuid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const uuid = (length = 12): string => {
return Math.random().toString(36).substring(3, length);
};

0 comments on commit b50adcf

Please sign in to comment.