diff options
Diffstat (limited to 'std/uuid/v4.ts')
-rw-r--r-- | std/uuid/v4.ts | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/std/uuid/v4.ts b/std/uuid/v4.ts index d291b5478..83fc6d86e 100644 --- a/std/uuid/v4.ts +++ b/std/uuid/v4.ts @@ -1,5 +1,7 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +import { bytesToUuid } from "./_common.ts"; + const UUID_RE = new RegExp( "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$", "i" @@ -15,19 +17,5 @@ export function generate(): string { rnds[6] = (rnds[6] & 0x0f) | 0x40; // Version 4 rnds[8] = (rnds[8] & 0x3f) | 0x80; // Variant 10 - const bits: string[] = [...rnds].map((bit): string => { - const s: string = bit.toString(16); - return bit < 0x10 ? "0" + s : s; - }); - return [ - ...bits.slice(0, 4), - "-", - ...bits.slice(4, 6), - "-", - ...bits.slice(6, 8), - "-", - ...bits.slice(8, 10), - "-", - ...bits.slice(10), - ].join(""); + return bytesToUuid(rnds); } |