Last change
on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
544 bytes
|
Line | |
---|
1 | import rng from './rng.js';
|
---|
2 | import stringify from './stringify.js';
|
---|
3 |
|
---|
4 | function v4(options, buf, offset) {
|
---|
5 | options = options || {};
|
---|
6 | var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
---|
7 |
|
---|
8 | rnds[6] = rnds[6] & 0x0f | 0x40;
|
---|
9 | rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
|
---|
10 |
|
---|
11 | if (buf) {
|
---|
12 | offset = offset || 0;
|
---|
13 |
|
---|
14 | for (var i = 0; i < 16; ++i) {
|
---|
15 | buf[offset + i] = rnds[i];
|
---|
16 | }
|
---|
17 |
|
---|
18 | return buf;
|
---|
19 | }
|
---|
20 |
|
---|
21 | return stringify(rnds);
|
---|
22 | }
|
---|
23 |
|
---|
24 | export default v4; |
---|
Note:
See
TracBrowser
for help on using the repository browser.