Last change
on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.6 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = void 0;
|
---|
7 |
|
---|
8 | var _validate = _interopRequireDefault(require("./validate.js"));
|
---|
9 |
|
---|
10 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Convert array of 16 byte values to UUID string format of the form:
|
---|
14 | * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
---|
15 | */
|
---|
16 | const byteToHex = [];
|
---|
17 |
|
---|
18 | for (let i = 0; i < 256; ++i) {
|
---|
19 | byteToHex.push((i + 0x100).toString(16).substr(1));
|
---|
20 | }
|
---|
21 |
|
---|
22 | function stringify(arr, offset = 0) {
|
---|
23 | // Note: Be careful editing this code! It's been tuned for performance
|
---|
24 | // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
|
---|
25 | const uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
|
---|
26 | // of the following:
|
---|
27 | // - One or more input array values don't map to a hex octet (leading to
|
---|
28 | // "undefined" in the uuid)
|
---|
29 | // - Invalid input values for the RFC `version` or `variant` fields
|
---|
30 |
|
---|
31 | if (!(0, _validate.default)(uuid)) {
|
---|
32 | throw TypeError('Stringified UUID is invalid');
|
---|
33 | }
|
---|
34 |
|
---|
35 | return uuid;
|
---|
36 | }
|
---|
37 |
|
---|
38 | var _default = stringify;
|
---|
39 | exports.default = _default; |
---|
Note:
See
TracBrowser
for help on using the repository browser.