@powfix/core-js 0.19.2 → 0.20.0

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