TelegramPWA/src/util/generateIdFor.ts
2022-11-01 18:53:18 +01:00

14 lines
243 B
TypeScript

export default function generateIdFor(store: AnyLiteral, withAutoUpdate = false) {
let id;
do {
id = String(Math.random()).replace('0.', 'id');
} while (store[id]);
if (withAutoUpdate) {
store[id] = true;
}
return id;
}