@journium/react 1.1.2 → 1.1.3
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/hooks.d.ts.map +1 -1
- package/dist/index.cjs +16 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +16 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,gBAId,MAAM,eAAe,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAOvD,CAAC;AAEF,eAAO,MAAM,WAAW,qBAIP,MAAM,eAAe,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAO5D,CAAC;AAEF,eAAO,MAAM,QAAQ,kBAQpB,CAAC;AAEF,eAAO,MAAM,gBAAgB,sBAIX,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAOxC,CAAC;AAEF,eAAO,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,gBAId,MAAM,eAAe,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAOvD,CAAC;AAEF,eAAO,MAAM,WAAW,qBAIP,MAAM,eAAe,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAO5D,CAAC;AAEF,eAAO,MAAM,QAAQ,kBAQpB,CAAC;AAEF,eAAO,MAAM,gBAAgB,sBAIX,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAOxC,CAAC;AAEF,eAAO,MAAM,oBAAoB,kBACjB,KAAK,CAAC,cAAc,eACrB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAOrC,CAAC;AAEF,eAAO,MAAM,cAAc;;;CAgB1B,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,7 @@ var React = require('react');
|
|
|
5
5
|
/**
|
|
6
6
|
* uuidv7: A JavaScript implementation of UUID version 7
|
|
7
7
|
*
|
|
8
|
-
* Copyright 2021-
|
|
8
|
+
* Copyright 2021-2025 LiosK
|
|
9
9
|
*
|
|
10
10
|
* @license Apache-2.0
|
|
11
11
|
* @packageDocumentation
|
|
@@ -234,7 +234,10 @@ class V7Generator {
|
|
|
234
234
|
* number generator should be cryptographically strong and securely seeded.
|
|
235
235
|
*/
|
|
236
236
|
constructor(randomNumberGenerator) {
|
|
237
|
-
|
|
237
|
+
/**
|
|
238
|
+
* Biased by one to distinguish zero (uninitialized) and zero (UNIX epoch).
|
|
239
|
+
*/
|
|
240
|
+
this.timestamp_biased = 0;
|
|
238
241
|
this.counter = 0;
|
|
239
242
|
this.random = randomNumberGenerator !== null && randomNumberGenerator !== void 0 ? randomNumberGenerator : getDefaultRandom();
|
|
240
243
|
}
|
|
@@ -280,13 +283,13 @@ class V7Generator {
|
|
|
280
283
|
*
|
|
281
284
|
* @param rollbackAllowance - The amount of `unixTsMs` rollback that is
|
|
282
285
|
* considered significant. A suggested value is `10_000` (milliseconds).
|
|
283
|
-
* @throws RangeError if `unixTsMs` is not a 48-bit
|
|
286
|
+
* @throws RangeError if `unixTsMs` is not a 48-bit unsigned integer.
|
|
284
287
|
*/
|
|
285
288
|
generateOrResetCore(unixTsMs, rollbackAllowance) {
|
|
286
289
|
let value = this.generateOrAbortCore(unixTsMs, rollbackAllowance);
|
|
287
290
|
if (value === undefined) {
|
|
288
291
|
// reset state and resume
|
|
289
|
-
this.
|
|
292
|
+
this.timestamp_biased = 0;
|
|
290
293
|
value = this.generateOrAbortCore(unixTsMs, rollbackAllowance);
|
|
291
294
|
}
|
|
292
295
|
return value;
|
|
@@ -300,28 +303,29 @@ class V7Generator {
|
|
|
300
303
|
*
|
|
301
304
|
* @param rollbackAllowance - The amount of `unixTsMs` rollback that is
|
|
302
305
|
* considered significant. A suggested value is `10_000` (milliseconds).
|
|
303
|
-
* @throws RangeError if `unixTsMs` is not a 48-bit
|
|
306
|
+
* @throws RangeError if `unixTsMs` is not a 48-bit unsigned integer.
|
|
304
307
|
*/
|
|
305
308
|
generateOrAbortCore(unixTsMs, rollbackAllowance) {
|
|
306
309
|
const MAX_COUNTER = 4398046511103;
|
|
307
310
|
if (!Number.isInteger(unixTsMs) ||
|
|
308
|
-
unixTsMs <
|
|
311
|
+
unixTsMs < 0 ||
|
|
309
312
|
unixTsMs > 281474976710655) {
|
|
310
|
-
throw new RangeError("`unixTsMs` must be a 48-bit
|
|
313
|
+
throw new RangeError("`unixTsMs` must be a 48-bit unsigned integer");
|
|
311
314
|
}
|
|
312
315
|
else if (rollbackAllowance < 0 || rollbackAllowance > 281474976710655) {
|
|
313
316
|
throw new RangeError("`rollbackAllowance` out of reasonable range");
|
|
314
317
|
}
|
|
315
|
-
|
|
316
|
-
|
|
318
|
+
unixTsMs++;
|
|
319
|
+
if (unixTsMs > this.timestamp_biased) {
|
|
320
|
+
this.timestamp_biased = unixTsMs;
|
|
317
321
|
this.resetCounter();
|
|
318
322
|
}
|
|
319
|
-
else if (unixTsMs + rollbackAllowance >= this.
|
|
323
|
+
else if (unixTsMs + rollbackAllowance >= this.timestamp_biased) {
|
|
320
324
|
// go on with previous timestamp if new one is not much smaller
|
|
321
325
|
this.counter++;
|
|
322
326
|
if (this.counter > MAX_COUNTER) {
|
|
323
327
|
// increment timestamp at counter overflow
|
|
324
|
-
this.
|
|
328
|
+
this.timestamp_biased++;
|
|
325
329
|
this.resetCounter();
|
|
326
330
|
}
|
|
327
331
|
}
|
|
@@ -329,7 +333,7 @@ class V7Generator {
|
|
|
329
333
|
// abort if clock went backwards to unbearable extent
|
|
330
334
|
return undefined;
|
|
331
335
|
}
|
|
332
|
-
return UUID.fromFieldsV7(this.
|
|
336
|
+
return UUID.fromFieldsV7(this.timestamp_biased - 1, Math.trunc(this.counter / 2 ** 30), this.counter & (2 ** 30 - 1), this.random.nextUint32());
|
|
333
337
|
}
|
|
334
338
|
/** Initializes the counter at a 42-bit random integer. */
|
|
335
339
|
resetCounter() {
|