Move generate userID to shared lib

This commit is contained in:
Ajay
2023-02-18 02:54:42 -05:00
parent 1d05c2b3df
commit 4ca6a331f1
4 changed files with 11 additions and 30 deletions

View File

@@ -49,27 +49,8 @@ function indexesOf<T>(array: T[], value: T): number[] {
return array.map((v, i) => v === value ? i : -1).filter(i => i !== -1);
}
function generateUserID(length = 36): string {
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "";
if (window.crypto && window.crypto.getRandomValues) {
const values = new Uint32Array(length);
window.crypto.getRandomValues(values);
for (let i = 0; i < length; i++) {
result += charset[values[i] % charset.length];
}
return result;
} else {
for (let i = 0; i < length; i++) {
result += charset[Math.floor(Math.random() * charset.length)];
}
return result;
}
}
export const GenericUtils = {
getErrorMessage,
getLuminance,
generateUserID,
indexesOf
}