All files / random guid.ts

100% Statements 5/5
100% Branches 2/2
100% Functions 2/2
100% Lines 5/5

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      3x 15x   465x   465x   465x      
/**
 * Generates a random guid
 */
export function randomGuid(): string {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
    // eslint-disable-next-line: no-bitwise
    const r = Math.random() * 16 | 0;
    // eslint-disable-next-line: no-bitwise no-magic-numbers
    const v = c === 'x' ? r : (r & 0x3 | 0x8);
 
    return v.toString(16);
  });
}