@powfix/core-js 0.19.2 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/cjs/browser/utils/UUID.js +2 -303
- package/dist/{node/cjs/browser → browser/cjs/shared}/utils/UUID.js +16 -10
- package/dist/browser/cjs/shared/utils/UUID.types.js +2 -0
- package/dist/browser/cjs/shared/utils/global/{fallbackIfEqual.js → fallbackIfMatch.js} +2 -2
- package/dist/browser/cjs/shared/utils/global/fallbackIfNull.js +2 -2
- package/dist/browser/cjs/shared/utils/global/fallbackIfNullish.js +9 -0
- package/dist/browser/cjs/shared/utils/global/fallbackIfUndefined.js +2 -2
- package/dist/browser/cjs/shared/utils/global/index.js +2 -1
- package/dist/browser/cjs/shared/utils/index.js +2 -0
- package/dist/browser/esm/browser/utils/UUID.mjs +2 -303
- package/dist/{node/esm/browser → browser/esm/shared}/utils/UUID.mjs +13 -7
- package/dist/browser/esm/shared/utils/UUID.types.mjs +1 -0
- package/dist/browser/esm/shared/utils/global/{fallbackIfEqual.mjs → fallbackIfMatch.mjs} +1 -1
- package/dist/browser/esm/shared/utils/global/fallbackIfNull.mjs +2 -2
- package/dist/browser/esm/shared/utils/global/fallbackIfNullish.mjs +6 -0
- package/dist/browser/esm/shared/utils/global/fallbackIfUndefined.mjs +2 -2
- package/dist/browser/esm/shared/utils/global/index.mjs +2 -1
- package/dist/browser/esm/shared/utils/index.mjs +2 -0
- package/dist/browser/types/browser/utils/UUID.d.ts +2 -143
- package/dist/{node/types/browser → browser/types/shared}/utils/UUID.d.ts +9 -8
- package/dist/browser/types/shared/utils/UUID.types.d.ts +2 -0
- package/dist/browser/types/shared/utils/global/fallbackIfMatch.d.ts +1 -0
- package/dist/browser/types/shared/utils/global/fallbackIfNullish.d.ts +1 -0
- package/dist/browser/types/shared/utils/global/index.d.ts +2 -1
- package/dist/browser/types/shared/utils/index.d.ts +1 -0
- package/dist/node/cjs/nodejs/utils/UUID.js +1 -1
- package/dist/node/cjs/nodejs/utils/sequelize-utils/SequelizeUtils.js +5 -6
- package/dist/node/cjs/shared/utils/UUID.js +314 -0
- package/dist/node/cjs/shared/utils/UUID.types.js +2 -0
- package/dist/node/cjs/shared/utils/global/{fallbackIfEqual.js → fallbackIfMatch.js} +2 -2
- package/dist/node/cjs/shared/utils/global/fallbackIfNull.js +2 -2
- package/dist/node/cjs/shared/utils/global/fallbackIfNullish.js +9 -0
- package/dist/node/cjs/shared/utils/global/fallbackIfUndefined.js +2 -2
- package/dist/node/cjs/shared/utils/global/index.js +2 -1
- package/dist/node/cjs/shared/utils/index.js +2 -0
- package/dist/node/esm/nodejs/utils/UUID.mjs +1 -1
- package/dist/node/esm/nodejs/utils/sequelize-utils/SequelizeUtils.mjs +5 -6
- package/dist/node/esm/shared/utils/UUID.mjs +310 -0
- package/dist/node/esm/shared/utils/UUID.types.mjs +1 -0
- package/dist/node/esm/shared/utils/global/{fallbackIfEqual.mjs → fallbackIfMatch.mjs} +1 -1
- package/dist/node/esm/shared/utils/global/fallbackIfNull.mjs +2 -2
- package/dist/node/esm/shared/utils/global/fallbackIfNullish.mjs +6 -0
- package/dist/node/esm/shared/utils/global/fallbackIfUndefined.mjs +2 -2
- package/dist/node/esm/shared/utils/global/index.mjs +2 -1
- package/dist/node/esm/shared/utils/index.mjs +2 -0
- package/dist/node/types/nodejs/utils/UUID.d.ts +1 -1
- package/dist/node/types/shared/utils/UUID.d.ts +145 -0
- package/dist/node/types/shared/utils/UUID.types.d.ts +2 -0
- package/dist/node/types/shared/utils/global/fallbackIfMatch.d.ts +1 -0
- package/dist/node/types/shared/utils/global/fallbackIfNullish.d.ts +1 -0
- package/dist/node/types/shared/utils/global/index.d.ts +2 -1
- package/dist/node/types/shared/utils/index.d.ts +1 -0
- package/package.json +1 -1
- package/dist/browser/types/shared/utils/global/fallbackIfEqual.d.ts +0 -1
- package/dist/node/types/shared/utils/global/fallbackIfEqual.d.ts +0 -1
|
@@ -1,308 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UUID = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
* Represents a UUID (Universally Unique Identifier) and provides various utility
|
|
7
|
-
* methods for validation, conversion, comparison and creation.
|
|
8
|
-
*/
|
|
9
|
-
class UUID {
|
|
10
|
-
/* --------------------------------------------------------------------
|
|
11
|
-
* Validation helpers
|
|
12
|
-
* -------------------------------------------------------------------- */
|
|
13
|
-
/**
|
|
14
|
-
* Checks if the supplied value is a valid hex representation of a UUID.
|
|
15
|
-
* @param hex - The string to validate.
|
|
16
|
-
* @returns true if the string matches {@link REGEX_HEX}.
|
|
17
|
-
*/
|
|
18
|
-
static isValidHex(hex) {
|
|
19
|
-
if (typeof hex !== 'string') {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
return UUID.REGEX_HEX.test(hex);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Checks if the supplied value is a valid RFC 4122 UUID string.
|
|
26
|
-
* @param str - The string to validate.
|
|
27
|
-
* @returns true if the string matches {@link REGEX_RFC4122}.
|
|
28
|
-
*/
|
|
29
|
-
static isValidString(str) {
|
|
30
|
-
if (typeof str !== 'string') {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
return UUID.REGEX_RFC4122.test(str);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Checks whether an ArrayBufferView contains exactly {@link BYTE_LENGTH} bytes.
|
|
37
|
-
* @param bytes - The view to check.
|
|
38
|
-
* @returns true if the byte length is correct.
|
|
39
|
-
*/
|
|
40
|
-
static isValidBytes(bytes) {
|
|
41
|
-
return bytes.byteLength === UUID.BYTE_LENGTH;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Generic validation that accepts either a string (hex or RFC 4122 format)
|
|
45
|
-
* or an ArrayBufferView containing the raw bytes.
|
|
46
|
-
* @param input - The value to validate.
|
|
47
|
-
* @returns true if the input is a valid representation of a UUID.
|
|
48
|
-
*/
|
|
49
|
-
static isValid(input) {
|
|
50
|
-
if (typeof input === 'string') {
|
|
51
|
-
const length = input.length;
|
|
52
|
-
switch (length) {
|
|
53
|
-
case UUID.STR_LENGTH:
|
|
54
|
-
// RFC 4122 uuid(string)
|
|
55
|
-
// 9e472052-a654-4693-9a8b-3ce57ada3d6c
|
|
56
|
-
return UUID.isValidString(input);
|
|
57
|
-
case UUID.HEX_STR_LENGTH:
|
|
58
|
-
// RFC 4122 uuid(string) without hyphens
|
|
59
|
-
// 9e472052a65446939a8b3ce57ada3d6c
|
|
60
|
-
return UUID.isValidHex(input);
|
|
61
|
-
default:
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
else if (ArrayBuffer.isView(input)) {
|
|
66
|
-
return UUID.isValidBytes(input);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/* --------------------------------------------------------------------
|
|
73
|
-
* Parsing / formatting helpers
|
|
74
|
-
* -------------------------------------------------------------------- */
|
|
75
|
-
/**
|
|
76
|
-
* Inserts hyphens into a 32‑character hex string to produce an RFC 4122 string.
|
|
77
|
-
* @param hex - The plain hexadecimal UUID.
|
|
78
|
-
* @returns The formatted RFC 4122 string.
|
|
79
|
-
*/
|
|
80
|
-
static formatHex(hex) {
|
|
81
|
-
if (hex.length !== UUID.HEX_STR_LENGTH) {
|
|
82
|
-
throw new Error(`hex length should be ${UUID.HEX_STR_LENGTH}`);
|
|
83
|
-
}
|
|
84
|
-
return hex.slice(0, 8) + '-' +
|
|
85
|
-
hex.slice(8, 12) + '-' +
|
|
86
|
-
hex.slice(12, 16) + '-' +
|
|
87
|
-
hex.slice(16, 20) + '-' +
|
|
88
|
-
hex.slice(20);
|
|
89
|
-
}
|
|
90
|
-
/** Removes all hyphens from a UUID string. */
|
|
91
|
-
static stripHyphens(str) {
|
|
92
|
-
return str.replace(/-/g, "");
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Converts a plain hexadecimal UUID into a Uint8Array.
|
|
96
|
-
* @param hex - The hex string to parse.
|
|
97
|
-
* @returns A Uint8Array containing the raw bytes.
|
|
98
|
-
*/
|
|
99
|
-
static parseHex(hex) {
|
|
100
|
-
if (hex.length !== UUID.HEX_STR_LENGTH) {
|
|
101
|
-
throw new Error(`Invalid hex string, length should be ${UUID.HEX_STR_LENGTH}`);
|
|
102
|
-
}
|
|
103
|
-
return shared_1.Uint8ArrayUtils.fromHex(hex);
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Parses an RFC 4122 string into a Uint8Array.
|
|
107
|
-
* @param str - The formatted UUID string.
|
|
108
|
-
* @returns A Uint8Array containing the raw bytes.
|
|
109
|
-
*/
|
|
110
|
-
static parseString(str) {
|
|
111
|
-
if (str.length !== UUID.STR_LENGTH) {
|
|
112
|
-
throw new Error(`Invalid UUID string, invalid character length should be ${UUID.STR_LENGTH}`);
|
|
113
|
-
}
|
|
114
|
-
if (!UUID.isValid(str)) {
|
|
115
|
-
throw new Error('Invalid UUID string, should be RFC 4122 format');
|
|
116
|
-
}
|
|
117
|
-
const hex = UUID.stripHyphens(str);
|
|
118
|
-
if (hex.length !== UUID.HEX_STR_LENGTH) {
|
|
119
|
-
throw new Error('Invalid UUID string, invalid character length after strip hyphens');
|
|
120
|
-
}
|
|
121
|
-
return shared_1.Uint8ArrayUtils.fromHex(hex);
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Parses an ArrayBufferView into a Uint8Array ensuring the correct byte length.
|
|
125
|
-
* @param bytes - The view to parse.
|
|
126
|
-
* @returns A Uint8Array containing the raw bytes.
|
|
127
|
-
*/
|
|
128
|
-
static parseBytes(bytes) {
|
|
129
|
-
const view = new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
130
|
-
if (view.length !== UUID.BYTE_LENGTH) {
|
|
131
|
-
throw new Error(`Expected ${UUID.BYTE_LENGTH} bytes`);
|
|
132
|
-
}
|
|
133
|
-
return new Uint8Array(view);
|
|
134
|
-
}
|
|
135
|
-
/* --------------------------------------------------------------------
|
|
136
|
-
* Factory methods
|
|
137
|
-
* -------------------------------------------------------------------- */
|
|
138
|
-
/**
|
|
139
|
-
* Creates a UUID instance from a plain hexadecimal string.
|
|
140
|
-
* @param hex - The hex representation of the UUID.
|
|
141
|
-
* @returns A new {@link UUID} object.
|
|
142
|
-
*/
|
|
143
|
-
static fromHex(hex) {
|
|
144
|
-
return new UUID(UUID.parseHex(hex));
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Creates a UUID instance from an RFC 4122 formatted string.
|
|
148
|
-
* @param str - The UUID string with hyphens.
|
|
149
|
-
* @returns A new {@link UUID} object.
|
|
150
|
-
*/
|
|
151
|
-
static fromString(str) {
|
|
152
|
-
return new UUID(UUID.parseString(str));
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Creates a UUID instance from raw bytes.
|
|
156
|
-
* @param bytes - An ArrayBufferView containing 16 bytes.
|
|
157
|
-
* @returns A new {@link UUID} object.
|
|
158
|
-
*/
|
|
159
|
-
static fromBytes(bytes) {
|
|
160
|
-
return new UUID(UUID.parseBytes(bytes));
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Parses any supported input (string or bytes) and returns the raw byte array.
|
|
164
|
-
* @param input - The value to parse.
|
|
165
|
-
* @returns A Uint8Array of length {@link BYTE_LENGTH}.
|
|
166
|
-
*/
|
|
167
|
-
static parse(input) {
|
|
168
|
-
if (typeof input === 'string') {
|
|
169
|
-
const length = input.length;
|
|
170
|
-
switch (length) {
|
|
171
|
-
case UUID.STR_LENGTH:
|
|
172
|
-
// RFC 4122 uuid(string)
|
|
173
|
-
return UUID.parseString(input);
|
|
174
|
-
case UUID.HEX_STR_LENGTH:
|
|
175
|
-
// RFC 4122 uuid(string) without hyphens
|
|
176
|
-
return UUID.parseHex(input);
|
|
177
|
-
default:
|
|
178
|
-
throw new Error(`Invalid input string, length should be ${UUID.STR_LENGTH} or ${UUID.HEX_STR_LENGTH}`);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
else if (ArrayBuffer.isView(input)) {
|
|
182
|
-
return UUID.parseBytes(input);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
throw new Error("Invalid input, Expected string or ArrayBufferView");
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Creates a UUID from any supported input type.
|
|
190
|
-
* @param input - The value to parse.
|
|
191
|
-
* @returns A new {@link UUID} object.
|
|
192
|
-
*/
|
|
193
|
-
static from(input) {
|
|
194
|
-
return UUID.fromBytes(UUID.parse(input));
|
|
195
|
-
}
|
|
196
|
-
/** Returns the nil (all zero) UUID. */
|
|
197
|
-
static nil() {
|
|
198
|
-
return UUID.fromBytes(new Uint8Array(UUID.BYTE_LENGTH));
|
|
199
|
-
}
|
|
200
|
-
/** Returns a UUID consisting of all 0xFF bytes. */
|
|
201
|
-
static max() {
|
|
202
|
-
return UUID.fromBytes((new Uint8Array(UUID.BYTE_LENGTH)).fill(0xFF));
|
|
203
|
-
}
|
|
204
|
-
/* --------------------------------------------------------------------
|
|
205
|
-
* Equality / comparison
|
|
206
|
-
* -------------------------------------------------------------------- */
|
|
207
|
-
/**
|
|
208
|
-
* Compares multiple UUIDs for strict equality.
|
|
209
|
-
* @param uuids - The UUIDs to compare (at least two required).
|
|
210
|
-
* @returns true if all provided UUIDs are identical.
|
|
211
|
-
*/
|
|
212
|
-
static equals(...uuids) {
|
|
213
|
-
const n = uuids.length;
|
|
214
|
-
if (n < 2) {
|
|
215
|
-
throw new Error('At least two UUIDs required for comparison');
|
|
216
|
-
}
|
|
217
|
-
const ref = uuids[0].bytes;
|
|
218
|
-
for (let i = 1; i < n; ++i) {
|
|
219
|
-
const b = uuids[i].bytes;
|
|
220
|
-
for (let j = 0; j < UUID.BYTE_LENGTH; ++j) {
|
|
221
|
-
if (ref[j] !== b[j])
|
|
222
|
-
return false;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return true;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Lexicographically compares two UUIDs.
|
|
229
|
-
* @param uuid1 - The first UUID.
|
|
230
|
-
* @param uuid2 - The second UUID.
|
|
231
|
-
* @returns -1 if uuid1 < uuid2, 1 if uuid1 > uuid2, 0 otherwise.
|
|
232
|
-
*/
|
|
233
|
-
static compare(uuid1, uuid2) {
|
|
234
|
-
const a = uuid1.bytes;
|
|
235
|
-
const b = uuid2.bytes;
|
|
236
|
-
for (let i = 0; i < UUID.BYTE_LENGTH; i++) {
|
|
237
|
-
if (a[i] !== b[i])
|
|
238
|
-
return a[i] < b[i] ? -1 : 1;
|
|
239
|
-
}
|
|
240
|
-
return 0;
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Constructs a new {@link UUID} instance from any supported input type.
|
|
244
|
-
* @param input - The value to parse (string or ArrayBufferView).
|
|
245
|
-
*/
|
|
246
|
-
constructor(input) {
|
|
247
|
-
this.bytes = UUID.parse(input);
|
|
248
|
-
}
|
|
249
|
-
/** Instance wrapper for {@link equals}. */
|
|
250
|
-
equals(...uuids) {
|
|
251
|
-
return UUID.equals(this, ...uuids);
|
|
252
|
-
}
|
|
253
|
-
/** Instance wrapper for {@link compare}. */
|
|
254
|
-
compare(other) {
|
|
255
|
-
return UUID.compare(this, other);
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Returns the RFC 4122 string representation of this UUID.
|
|
259
|
-
* @returns The formatted UUID string.
|
|
260
|
-
*/
|
|
261
|
-
toString() {
|
|
262
|
-
if (this._str != null) {
|
|
263
|
-
return this._str;
|
|
264
|
-
}
|
|
265
|
-
const hex = this.toHex();
|
|
266
|
-
this._str = UUID.formatHex(hex);
|
|
267
|
-
return this._str;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Returns the plain hexadecimal representation of this UUID.
|
|
271
|
-
* @returns A 32‑character hex string.
|
|
272
|
-
*/
|
|
273
|
-
toHex() {
|
|
274
|
-
if (this._hex != null) {
|
|
275
|
-
return this._hex;
|
|
276
|
-
}
|
|
277
|
-
this._hex = shared_1.Uint8ArrayUtils.toHex(this.bytes);
|
|
278
|
-
return this._hex;
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Returns a copy of the raw byte array.
|
|
282
|
-
* @returns A new Uint8Array containing the UUID bytes.
|
|
283
|
-
*/
|
|
284
|
-
toBytes() {
|
|
285
|
-
return new Uint8Array(this.bytes);
|
|
286
|
-
}
|
|
287
|
-
/** JSON serialization helper – returns the RFC 4122 string. */
|
|
288
|
-
toJSON() {
|
|
289
|
-
return this.toString();
|
|
290
|
-
}
|
|
4
|
+
const UUID_1 = require("../../shared/utils/UUID");
|
|
5
|
+
class UUID extends UUID_1.UUID {
|
|
291
6
|
}
|
|
292
7
|
exports.UUID = UUID;
|
|
293
|
-
/* --------------------------------------------------------------------
|
|
294
|
-
* Regular expressions used to validate UUIDs in different string forms
|
|
295
|
-
* -------------------------------------------------------------------- */
|
|
296
|
-
/** Matches a 32‑character hexadecimal representation of a UUID without hyphens. */
|
|
297
|
-
UUID.REGEX_HEX = /^[0-9a-fA-F]{8}[0-9a-fA-F]{4}[1-5][0-9a-fA-F]{3}[89abAB][0-9a-fA-F]{3}[0-9a-fA-F]{12}$/;
|
|
298
|
-
/** Matches the RFC 4122 canonical UUID format with hyphens. */
|
|
299
|
-
UUID.REGEX_RFC4122 = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
|
|
300
|
-
/* --------------------------------------------------------------------
|
|
301
|
-
* Constant lengths used throughout the class
|
|
302
|
-
* -------------------------------------------------------------------- */
|
|
303
|
-
/** Number of bytes that represent a UUID. */
|
|
304
|
-
UUID.BYTE_LENGTH = 16;
|
|
305
|
-
/** Total length of an RFC 4122 UUID string (including hyphens). */
|
|
306
|
-
UUID.STR_LENGTH = 36;
|
|
307
|
-
/** Length of a UUID represented as a plain hexadecimal string. */
|
|
308
|
-
UUID.HEX_STR_LENGTH = 32;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UUID = void 0;
|
|
4
|
-
const
|
|
4
|
+
const index_1 = require("../index");
|
|
5
5
|
/**
|
|
6
6
|
* Represents a UUID (Universally Unique Identifier) and provides various utility
|
|
7
7
|
* methods for validation, conversion, comparison and creation.
|
|
@@ -62,6 +62,9 @@ class UUID {
|
|
|
62
62
|
return false;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
+
else if (input instanceof UUID) {
|
|
66
|
+
return UUID.isValidBytes(input.bytes);
|
|
67
|
+
}
|
|
65
68
|
else if (ArrayBuffer.isView(input)) {
|
|
66
69
|
return UUID.isValidBytes(input);
|
|
67
70
|
}
|
|
@@ -100,7 +103,7 @@ class UUID {
|
|
|
100
103
|
if (hex.length !== UUID.HEX_STR_LENGTH) {
|
|
101
104
|
throw new Error(`Invalid hex string, length should be ${UUID.HEX_STR_LENGTH}`);
|
|
102
105
|
}
|
|
103
|
-
return
|
|
106
|
+
return index_1.Uint8ArrayUtils.fromHex(hex);
|
|
104
107
|
}
|
|
105
108
|
/**
|
|
106
109
|
* Parses an RFC 4122 string into a Uint8Array.
|
|
@@ -118,7 +121,7 @@ class UUID {
|
|
|
118
121
|
if (hex.length !== UUID.HEX_STR_LENGTH) {
|
|
119
122
|
throw new Error('Invalid UUID string, invalid character length after strip hyphens');
|
|
120
123
|
}
|
|
121
|
-
return
|
|
124
|
+
return index_1.Uint8ArrayUtils.fromHex(hex);
|
|
122
125
|
}
|
|
123
126
|
/**
|
|
124
127
|
* Parses an ArrayBufferView into a Uint8Array ensuring the correct byte length.
|
|
@@ -141,7 +144,7 @@ class UUID {
|
|
|
141
144
|
* @returns A new {@link UUID} object.
|
|
142
145
|
*/
|
|
143
146
|
static fromHex(hex) {
|
|
144
|
-
return new
|
|
147
|
+
return new this(UUID.parseHex(hex));
|
|
145
148
|
}
|
|
146
149
|
/**
|
|
147
150
|
* Creates a UUID instance from an RFC 4122 formatted string.
|
|
@@ -149,7 +152,7 @@ class UUID {
|
|
|
149
152
|
* @returns A new {@link UUID} object.
|
|
150
153
|
*/
|
|
151
154
|
static fromString(str) {
|
|
152
|
-
return new
|
|
155
|
+
return new this(UUID.parseString(str));
|
|
153
156
|
}
|
|
154
157
|
/**
|
|
155
158
|
* Creates a UUID instance from raw bytes.
|
|
@@ -157,7 +160,7 @@ class UUID {
|
|
|
157
160
|
* @returns A new {@link UUID} object.
|
|
158
161
|
*/
|
|
159
162
|
static fromBytes(bytes) {
|
|
160
|
-
return new
|
|
163
|
+
return new this(UUID.parseBytes(bytes));
|
|
161
164
|
}
|
|
162
165
|
/**
|
|
163
166
|
* Parses any supported input (string or bytes) and returns the raw byte array.
|
|
@@ -178,6 +181,9 @@ class UUID {
|
|
|
178
181
|
throw new Error(`Invalid input string, length should be ${UUID.STR_LENGTH} or ${UUID.HEX_STR_LENGTH}`);
|
|
179
182
|
}
|
|
180
183
|
}
|
|
184
|
+
else if (input instanceof UUID) {
|
|
185
|
+
return input.toBytes();
|
|
186
|
+
}
|
|
181
187
|
else if (ArrayBuffer.isView(input)) {
|
|
182
188
|
return UUID.parseBytes(input);
|
|
183
189
|
}
|
|
@@ -191,15 +197,15 @@ class UUID {
|
|
|
191
197
|
* @returns A new {@link UUID} object.
|
|
192
198
|
*/
|
|
193
199
|
static from(input) {
|
|
194
|
-
return
|
|
200
|
+
return this.fromBytes(UUID.parse(input));
|
|
195
201
|
}
|
|
196
202
|
/** Returns the nil (all zero) UUID. */
|
|
197
203
|
static nil() {
|
|
198
|
-
return
|
|
204
|
+
return this.fromBytes(new Uint8Array(UUID.BYTE_LENGTH));
|
|
199
205
|
}
|
|
200
206
|
/** Returns a UUID consisting of all 0xFF bytes. */
|
|
201
207
|
static max() {
|
|
202
|
-
return
|
|
208
|
+
return this.fromBytes((new Uint8Array(UUID.BYTE_LENGTH)).fill(0xFF));
|
|
203
209
|
}
|
|
204
210
|
/* --------------------------------------------------------------------
|
|
205
211
|
* Equality / comparison
|
|
@@ -274,7 +280,7 @@ class UUID {
|
|
|
274
280
|
if (this._hex != null) {
|
|
275
281
|
return this._hex;
|
|
276
282
|
}
|
|
277
|
-
this._hex =
|
|
283
|
+
this._hex = index_1.Uint8ArrayUtils.toHex(this.bytes);
|
|
278
284
|
return this._hex;
|
|
279
285
|
}
|
|
280
286
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
function
|
|
3
|
+
exports.fallbackIfMatch = fallbackIfMatch;
|
|
4
|
+
function fallbackIfMatch(value, condition, fallback) {
|
|
5
5
|
if (typeof value === typeof condition && value === condition) {
|
|
6
6
|
return fallback;
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fallbackIfNull = fallbackIfNull;
|
|
4
|
-
const
|
|
4
|
+
const fallbackIfMatch_1 = require("./fallbackIfMatch");
|
|
5
5
|
function fallbackIfNull(value, fallback) {
|
|
6
|
-
return (0,
|
|
6
|
+
return (0, fallbackIfMatch_1.fallbackIfMatch)(value, null, fallback);
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fallbackIfUndefined = fallbackIfUndefined;
|
|
4
|
-
const
|
|
4
|
+
const fallbackIfMatch_1 = require("./fallbackIfMatch");
|
|
5
5
|
function fallbackIfUndefined(value, fallback) {
|
|
6
|
-
return (0,
|
|
6
|
+
return (0, fallbackIfMatch_1.fallbackIfMatch)(value, undefined, fallback);
|
|
7
7
|
}
|
|
@@ -21,8 +21,9 @@ __exportStar(require("./btoa"), exports);
|
|
|
21
21
|
__exportStar(require("./castArray"), exports);
|
|
22
22
|
__exportStar(require("./circularDistance"), exports);
|
|
23
23
|
__exportStar(require("./sleep"), exports);
|
|
24
|
-
__exportStar(require("./
|
|
24
|
+
__exportStar(require("./fallbackIfMatch"), exports);
|
|
25
25
|
__exportStar(require("./fallbackIfNull"), exports);
|
|
26
|
+
__exportStar(require("./fallbackIfNullish"), exports);
|
|
26
27
|
__exportStar(require("./fallbackIfUndefined"), exports);
|
|
27
28
|
__exportStar(require("./firstNonNullish"), exports);
|
|
28
29
|
__exportStar(require("./flat"), exports);
|
|
@@ -19,6 +19,8 @@ __exportStar(require("./ArrayUtils"), exports);
|
|
|
19
19
|
__exportStar(require("./AxiosUtils"), exports);
|
|
20
20
|
__exportStar(require("./StringUtils"), exports);
|
|
21
21
|
__exportStar(require("./Uint8ArrayUtils"), exports);
|
|
22
|
+
// export * from './UUID';
|
|
23
|
+
__exportStar(require("./UUID.types"), exports);
|
|
22
24
|
__exportStar(require("./UuidUtils"), exports);
|
|
23
25
|
__exportStar(require("./BooleanUtils"), exports);
|
|
24
26
|
__exportStar(require("./Calc"), exports);
|