main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
619 bytes
|
Line | |
---|
1 | import native from './native.js';
|
---|
2 | import rng from './rng.js';
|
---|
3 | import { unsafeStringify } from './stringify.js';
|
---|
4 | function v4(options, buf, offset) {
|
---|
5 | if (native.randomUUID && !buf && !options) {
|
---|
6 | return native.randomUUID();
|
---|
7 | }
|
---|
8 | options = options || {};
|
---|
9 | const rnds = options.random || (options.rng || rng)();
|
---|
10 | rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
---|
11 | rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
---|
12 | if (buf) {
|
---|
13 | offset = offset || 0;
|
---|
14 | for (let i = 0; i < 16; ++i) {
|
---|
15 | buf[offset + i] = rnds[i];
|
---|
16 | }
|
---|
17 | return buf;
|
---|
18 | }
|
---|
19 | return unsafeStringify(rnds);
|
---|
20 | }
|
---|
21 | export default v4;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.