Last change
on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | import validate from './validate.js';
|
---|
2 |
|
---|
3 | function parse(uuid) {
|
---|
4 | if (!validate(uuid)) {
|
---|
5 | throw TypeError('Invalid UUID');
|
---|
6 | }
|
---|
7 |
|
---|
8 | let v;
|
---|
9 | const arr = new Uint8Array(16); // Parse ########-....-....-....-............
|
---|
10 |
|
---|
11 | arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
|
---|
12 | arr[1] = v >>> 16 & 0xff;
|
---|
13 | arr[2] = v >>> 8 & 0xff;
|
---|
14 | arr[3] = v & 0xff; // Parse ........-####-....-....-............
|
---|
15 |
|
---|
16 | arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
|
---|
17 | arr[5] = v & 0xff; // Parse ........-....-####-....-............
|
---|
18 |
|
---|
19 | arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
|
---|
20 | arr[7] = v & 0xff; // Parse ........-....-....-####-............
|
---|
21 |
|
---|
22 | arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
|
---|
23 | arr[9] = v & 0xff; // Parse ........-....-....-....-############
|
---|
24 | // (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
|
---|
25 |
|
---|
26 | arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000 & 0xff;
|
---|
27 | arr[11] = v / 0x100000000 & 0xff;
|
---|
28 | arr[12] = v >>> 24 & 0xff;
|
---|
29 | arr[13] = v >>> 16 & 0xff;
|
---|
30 | arr[14] = v >>> 8 & 0xff;
|
---|
31 | arr[15] = v & 0xff;
|
---|
32 | return arr;
|
---|
33 | }
|
---|
34 |
|
---|
35 | export default parse; |
---|
Note:
See
TracBrowser
for help on using the repository browser.