massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-json / node_modules / vscode-languageserver / lib / common / utils / uuid.js
1 "use strict";
2 /*---------------------------------------------------------------------------------------------
3  *  Copyright (c) Microsoft Corporation. All rights reserved.
4  *  Licensed under the MIT License. See License.txt in the project root for license information.
5  *--------------------------------------------------------------------------------------------*/
6 Object.defineProperty(exports, "__esModule", { value: true });
7 exports.generateUuid = exports.parse = exports.isUUID = exports.v4 = exports.empty = void 0;
8 class ValueUUID {
9     constructor(_value) {
10         this._value = _value;
11         // empty
12     }
13     asHex() {
14         return this._value;
15     }
16     equals(other) {
17         return this.asHex() === other.asHex();
18     }
19 }
20 class V4UUID extends ValueUUID {
21     constructor() {
22         super([
23             V4UUID._randomHex(),
24             V4UUID._randomHex(),
25             V4UUID._randomHex(),
26             V4UUID._randomHex(),
27             V4UUID._randomHex(),
28             V4UUID._randomHex(),
29             V4UUID._randomHex(),
30             V4UUID._randomHex(),
31             '-',
32             V4UUID._randomHex(),
33             V4UUID._randomHex(),
34             V4UUID._randomHex(),
35             V4UUID._randomHex(),
36             '-',
37             '4',
38             V4UUID._randomHex(),
39             V4UUID._randomHex(),
40             V4UUID._randomHex(),
41             '-',
42             V4UUID._oneOf(V4UUID._timeHighBits),
43             V4UUID._randomHex(),
44             V4UUID._randomHex(),
45             V4UUID._randomHex(),
46             '-',
47             V4UUID._randomHex(),
48             V4UUID._randomHex(),
49             V4UUID._randomHex(),
50             V4UUID._randomHex(),
51             V4UUID._randomHex(),
52             V4UUID._randomHex(),
53             V4UUID._randomHex(),
54             V4UUID._randomHex(),
55             V4UUID._randomHex(),
56             V4UUID._randomHex(),
57             V4UUID._randomHex(),
58             V4UUID._randomHex(),
59         ].join(''));
60     }
61     static _oneOf(array) {
62         return array[Math.floor(array.length * Math.random())];
63     }
64     static _randomHex() {
65         return V4UUID._oneOf(V4UUID._chars);
66     }
67 }
68 V4UUID._chars = ['0', '1', '2', '3', '4', '5', '6', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
69 V4UUID._timeHighBits = ['8', '9', 'a', 'b'];
70 /**
71  * An empty UUID that contains only zeros.
72  */
73 exports.empty = new ValueUUID('00000000-0000-0000-0000-000000000000');
74 function v4() {
75     return new V4UUID();
76 }
77 exports.v4 = v4;
78 const _UUIDPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
79 function isUUID(value) {
80     return _UUIDPattern.test(value);
81 }
82 exports.isUUID = isUUID;
83 /**
84  * Parses a UUID that is of the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
85  * @param value A uuid string.
86  */
87 function parse(value) {
88     if (!isUUID(value)) {
89         throw new Error('invalid uuid');
90     }
91     return new ValueUUID(value);
92 }
93 exports.parse = parse;
94 function generateUuid() {
95     return v4().asHex();
96 }
97 exports.generateUuid = generateUuid;
98 //# sourceMappingURL=uuid.js.map