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;
17 return this.asHex() === other.asHex();
20 class V4UUID extends ValueUUID {
42 V4UUID._oneOf(V4UUID._timeHighBits),
61 static _oneOf(array) {
62 return array[Math.floor(array.length * Math.random())];
65 return V4UUID._oneOf(V4UUID._chars);
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'];
71 * An empty UUID that contains only zeros.
73 exports.empty = new ValueUUID('00000000-0000-0000-0000-000000000000');
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);
82 exports.isUUID = isUUID;
84 * Parses a UUID that is of the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
85 * @param value A uuid string.
87 function parse(value) {
89 throw new Error('invalid uuid');
91 return new ValueUUID(value);
93 exports.parse = parse;
94 function generateUuid() {
97 exports.generateUuid = generateUuid;
98 //# sourceMappingURL=uuid.js.map