All files / core/src/utils uuid.ts

100% Statements 15/15
100% Branches 4/4
100% Functions 1/1
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 201x 1x   1x 694x   694x 320x 651x 374x 374x 694x   694x 694x 694x   694x 694x  
let lastTimestamp = 0;
let sequence = 0;
 
export function shortId(): string {
  const timestamp = Date.now();
 
  if (timestamp === lastTimestamp) {
    sequence++;
  } else {
    sequence = 0;
  }
  lastTimestamp = timestamp;
 
  const timestampPart = timestamp.toString(36);
  const sequencePart = sequence.toString(36).padStart(3, '0');
  const randomPart = Math.random().toString(36).substring(2, 6);
 
  return `${timestampPart}${sequencePart}${randomPart}`;
}