Ids

_archivesourcetypescript
Path: _archive/loom-stale-pre-sprint-snapshot/src/lib/ids.tsRelative: loom-stale-pre-sprint-snapshot/src/lib/ids.tsSubproject: _archiveCategory: archived
Lines: 58Bytes: 2,060Imports: 0Exports: 8

Content Preview

  1. /**
  2. * Identity + hashing primitives shared by every loop.
  3. * Web Crypto only — identical behavior on workerd and Bun (HC-1 parity).
  4. */
  5. const ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789";
  6. const ID_LEN = 12;
  7. function randomBody(): string {
  8. const bytes = new Uint8Array(ID_LEN);
  9. crypto.getRandomValues(bytes);
  10. let out = "";
  11. for (const b of bytes) out += ALPHABET[b % ALPHABET.length];
  12. return out;
  13. }
  14. export const newGoalId = (): `goal_${string}` => `goal_${randomBody()}`;
  15. export cons