All files uuid.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 15 16 17            8x   2x   62x 62x 62x        
/**
 * Generates non cryptographic UUID
 * @example
 * P.uuidv4() //=> aecad060-0bb7-4567-af08-4dfe5f46d130
 * @category Utility
 */
export function uuidv4(): string {
  // https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
    // tslint:disable
    let r = (Math.random() * 16) | 0,
      v = c === 'x' ? r : (r & 0x3) | 0x8;
    return v.toString(16);
  });
  // tslint:enable
}