LCOV - code coverage report
Current view: top level - randomjs/distribution - uuid4.ts (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 1 22 4.5 %
Date: 2021-03-12 10:43:40 Functions: 0 2 0.0 %

          Line data    Source code
       1             : import { Engine } from "../types.ts";
       2           1 : import { stringRepeat } from "../utils/stringRepeat.ts";
       3             : 
       4           0 : function zeroPad(text: string, zeroCount: number) {
       5           0 :   return stringRepeat("0", zeroCount - text.length) + text;
       6           0 : }
       7             : 
       8             : /**
       9             :  * Returns a Universally Unique Identifier Version 4.
      10             :  *
      11             :  * See http://en.wikipedia.org/wiki/Universally_unique_identifier
      12             :  */
      13           0 : export function uuid4(engine: Engine) {
      14           0 :   const a = engine.next() >>> 0;
      15           0 :   const b = engine.next() | 0;
      16           0 :   const c = engine.next() | 0;
      17           0 :   const d = engine.next() >>> 0;
      18             : 
      19           0 :   return (
      20           0 :     zeroPad(a.toString(16), 8) +
      21           0 :     "-" +
      22           0 :     zeroPad((b & 0xffff).toString(16), 4) +
      23           0 :     "-" +
      24           0 :     zeroPad((((b >> 4) & 0x0fff) | 0x4000).toString(16), 4) +
      25           0 :     "-" +
      26           0 :     zeroPad(((c & 0x3fff) | 0x8000).toString(16), 4) +
      27           0 :     "-" +
      28           0 :     zeroPad(((c >> 4) & 0xffff).toString(16), 4) +
      29           0 :     zeroPad(d.toString(16), 8)
      30           0 :   );
      31           0 : }

Generated by: LCOV version 1.15