Skip to content

Commit

Permalink
feat: unique hash id function
Browse files Browse the repository at this point in the history
  • Loading branch information
wsbrunson committed Apr 12, 2024
1 parent 449034e commit 9838f20
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,22 @@ export function base64decode(str: string): string {
throw new Error(`Can not find window.atob or Buffer`);
}

export function uniqueID(): string {
export const uniqueHashId = (): string => {
const chars = "0123456789abcdef";

const randomID = "xxxxxxxxxx".replace(/./g, () => {
return chars.charAt(Math.floor(Math.random() * chars.length));
});
return "xxxxxxxxxxxxx".replace(/./g, () =>
chars.charAt(Math.floor(Math.random() * chars.length))
);
};

export function uniqueID(): string {
const timeID = base64encode(
new Date().toISOString().slice(11, 19).replace("T", ".")
)
.replace(/[^a-zA-Z0-9]/g, "")
.toLowerCase();

return `uid_${randomID}_${timeID}`;
return `uid_${uniqueHashId()}_${timeID}`;
}

export function getGlobal(): Object {
Expand Down

0 comments on commit 9838f20

Please # to comment.