@sv443-network/userutils 10.1.0 → 10.2.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.
- package/CHANGELOG.md +9 -0
- package/README.md +2 -0
- package/dist/UserUtils.cjs +50 -12
- package/dist/UserUtils.mjs +50 -12
- package/dist/UserUtils.umd.js +50 -12
- package/dist/lib/consts.d.ts +1 -6
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @sv443-network/userutils
|
|
2
2
|
|
|
3
|
+
## 10.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 1f32c2e: Updated CoreUtils to v3.4.0, which includes the following changes:
|
|
8
|
+
- `Debouncer` and `debounce` now have an extra parameter of type `NanoEmitterOptions` to customize the underlying `NanoEmitter` instance.
|
|
9
|
+
- Added function `createRecurringTask()` as a "batteries included" alternative to `setImmediateTimeoutLoop()` and `setImmediateInterval()`, with more ways to control task execution and aborting.
|
|
10
|
+
- Fixed internal event emission problems in `Debouncer`
|
|
11
|
+
|
|
3
12
|
## 10.1.0
|
|
4
13
|
|
|
5
14
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -108,6 +108,8 @@ View the documentation of previous major versions:
|
|
|
108
108
|
- 🟧 [`class DataStore`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#class-datastore) - The main class for the data store
|
|
109
109
|
- 🔷 [`type DataStoreOptions`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#type-datastoreoptions) - Options for the data store
|
|
110
110
|
- 🔷 [`type DataMigrationsDict`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#type-datamigrationsdict) - Dictionary of data migration functions
|
|
111
|
+
- 🔷 [`type DataStoreData`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#type-datastoredata) - The type of the serializable data
|
|
112
|
+
- 🔷 [`type DataStoreEventMap`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#type-datastoreeventmap) - Map of DataStore events
|
|
111
113
|
- 🟧 [`class DataStoreSerializer`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#class-datastoreserializer) - Serializes and deserializes data for multiple DataStore instances
|
|
112
114
|
- 🔷 [`type DataStoreSerializerOptions`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#type-datastoreserializeroptions) - Options for the DataStoreSerializer
|
|
113
115
|
- 🔷 [`type LoadStoresDataResult`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#type-loadstoresdataresult) - Result of calling [`loadStoresData()`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#datastoreserializer-loadstoresdata)
|
package/dist/UserUtils.cjs
CHANGED
|
@@ -64,6 +64,7 @@ __export(lib_exports, {
|
|
|
64
64
|
consumeGen: () => consumeGen,
|
|
65
65
|
consumeStringGen: () => consumeStringGen,
|
|
66
66
|
createProgressBar: () => createProgressBar,
|
|
67
|
+
createRecurringTask: () => createRecurringTask,
|
|
67
68
|
currentDialogId: () => currentDialogId,
|
|
68
69
|
darkenColor: () => darkenColor,
|
|
69
70
|
debounce: () => debounce,
|
|
@@ -117,7 +118,7 @@ __export(lib_exports, {
|
|
|
117
118
|
});
|
|
118
119
|
module.exports = __toCommonJS(lib_exports);
|
|
119
120
|
|
|
120
|
-
// node_modules/.pnpm/@sv443-network+coreutils@3.
|
|
121
|
+
// node_modules/.pnpm/@sv443-network+coreutils@3.4.0/node_modules/@sv443-network/coreutils/dist/CoreUtils.mjs
|
|
121
122
|
function bitSetHas(bitSet, checkVal) {
|
|
122
123
|
return (bitSet & checkVal) === checkVal;
|
|
123
124
|
}
|
|
@@ -480,12 +481,46 @@ function getCallStack(asArray, lines = Infinity) {
|
|
|
480
481
|
if (typeof lines !== "number" || isNaN(lines) || lines < 0)
|
|
481
482
|
throw new TypeError("lines parameter must be a non-negative number");
|
|
482
483
|
try {
|
|
483
|
-
throw new
|
|
484
|
+
throw new CustomError("GetCallStack", "Capturing a stack trace with CoreUtils.getCallStack(). If you see this anywhere, you can safely ignore it.");
|
|
484
485
|
} catch (err) {
|
|
485
486
|
const stack = ((_a = err.stack) != null ? _a : "").split("\n").map((line) => line.trim()).slice(2, lines + 2);
|
|
486
487
|
return asArray !== false ? stack : stack.join("\n");
|
|
487
488
|
}
|
|
488
489
|
}
|
|
490
|
+
function createRecurringTask(options) {
|
|
491
|
+
var _a;
|
|
492
|
+
let iterations = 0;
|
|
493
|
+
let aborted = false;
|
|
494
|
+
(_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
|
|
495
|
+
aborted = true;
|
|
496
|
+
}, { once: true });
|
|
497
|
+
const runRecurringTask = async (initial = false) => {
|
|
498
|
+
var _a3, _b;
|
|
499
|
+
var _a2;
|
|
500
|
+
if (aborted)
|
|
501
|
+
return;
|
|
502
|
+
try {
|
|
503
|
+
if (((_a3 = options.immediate) != null ? _a3 : true) || !initial) {
|
|
504
|
+
iterations++;
|
|
505
|
+
if ((_b = await ((_a2 = options.condition) == null ? void 0 : _a2.call(options, iterations - 1))) != null ? _b : true) {
|
|
506
|
+
const val = await options.task(iterations - 1);
|
|
507
|
+
if (options.onSuccess)
|
|
508
|
+
await options.onSuccess(val, iterations - 1);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
} catch (err) {
|
|
512
|
+
if (options.onError)
|
|
513
|
+
await options.onError(err, iterations - 1);
|
|
514
|
+
if (options.abortOnError)
|
|
515
|
+
aborted = true;
|
|
516
|
+
if (!options.onError && !options.abortOnError)
|
|
517
|
+
throw err;
|
|
518
|
+
}
|
|
519
|
+
if (!aborted && (typeof options.maxIterations !== "number" || iterations < options.maxIterations))
|
|
520
|
+
setTimeout(runRecurringTask, options.timeout);
|
|
521
|
+
};
|
|
522
|
+
return runRecurringTask(true);
|
|
523
|
+
}
|
|
489
524
|
function autoPlural(term, num, pluralType = "auto") {
|
|
490
525
|
if (typeof num !== "number") {
|
|
491
526
|
if ("length" in num)
|
|
@@ -1291,7 +1326,10 @@ var DataStoreSerializer = class _DataStoreSerializer {
|
|
|
1291
1326
|
...options
|
|
1292
1327
|
};
|
|
1293
1328
|
}
|
|
1294
|
-
/**
|
|
1329
|
+
/**
|
|
1330
|
+
* Calculates the checksum of a string. Uses {@linkcode computeHash()} with SHA-256 and digests as a hex string by default.
|
|
1331
|
+
* Override this in a subclass if a custom checksum method is needed.
|
|
1332
|
+
*/
|
|
1295
1333
|
async calcChecksum(input) {
|
|
1296
1334
|
return computeHash(input, "SHA-256");
|
|
1297
1335
|
}
|
|
@@ -1421,8 +1459,8 @@ var Debouncer = class extends NanoEmitter {
|
|
|
1421
1459
|
* @param timeout Timeout in milliseconds between letting through calls - defaults to 200
|
|
1422
1460
|
* @param type The edge type to use for the debouncer - see {@linkcode DebouncerType} for details or [the documentation for an explanation and diagram](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#debouncer) - defaults to "immediate"
|
|
1423
1461
|
*/
|
|
1424
|
-
constructor(timeout = 200, type = "immediate") {
|
|
1425
|
-
super();
|
|
1462
|
+
constructor(timeout = 200, type = "immediate", nanoEmitterOptions) {
|
|
1463
|
+
super(nanoEmitterOptions);
|
|
1426
1464
|
/** All registered listener functions and the time they were attached */
|
|
1427
1465
|
__publicField(this, "listeners", []);
|
|
1428
1466
|
/** The currently active timeout */
|
|
@@ -1453,7 +1491,7 @@ var Debouncer = class extends NanoEmitter {
|
|
|
1453
1491
|
//#region timeout
|
|
1454
1492
|
/** Sets the timeout for the debouncer */
|
|
1455
1493
|
setTimeout(timeout) {
|
|
1456
|
-
this.emit("change", this.timeout = timeout, this.type);
|
|
1494
|
+
this.events.emit("change", this.timeout = timeout, this.type);
|
|
1457
1495
|
}
|
|
1458
1496
|
/** Returns the current timeout */
|
|
1459
1497
|
getTimeout() {
|
|
@@ -1466,7 +1504,7 @@ var Debouncer = class extends NanoEmitter {
|
|
|
1466
1504
|
//#region type
|
|
1467
1505
|
/** Sets the edge type for the debouncer */
|
|
1468
1506
|
setType(type) {
|
|
1469
|
-
this.emit("change", this.timeout, this.type = type);
|
|
1507
|
+
this.events.emit("change", this.timeout, this.type = type);
|
|
1470
1508
|
}
|
|
1471
1509
|
/** Returns the current edge type */
|
|
1472
1510
|
getType() {
|
|
@@ -1477,7 +1515,7 @@ var Debouncer = class extends NanoEmitter {
|
|
|
1477
1515
|
call(...args) {
|
|
1478
1516
|
const cl = (...a) => {
|
|
1479
1517
|
this.queuedCall = void 0;
|
|
1480
|
-
this.emit("call", ...a);
|
|
1518
|
+
this.events.emit("call", ...a);
|
|
1481
1519
|
this.listeners.forEach((l) => l.call(this, ...a));
|
|
1482
1520
|
};
|
|
1483
1521
|
const setRepeatTimeout = () => {
|
|
@@ -1510,8 +1548,8 @@ var Debouncer = class extends NanoEmitter {
|
|
|
1510
1548
|
}
|
|
1511
1549
|
}
|
|
1512
1550
|
};
|
|
1513
|
-
function debounce(fn, timeout = 200, type = "immediate") {
|
|
1514
|
-
const debouncer = new Debouncer(timeout, type);
|
|
1551
|
+
function debounce(fn, timeout = 200, type = "immediate", nanoEmitterOptions) {
|
|
1552
|
+
const debouncer = new Debouncer(timeout, type, nanoEmitterOptions);
|
|
1515
1553
|
debouncer.addListener(fn);
|
|
1516
1554
|
const func = ((...args) => debouncer.call(...args));
|
|
1517
1555
|
func.debouncer = debouncer;
|
|
@@ -1520,8 +1558,8 @@ function debounce(fn, timeout = 200, type = "immediate") {
|
|
|
1520
1558
|
|
|
1521
1559
|
// lib/consts.ts
|
|
1522
1560
|
var rawConsts = {
|
|
1523
|
-
coreUtilsVersion: "3.
|
|
1524
|
-
userUtilsVersion: "10.
|
|
1561
|
+
coreUtilsVersion: "3.4.0",
|
|
1562
|
+
userUtilsVersion: "10.2.0"
|
|
1525
1563
|
};
|
|
1526
1564
|
function getConst(constKey, defaultVal) {
|
|
1527
1565
|
const val = rawConsts[constKey];
|
package/dist/UserUtils.mjs
CHANGED
|
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
|
|
5
|
-
// node_modules/.pnpm/@sv443-network+coreutils@3.
|
|
5
|
+
// node_modules/.pnpm/@sv443-network+coreutils@3.4.0/node_modules/@sv443-network/coreutils/dist/CoreUtils.mjs
|
|
6
6
|
function bitSetHas(bitSet, checkVal) {
|
|
7
7
|
return (bitSet & checkVal) === checkVal;
|
|
8
8
|
}
|
|
@@ -365,12 +365,46 @@ function getCallStack(asArray, lines = Infinity) {
|
|
|
365
365
|
if (typeof lines !== "number" || isNaN(lines) || lines < 0)
|
|
366
366
|
throw new TypeError("lines parameter must be a non-negative number");
|
|
367
367
|
try {
|
|
368
|
-
throw new
|
|
368
|
+
throw new CustomError("GetCallStack", "Capturing a stack trace with CoreUtils.getCallStack(). If you see this anywhere, you can safely ignore it.");
|
|
369
369
|
} catch (err) {
|
|
370
370
|
const stack = ((_a = err.stack) != null ? _a : "").split("\n").map((line) => line.trim()).slice(2, lines + 2);
|
|
371
371
|
return asArray !== false ? stack : stack.join("\n");
|
|
372
372
|
}
|
|
373
373
|
}
|
|
374
|
+
function createRecurringTask(options) {
|
|
375
|
+
var _a;
|
|
376
|
+
let iterations = 0;
|
|
377
|
+
let aborted = false;
|
|
378
|
+
(_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
|
|
379
|
+
aborted = true;
|
|
380
|
+
}, { once: true });
|
|
381
|
+
const runRecurringTask = async (initial = false) => {
|
|
382
|
+
var _a3, _b;
|
|
383
|
+
var _a2;
|
|
384
|
+
if (aborted)
|
|
385
|
+
return;
|
|
386
|
+
try {
|
|
387
|
+
if (((_a3 = options.immediate) != null ? _a3 : true) || !initial) {
|
|
388
|
+
iterations++;
|
|
389
|
+
if ((_b = await ((_a2 = options.condition) == null ? void 0 : _a2.call(options, iterations - 1))) != null ? _b : true) {
|
|
390
|
+
const val = await options.task(iterations - 1);
|
|
391
|
+
if (options.onSuccess)
|
|
392
|
+
await options.onSuccess(val, iterations - 1);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
} catch (err) {
|
|
396
|
+
if (options.onError)
|
|
397
|
+
await options.onError(err, iterations - 1);
|
|
398
|
+
if (options.abortOnError)
|
|
399
|
+
aborted = true;
|
|
400
|
+
if (!options.onError && !options.abortOnError)
|
|
401
|
+
throw err;
|
|
402
|
+
}
|
|
403
|
+
if (!aborted && (typeof options.maxIterations !== "number" || iterations < options.maxIterations))
|
|
404
|
+
setTimeout(runRecurringTask, options.timeout);
|
|
405
|
+
};
|
|
406
|
+
return runRecurringTask(true);
|
|
407
|
+
}
|
|
374
408
|
function autoPlural(term, num, pluralType = "auto") {
|
|
375
409
|
if (typeof num !== "number") {
|
|
376
410
|
if ("length" in num)
|
|
@@ -1176,7 +1210,10 @@ var DataStoreSerializer = class _DataStoreSerializer {
|
|
|
1176
1210
|
...options
|
|
1177
1211
|
};
|
|
1178
1212
|
}
|
|
1179
|
-
/**
|
|
1213
|
+
/**
|
|
1214
|
+
* Calculates the checksum of a string. Uses {@linkcode computeHash()} with SHA-256 and digests as a hex string by default.
|
|
1215
|
+
* Override this in a subclass if a custom checksum method is needed.
|
|
1216
|
+
*/
|
|
1180
1217
|
async calcChecksum(input) {
|
|
1181
1218
|
return computeHash(input, "SHA-256");
|
|
1182
1219
|
}
|
|
@@ -1306,8 +1343,8 @@ var Debouncer = class extends NanoEmitter {
|
|
|
1306
1343
|
* @param timeout Timeout in milliseconds between letting through calls - defaults to 200
|
|
1307
1344
|
* @param type The edge type to use for the debouncer - see {@linkcode DebouncerType} for details or [the documentation for an explanation and diagram](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#debouncer) - defaults to "immediate"
|
|
1308
1345
|
*/
|
|
1309
|
-
constructor(timeout = 200, type = "immediate") {
|
|
1310
|
-
super();
|
|
1346
|
+
constructor(timeout = 200, type = "immediate", nanoEmitterOptions) {
|
|
1347
|
+
super(nanoEmitterOptions);
|
|
1311
1348
|
/** All registered listener functions and the time they were attached */
|
|
1312
1349
|
__publicField(this, "listeners", []);
|
|
1313
1350
|
/** The currently active timeout */
|
|
@@ -1338,7 +1375,7 @@ var Debouncer = class extends NanoEmitter {
|
|
|
1338
1375
|
//#region timeout
|
|
1339
1376
|
/** Sets the timeout for the debouncer */
|
|
1340
1377
|
setTimeout(timeout) {
|
|
1341
|
-
this.emit("change", this.timeout = timeout, this.type);
|
|
1378
|
+
this.events.emit("change", this.timeout = timeout, this.type);
|
|
1342
1379
|
}
|
|
1343
1380
|
/** Returns the current timeout */
|
|
1344
1381
|
getTimeout() {
|
|
@@ -1351,7 +1388,7 @@ var Debouncer = class extends NanoEmitter {
|
|
|
1351
1388
|
//#region type
|
|
1352
1389
|
/** Sets the edge type for the debouncer */
|
|
1353
1390
|
setType(type) {
|
|
1354
|
-
this.emit("change", this.timeout, this.type = type);
|
|
1391
|
+
this.events.emit("change", this.timeout, this.type = type);
|
|
1355
1392
|
}
|
|
1356
1393
|
/** Returns the current edge type */
|
|
1357
1394
|
getType() {
|
|
@@ -1362,7 +1399,7 @@ var Debouncer = class extends NanoEmitter {
|
|
|
1362
1399
|
call(...args) {
|
|
1363
1400
|
const cl = (...a) => {
|
|
1364
1401
|
this.queuedCall = void 0;
|
|
1365
|
-
this.emit("call", ...a);
|
|
1402
|
+
this.events.emit("call", ...a);
|
|
1366
1403
|
this.listeners.forEach((l) => l.call(this, ...a));
|
|
1367
1404
|
};
|
|
1368
1405
|
const setRepeatTimeout = () => {
|
|
@@ -1395,8 +1432,8 @@ var Debouncer = class extends NanoEmitter {
|
|
|
1395
1432
|
}
|
|
1396
1433
|
}
|
|
1397
1434
|
};
|
|
1398
|
-
function debounce(fn, timeout = 200, type = "immediate") {
|
|
1399
|
-
const debouncer = new Debouncer(timeout, type);
|
|
1435
|
+
function debounce(fn, timeout = 200, type = "immediate", nanoEmitterOptions) {
|
|
1436
|
+
const debouncer = new Debouncer(timeout, type, nanoEmitterOptions);
|
|
1400
1437
|
debouncer.addListener(fn);
|
|
1401
1438
|
const func = ((...args) => debouncer.call(...args));
|
|
1402
1439
|
func.debouncer = debouncer;
|
|
@@ -1405,8 +1442,8 @@ function debounce(fn, timeout = 200, type = "immediate") {
|
|
|
1405
1442
|
|
|
1406
1443
|
// lib/consts.ts
|
|
1407
1444
|
var rawConsts = {
|
|
1408
|
-
coreUtilsVersion: "3.
|
|
1409
|
-
userUtilsVersion: "10.
|
|
1445
|
+
coreUtilsVersion: "3.4.0",
|
|
1446
|
+
userUtilsVersion: "10.2.0"
|
|
1410
1447
|
};
|
|
1411
1448
|
function getConst(constKey, defaultVal) {
|
|
1412
1449
|
const val = rawConsts[constKey];
|
|
@@ -2640,6 +2677,7 @@ export {
|
|
|
2640
2677
|
consumeGen,
|
|
2641
2678
|
consumeStringGen,
|
|
2642
2679
|
createProgressBar,
|
|
2680
|
+
createRecurringTask,
|
|
2643
2681
|
currentDialogId,
|
|
2644
2682
|
darkenColor,
|
|
2645
2683
|
debounce,
|
package/dist/UserUtils.umd.js
CHANGED
|
@@ -131,6 +131,7 @@ __export(lib_exports, {
|
|
|
131
131
|
consumeGen: () => consumeGen,
|
|
132
132
|
consumeStringGen: () => consumeStringGen,
|
|
133
133
|
createProgressBar: () => createProgressBar,
|
|
134
|
+
createRecurringTask: () => createRecurringTask,
|
|
134
135
|
currentDialogId: () => currentDialogId,
|
|
135
136
|
darkenColor: () => darkenColor,
|
|
136
137
|
debounce: () => debounce,
|
|
@@ -184,7 +185,7 @@ __export(lib_exports, {
|
|
|
184
185
|
});
|
|
185
186
|
module.exports = __toCommonJS(lib_exports);
|
|
186
187
|
|
|
187
|
-
// node_modules/.pnpm/@sv443-network+coreutils@3.
|
|
188
|
+
// node_modules/.pnpm/@sv443-network+coreutils@3.4.0/node_modules/@sv443-network/coreutils/dist/CoreUtils.mjs
|
|
188
189
|
function bitSetHas(bitSet, checkVal) {
|
|
189
190
|
return (bitSet & checkVal) === checkVal;
|
|
190
191
|
}
|
|
@@ -556,12 +557,46 @@ function getCallStack(asArray, lines = Infinity) {
|
|
|
556
557
|
if (typeof lines !== "number" || isNaN(lines) || lines < 0)
|
|
557
558
|
throw new TypeError("lines parameter must be a non-negative number");
|
|
558
559
|
try {
|
|
559
|
-
throw new
|
|
560
|
+
throw new CustomError("GetCallStack", "Capturing a stack trace with CoreUtils.getCallStack(). If you see this anywhere, you can safely ignore it.");
|
|
560
561
|
} catch (err) {
|
|
561
562
|
const stack = ((_a = err.stack) != null ? _a : "").split("\n").map((line) => line.trim()).slice(2, lines + 2);
|
|
562
563
|
return asArray !== false ? stack : stack.join("\n");
|
|
563
564
|
}
|
|
564
565
|
}
|
|
566
|
+
function createRecurringTask(options) {
|
|
567
|
+
var _a;
|
|
568
|
+
let iterations = 0;
|
|
569
|
+
let aborted = false;
|
|
570
|
+
(_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
|
|
571
|
+
aborted = true;
|
|
572
|
+
}, { once: true });
|
|
573
|
+
const runRecurringTask = (initial = false) => __async(null, null, function* () {
|
|
574
|
+
var _a3, _b;
|
|
575
|
+
var _a2;
|
|
576
|
+
if (aborted)
|
|
577
|
+
return;
|
|
578
|
+
try {
|
|
579
|
+
if (((_a3 = options.immediate) != null ? _a3 : true) || !initial) {
|
|
580
|
+
iterations++;
|
|
581
|
+
if ((_b = yield (_a2 = options.condition) == null ? void 0 : _a2.call(options, iterations - 1)) != null ? _b : true) {
|
|
582
|
+
const val = yield options.task(iterations - 1);
|
|
583
|
+
if (options.onSuccess)
|
|
584
|
+
yield options.onSuccess(val, iterations - 1);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
} catch (err) {
|
|
588
|
+
if (options.onError)
|
|
589
|
+
yield options.onError(err, iterations - 1);
|
|
590
|
+
if (options.abortOnError)
|
|
591
|
+
aborted = true;
|
|
592
|
+
if (!options.onError && !options.abortOnError)
|
|
593
|
+
throw err;
|
|
594
|
+
}
|
|
595
|
+
if (!aborted && (typeof options.maxIterations !== "number" || iterations < options.maxIterations))
|
|
596
|
+
setTimeout(runRecurringTask, options.timeout);
|
|
597
|
+
});
|
|
598
|
+
return runRecurringTask(true);
|
|
599
|
+
}
|
|
565
600
|
function autoPlural(term, num, pluralType = "auto") {
|
|
566
601
|
if (typeof num !== "number") {
|
|
567
602
|
if ("length" in num)
|
|
@@ -1398,7 +1433,10 @@ var DataStoreSerializer = class _DataStoreSerializer {
|
|
|
1398
1433
|
remapIds: {}
|
|
1399
1434
|
}, options);
|
|
1400
1435
|
}
|
|
1401
|
-
/**
|
|
1436
|
+
/**
|
|
1437
|
+
* Calculates the checksum of a string. Uses {@linkcode computeHash()} with SHA-256 and digests as a hex string by default.
|
|
1438
|
+
* Override this in a subclass if a custom checksum method is needed.
|
|
1439
|
+
*/
|
|
1402
1440
|
calcChecksum(input) {
|
|
1403
1441
|
return __async(this, null, function* () {
|
|
1404
1442
|
return computeHash(input, "SHA-256");
|
|
@@ -1546,8 +1584,8 @@ var Debouncer = class extends NanoEmitter {
|
|
|
1546
1584
|
* @param timeout Timeout in milliseconds between letting through calls - defaults to 200
|
|
1547
1585
|
* @param type The edge type to use for the debouncer - see {@linkcode DebouncerType} for details or [the documentation for an explanation and diagram](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#debouncer) - defaults to "immediate"
|
|
1548
1586
|
*/
|
|
1549
|
-
constructor(timeout = 200, type = "immediate") {
|
|
1550
|
-
super();
|
|
1587
|
+
constructor(timeout = 200, type = "immediate", nanoEmitterOptions) {
|
|
1588
|
+
super(nanoEmitterOptions);
|
|
1551
1589
|
/** All registered listener functions and the time they were attached */
|
|
1552
1590
|
__publicField(this, "listeners", []);
|
|
1553
1591
|
/** The currently active timeout */
|
|
@@ -1578,7 +1616,7 @@ var Debouncer = class extends NanoEmitter {
|
|
|
1578
1616
|
//#region timeout
|
|
1579
1617
|
/** Sets the timeout for the debouncer */
|
|
1580
1618
|
setTimeout(timeout) {
|
|
1581
|
-
this.emit("change", this.timeout = timeout, this.type);
|
|
1619
|
+
this.events.emit("change", this.timeout = timeout, this.type);
|
|
1582
1620
|
}
|
|
1583
1621
|
/** Returns the current timeout */
|
|
1584
1622
|
getTimeout() {
|
|
@@ -1591,7 +1629,7 @@ var Debouncer = class extends NanoEmitter {
|
|
|
1591
1629
|
//#region type
|
|
1592
1630
|
/** Sets the edge type for the debouncer */
|
|
1593
1631
|
setType(type) {
|
|
1594
|
-
this.emit("change", this.timeout, this.type = type);
|
|
1632
|
+
this.events.emit("change", this.timeout, this.type = type);
|
|
1595
1633
|
}
|
|
1596
1634
|
/** Returns the current edge type */
|
|
1597
1635
|
getType() {
|
|
@@ -1602,7 +1640,7 @@ var Debouncer = class extends NanoEmitter {
|
|
|
1602
1640
|
call(...args) {
|
|
1603
1641
|
const cl = (...a) => {
|
|
1604
1642
|
this.queuedCall = void 0;
|
|
1605
|
-
this.emit("call", ...a);
|
|
1643
|
+
this.events.emit("call", ...a);
|
|
1606
1644
|
this.listeners.forEach((l) => l.call(this, ...a));
|
|
1607
1645
|
};
|
|
1608
1646
|
const setRepeatTimeout = () => {
|
|
@@ -1635,8 +1673,8 @@ var Debouncer = class extends NanoEmitter {
|
|
|
1635
1673
|
}
|
|
1636
1674
|
}
|
|
1637
1675
|
};
|
|
1638
|
-
function debounce(fn, timeout = 200, type = "immediate") {
|
|
1639
|
-
const debouncer = new Debouncer(timeout, type);
|
|
1676
|
+
function debounce(fn, timeout = 200, type = "immediate", nanoEmitterOptions) {
|
|
1677
|
+
const debouncer = new Debouncer(timeout, type, nanoEmitterOptions);
|
|
1640
1678
|
debouncer.addListener(fn);
|
|
1641
1679
|
const func = ((...args) => debouncer.call(...args));
|
|
1642
1680
|
func.debouncer = debouncer;
|
|
@@ -1645,8 +1683,8 @@ function debounce(fn, timeout = 200, type = "immediate") {
|
|
|
1645
1683
|
|
|
1646
1684
|
// lib/consts.ts
|
|
1647
1685
|
var rawConsts = {
|
|
1648
|
-
coreUtilsVersion: "3.
|
|
1649
|
-
userUtilsVersion: "10.
|
|
1686
|
+
coreUtilsVersion: "3.4.0",
|
|
1687
|
+
userUtilsVersion: "10.2.0"
|
|
1650
1688
|
};
|
|
1651
1689
|
function getConst(constKey, defaultVal) {
|
|
1652
1690
|
const val = rawConsts[constKey];
|
package/dist/lib/consts.d.ts
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
1
|
/** Contains the semver version strings of UserUtils and the bundled library CoreUtils. */
|
|
2
|
-
export declare const versions:
|
|
3
|
-
/** Semver version string of the bundled library CoreUtils. */
|
|
4
|
-
CoreUtils: string;
|
|
5
|
-
/** Semver version string of UserUtils. */
|
|
6
|
-
UserUtils: string;
|
|
7
|
-
};
|
|
2
|
+
export declare const versions: Record<"CoreUtils" | "UserUtils", string>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sv443-network/userutils",
|
|
3
3
|
"libName": "UserUtils",
|
|
4
|
-
"version": "10.
|
|
4
|
+
"version": "10.2.0",
|
|
5
5
|
"description": "General purpose DOM/GreaseMonkey library that allows you to register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and much more",
|
|
6
6
|
"main": "dist/UserUtils.mjs",
|
|
7
7
|
"module": "dist/UserUtils.mjs",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://github.com/Sv443-Network/UserUtils",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@sv443-network/coreutils": "3.
|
|
36
|
+
"@sv443-network/coreutils": "3.4.0",
|
|
37
37
|
"nanoevents": "9.1.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|