diff options
| author | Ali Hasani <a.hassssani@gmail.com> | 2020-04-15 19:08:05 +0430 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-15 10:38:05 -0400 |
| commit | 7cfd094359f7f94573b084328ad1a956dd70005d (patch) | |
| tree | 5541cf175560f24573227a8cec04d187c5dc21c3 /std/uuid/_common.ts | |
| parent | 926db017d99d076110aeb70fe4fc6df56f58d09c (diff) | |
Implement UUID v1 (#4758)
Diffstat (limited to 'std/uuid/_common.ts')
| -rw-r--r-- | std/uuid/_common.ts | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/std/uuid/_common.ts b/std/uuid/_common.ts new file mode 100644 index 000000000..b0cad2584 --- /dev/null +++ b/std/uuid/_common.ts @@ -0,0 +1,18 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +export function bytesToUuid(bytes: number[] | Uint8Array): string { + const bits: string[] = [...bytes].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(""); +} |
