ente/web/packages/base/id-worker.ts
Manav Rathi ce421eded4
nanoids
2024-08-08 11:17:18 +05:30

18 lines
624 B
TypeScript

import { customAlphabet } from "nanoid/non-secure";
import { alphabet } from "./id";
const nanoid = customAlphabet(alphabet, 22);
/**
* This is a variant of the regular {@link newID} that can be used in web
* workers.
*
* Web workers don't have access to a secure random generator, so we need to use
* the non-secure variant.
* https://github.com/ai/nanoid?tab=readme-ov-file#web-workers
*
* For many of our use cases, where we're not using these IDs for cryptographic
* operations, this is okay. We also have an increased alphabet length.
*/
export const newNonSecureID = (prefix: string) => prefix + nanoid();