@sv443-network/userutils 10.2.0 → 10.3.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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @sv443-network/userutils
2
2
 
3
+ ## 10.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ffca33d: Updated CoreUtils to v3.5.0, which includes the following changes:
8
+ - Added function `createTable()` to create a very flexible ASCII table, including ANSI color and `%c` styling support.
9
+ - Fixed type variance issue in `DataStoreSerializer` where `DataStore` instances with specific data types (e.g. `DataStore<MyType>`) couldn't be passed to the constructor without being asserted `as DataStore<DataStoreData, boolean>`.
10
+
3
11
  ## 10.2.0
4
12
 
5
13
  ### Minor Changes
package/README.md CHANGED
@@ -157,6 +157,8 @@ View the documentation of previous major versions:
157
157
  - 🟣 [`function pureObj()`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#function-pureobj) - Applies an object's props to a null object (object without prototype chain) or just returns a new null object
158
158
  - 🟣 [`function setImmediateInterval()`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#function-setimmediateinterval) - Like `setInterval()`, but instantly calls the callback and supports passing an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
159
159
  - 🟣 [`function setImmediateTimeoutLoop()`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#function-setimmediatetimeoutloop) - Like a recursive `setTimeout()` loop, but instantly calls the callback and supports passing an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
160
+ - 🟣 [`function createRecurringTask()`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#function-createrecurringtask) - Similar to `setImmediateTimeoutLoop()`, but with many more ways of controlling execution.
161
+ - 🔷 [`type RecurringTaskOptions`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#type-recurringtaskoptions) - Options for the `createRecurringTask()` function.
160
162
  - 🟣 [`function scheduleExit()`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#function-scheduleexit) - Schedules a process exit after the next event loop tick, to allow operations like IO writes to finish.
161
163
  - 🟣 [`function getCallStack()`](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#function-getcallstack) - Returns the current call stack, starting at the caller of this function.
162
164
  - [**NanoEmitter:**](https://github.com/Sv443-Network/CoreUtils/blob/main/docs.md#nanoemitter)
@@ -65,6 +65,7 @@ __export(lib_exports, {
65
65
  consumeStringGen: () => consumeStringGen,
66
66
  createProgressBar: () => createProgressBar,
67
67
  createRecurringTask: () => createRecurringTask,
68
+ createTable: () => createTable,
68
69
  currentDialogId: () => currentDialogId,
69
70
  darkenColor: () => darkenColor,
70
71
  debounce: () => debounce,
@@ -72,6 +73,7 @@ __export(lib_exports, {
72
73
  defaultDialogCss: () => defaultDialogCss,
73
74
  defaultPbChars: () => defaultPbChars,
74
75
  defaultStrings: () => defaultStrings,
76
+ defaultTableLineCharset: () => defaultTableLineCharset,
75
77
  digitCount: () => digitCount,
76
78
  fetchAdvanced: () => fetchAdvanced,
77
79
  formatNumber: () => formatNumber,
@@ -118,7 +120,7 @@ __export(lib_exports, {
118
120
  });
119
121
  module.exports = __toCommonJS(lib_exports);
120
122
 
121
- // node_modules/.pnpm/@sv443-network+coreutils@3.4.0/node_modules/@sv443-network/coreutils/dist/CoreUtils.mjs
123
+ // node_modules/.pnpm/@sv443-network+coreutils@3.5.0/node_modules/@sv443-network/coreutils/dist/CoreUtils.mjs
122
124
  function bitSetHas(bitSet, checkVal) {
123
125
  return (bitSet & checkVal) === checkVal;
124
126
  }
@@ -609,6 +611,179 @@ function truncStr(input, length, endStr = "...") {
609
611
  const finalStr = str.length > length ? str.substring(0, length - endStr.length) + endStr : str;
610
612
  return finalStr.length > length ? finalStr.substring(0, length) : finalStr;
611
613
  }
614
+ var defaultTableLineCharset = {
615
+ single: {
616
+ horizontal: "\u2500",
617
+ vertical: "\u2502",
618
+ topLeft: "\u250C",
619
+ topRight: "\u2510",
620
+ bottomLeft: "\u2514",
621
+ bottomRight: "\u2518",
622
+ leftT: "\u251C",
623
+ rightT: "\u2524",
624
+ topT: "\u252C",
625
+ bottomT: "\u2534",
626
+ cross: "\u253C"
627
+ },
628
+ double: {
629
+ horizontal: "\u2550",
630
+ vertical: "\u2551",
631
+ topLeft: "\u2554",
632
+ topRight: "\u2557",
633
+ bottomLeft: "\u255A",
634
+ bottomRight: "\u255D",
635
+ leftT: "\u2560",
636
+ rightT: "\u2563",
637
+ topT: "\u2566",
638
+ bottomT: "\u2569",
639
+ cross: "\u256C"
640
+ },
641
+ none: {
642
+ horizontal: " ",
643
+ vertical: " ",
644
+ topLeft: " ",
645
+ topRight: " ",
646
+ bottomLeft: " ",
647
+ bottomRight: " ",
648
+ leftT: " ",
649
+ rightT: " ",
650
+ topT: " ",
651
+ bottomT: " ",
652
+ cross: " "
653
+ }
654
+ };
655
+ function createTable(rows, options) {
656
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
657
+ var _a;
658
+ const opts = {
659
+ columnAlign: "left",
660
+ truncateAbove: Infinity,
661
+ truncEndStr: "\u2026",
662
+ minPadding: 1,
663
+ lineStyle: "single",
664
+ applyCellStyle: () => void 0,
665
+ applyLineStyle: () => void 0,
666
+ lineCharset: defaultTableLineCharset,
667
+ ...options != null ? options : {}
668
+ };
669
+ const defRange = (val, min, max) => clamp(typeof val !== "number" || isNaN(Number(val)) ? min : val, min, max);
670
+ opts.truncateAbove = defRange(opts.truncateAbove, 0, Infinity);
671
+ opts.minPadding = defRange(opts.minPadding, 0, Infinity);
672
+ const lnCh = opts.lineCharset[opts.lineStyle];
673
+ const stripAnsi = (str) => str.replace(/\u001b\[[0-9;]*m/g, "");
674
+ const stringRows = rows.map((row) => row.map((cell) => String(cell)));
675
+ const colCount = (_a2 = (_a = rows[0]) == null ? void 0 : _a.length) != null ? _a2 : 0;
676
+ if (colCount === 0 || stringRows.length === 0)
677
+ return "";
678
+ if (isFinite(opts.truncateAbove)) {
679
+ const truncAnsi = (str, maxVisible, endStr) => {
680
+ const limit = maxVisible - endStr.length;
681
+ if (limit <= 0)
682
+ return endStr.slice(0, maxVisible);
683
+ let visible = 0;
684
+ let result = "";
685
+ let i = 0;
686
+ let hasAnsi = false;
687
+ while (i < str.length) {
688
+ if (str[i] === "\x1B" && str[i + 1] === "[") {
689
+ const seqEnd = str.indexOf("m", i + 2);
690
+ if (seqEnd !== -1) {
691
+ result += str.slice(i, seqEnd + 1);
692
+ hasAnsi = true;
693
+ i = seqEnd + 1;
694
+ continue;
695
+ }
696
+ }
697
+ if (visible === limit) {
698
+ result += endStr;
699
+ if (hasAnsi)
700
+ result += "\x1B[0m";
701
+ return result;
702
+ }
703
+ result += str[i];
704
+ visible++;
705
+ i++;
706
+ }
707
+ return result;
708
+ };
709
+ for (const row of stringRows)
710
+ for (let j = 0; j < row.length; j++)
711
+ if (stripAnsi((_b = row[j]) != null ? _b : "").length > opts.truncateAbove)
712
+ row[j] = truncAnsi((_c = row[j]) != null ? _c : "", opts.truncateAbove, opts.truncEndStr);
713
+ }
714
+ const colWidths = Array.from(
715
+ { length: colCount },
716
+ (_, j) => Math.max(0, ...stringRows.map((row) => {
717
+ var _a3;
718
+ return stripAnsi((_a3 = row[j]) != null ? _a3 : "").length;
719
+ }))
720
+ );
721
+ const applyLn = (i, j, ch) => {
722
+ var _a3;
723
+ const [before = "", after = ""] = (_a3 = opts.applyLineStyle(i, j)) != null ? _a3 : [];
724
+ return `${before}${ch}${after}`;
725
+ };
726
+ const buildBorderRow = (lineIdx, leftCh, midCh, rightCh) => {
727
+ var _a3;
728
+ let result = "";
729
+ let j = 0;
730
+ result += applyLn(lineIdx, j++, leftCh);
731
+ for (let col = 0; col < colCount; col++) {
732
+ const cellWidth = ((_a3 = colWidths[col]) != null ? _a3 : 0) + opts.minPadding * 2;
733
+ for (let ci = 0; ci < cellWidth; ci++)
734
+ result += applyLn(lineIdx, j++, lnCh.horizontal);
735
+ if (col < colCount - 1)
736
+ result += applyLn(lineIdx, j++, midCh);
737
+ }
738
+ result += applyLn(lineIdx, j++, rightCh);
739
+ return result;
740
+ };
741
+ const lines = [];
742
+ for (let rowIdx = 0; rowIdx < stringRows.length; rowIdx++) {
743
+ const row = (_d = stringRows[rowIdx]) != null ? _d : [];
744
+ const lineIdxBase = rowIdx * 3;
745
+ if (opts.lineStyle !== "none") {
746
+ lines.push(
747
+ rowIdx === 0 ? buildBorderRow(lineIdxBase, lnCh.topLeft, lnCh.topT, lnCh.topRight) : buildBorderRow(lineIdxBase, lnCh.leftT, lnCh.cross, lnCh.rightT)
748
+ );
749
+ }
750
+ let contentLine = "";
751
+ let j = 0;
752
+ contentLine += applyLn(lineIdxBase + 1, j++, lnCh.vertical);
753
+ for (let colIdx = 0; colIdx < colCount; colIdx++) {
754
+ const cell = (_e = row[colIdx]) != null ? _e : "";
755
+ const visLen = stripAnsi(cell).length;
756
+ const extra = ((_f = colWidths[colIdx]) != null ? _f : 0) - visLen;
757
+ const align = (_g = Array.isArray(opts.columnAlign) ? opts.columnAlign[colIdx] : opts.columnAlign) != null ? _g : "left";
758
+ let leftPad;
759
+ let rightPad;
760
+ switch (align) {
761
+ case "right":
762
+ leftPad = opts.minPadding + extra;
763
+ rightPad = opts.minPadding;
764
+ break;
765
+ case "centerLeft":
766
+ leftPad = opts.minPadding + Math.floor(extra / 2);
767
+ rightPad = opts.minPadding + Math.ceil(extra / 2);
768
+ break;
769
+ case "centerRight":
770
+ leftPad = opts.minPadding + Math.ceil(extra / 2);
771
+ rightPad = opts.minPadding + Math.floor(extra / 2);
772
+ break;
773
+ default:
774
+ leftPad = opts.minPadding;
775
+ rightPad = opts.minPadding + extra;
776
+ }
777
+ const [cellBefore = "", cellAfter = ""] = (_h = opts.applyCellStyle(rowIdx, colIdx)) != null ? _h : [];
778
+ contentLine += " ".repeat(leftPad) + cellBefore + cell + cellAfter + " ".repeat(rightPad);
779
+ contentLine += applyLn(lineIdxBase + 1, j++, lnCh.vertical);
780
+ }
781
+ lines.push(contentLine);
782
+ if (opts.lineStyle !== "none" && rowIdx === stringRows.length - 1)
783
+ lines.push(buildBorderRow(lineIdxBase + 2, lnCh.bottomLeft, lnCh.bottomT, lnCh.bottomRight));
784
+ }
785
+ return lines.join("\n");
786
+ }
612
787
  var createNanoEvents = () => ({
613
788
  emit(event, ...args) {
614
789
  for (let callbacks = this.events[event] || [], i = 0, length = callbacks.length; i < length; i++) {
@@ -1315,6 +1490,7 @@ var FileStorageEngine = class extends DataStoreEngine {
1315
1490
  var DataStoreSerializer = class _DataStoreSerializer {
1316
1491
  constructor(stores, options = {}) {
1317
1492
  __publicField(this, "stores");
1493
+ // eslint-disable-line @typescript-eslint/no-explicit-any
1318
1494
  __publicField(this, "options");
1319
1495
  if (!crypto || !crypto.subtle)
1320
1496
  throw new ScriptContextError("DataStoreSerializer has to run in a secure context (HTTPS) or in another environment that implements the subtleCrypto API!");
@@ -1558,8 +1734,8 @@ function debounce(fn, timeout = 200, type = "immediate", nanoEmitterOptions) {
1558
1734
 
1559
1735
  // lib/consts.ts
1560
1736
  var rawConsts = {
1561
- coreUtilsVersion: "3.4.0",
1562
- userUtilsVersion: "10.2.0"
1737
+ coreUtilsVersion: "3.5.0",
1738
+ userUtilsVersion: "10.3.0"
1563
1739
  };
1564
1740
  function getConst(constKey, defaultVal) {
1565
1741
  const val = rawConsts[constKey];
@@ -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.4.0/node_modules/@sv443-network/coreutils/dist/CoreUtils.mjs
5
+ // node_modules/.pnpm/@sv443-network+coreutils@3.5.0/node_modules/@sv443-network/coreutils/dist/CoreUtils.mjs
6
6
  function bitSetHas(bitSet, checkVal) {
7
7
  return (bitSet & checkVal) === checkVal;
8
8
  }
@@ -493,6 +493,179 @@ function truncStr(input, length, endStr = "...") {
493
493
  const finalStr = str.length > length ? str.substring(0, length - endStr.length) + endStr : str;
494
494
  return finalStr.length > length ? finalStr.substring(0, length) : finalStr;
495
495
  }
496
+ var defaultTableLineCharset = {
497
+ single: {
498
+ horizontal: "\u2500",
499
+ vertical: "\u2502",
500
+ topLeft: "\u250C",
501
+ topRight: "\u2510",
502
+ bottomLeft: "\u2514",
503
+ bottomRight: "\u2518",
504
+ leftT: "\u251C",
505
+ rightT: "\u2524",
506
+ topT: "\u252C",
507
+ bottomT: "\u2534",
508
+ cross: "\u253C"
509
+ },
510
+ double: {
511
+ horizontal: "\u2550",
512
+ vertical: "\u2551",
513
+ topLeft: "\u2554",
514
+ topRight: "\u2557",
515
+ bottomLeft: "\u255A",
516
+ bottomRight: "\u255D",
517
+ leftT: "\u2560",
518
+ rightT: "\u2563",
519
+ topT: "\u2566",
520
+ bottomT: "\u2569",
521
+ cross: "\u256C"
522
+ },
523
+ none: {
524
+ horizontal: " ",
525
+ vertical: " ",
526
+ topLeft: " ",
527
+ topRight: " ",
528
+ bottomLeft: " ",
529
+ bottomRight: " ",
530
+ leftT: " ",
531
+ rightT: " ",
532
+ topT: " ",
533
+ bottomT: " ",
534
+ cross: " "
535
+ }
536
+ };
537
+ function createTable(rows, options) {
538
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
539
+ var _a;
540
+ const opts = {
541
+ columnAlign: "left",
542
+ truncateAbove: Infinity,
543
+ truncEndStr: "\u2026",
544
+ minPadding: 1,
545
+ lineStyle: "single",
546
+ applyCellStyle: () => void 0,
547
+ applyLineStyle: () => void 0,
548
+ lineCharset: defaultTableLineCharset,
549
+ ...options != null ? options : {}
550
+ };
551
+ const defRange = (val, min, max) => clamp(typeof val !== "number" || isNaN(Number(val)) ? min : val, min, max);
552
+ opts.truncateAbove = defRange(opts.truncateAbove, 0, Infinity);
553
+ opts.minPadding = defRange(opts.minPadding, 0, Infinity);
554
+ const lnCh = opts.lineCharset[opts.lineStyle];
555
+ const stripAnsi = (str) => str.replace(/\u001b\[[0-9;]*m/g, "");
556
+ const stringRows = rows.map((row) => row.map((cell) => String(cell)));
557
+ const colCount = (_a2 = (_a = rows[0]) == null ? void 0 : _a.length) != null ? _a2 : 0;
558
+ if (colCount === 0 || stringRows.length === 0)
559
+ return "";
560
+ if (isFinite(opts.truncateAbove)) {
561
+ const truncAnsi = (str, maxVisible, endStr) => {
562
+ const limit = maxVisible - endStr.length;
563
+ if (limit <= 0)
564
+ return endStr.slice(0, maxVisible);
565
+ let visible = 0;
566
+ let result = "";
567
+ let i = 0;
568
+ let hasAnsi = false;
569
+ while (i < str.length) {
570
+ if (str[i] === "\x1B" && str[i + 1] === "[") {
571
+ const seqEnd = str.indexOf("m", i + 2);
572
+ if (seqEnd !== -1) {
573
+ result += str.slice(i, seqEnd + 1);
574
+ hasAnsi = true;
575
+ i = seqEnd + 1;
576
+ continue;
577
+ }
578
+ }
579
+ if (visible === limit) {
580
+ result += endStr;
581
+ if (hasAnsi)
582
+ result += "\x1B[0m";
583
+ return result;
584
+ }
585
+ result += str[i];
586
+ visible++;
587
+ i++;
588
+ }
589
+ return result;
590
+ };
591
+ for (const row of stringRows)
592
+ for (let j = 0; j < row.length; j++)
593
+ if (stripAnsi((_b = row[j]) != null ? _b : "").length > opts.truncateAbove)
594
+ row[j] = truncAnsi((_c = row[j]) != null ? _c : "", opts.truncateAbove, opts.truncEndStr);
595
+ }
596
+ const colWidths = Array.from(
597
+ { length: colCount },
598
+ (_, j) => Math.max(0, ...stringRows.map((row) => {
599
+ var _a3;
600
+ return stripAnsi((_a3 = row[j]) != null ? _a3 : "").length;
601
+ }))
602
+ );
603
+ const applyLn = (i, j, ch) => {
604
+ var _a3;
605
+ const [before = "", after = ""] = (_a3 = opts.applyLineStyle(i, j)) != null ? _a3 : [];
606
+ return `${before}${ch}${after}`;
607
+ };
608
+ const buildBorderRow = (lineIdx, leftCh, midCh, rightCh) => {
609
+ var _a3;
610
+ let result = "";
611
+ let j = 0;
612
+ result += applyLn(lineIdx, j++, leftCh);
613
+ for (let col = 0; col < colCount; col++) {
614
+ const cellWidth = ((_a3 = colWidths[col]) != null ? _a3 : 0) + opts.minPadding * 2;
615
+ for (let ci = 0; ci < cellWidth; ci++)
616
+ result += applyLn(lineIdx, j++, lnCh.horizontal);
617
+ if (col < colCount - 1)
618
+ result += applyLn(lineIdx, j++, midCh);
619
+ }
620
+ result += applyLn(lineIdx, j++, rightCh);
621
+ return result;
622
+ };
623
+ const lines = [];
624
+ for (let rowIdx = 0; rowIdx < stringRows.length; rowIdx++) {
625
+ const row = (_d = stringRows[rowIdx]) != null ? _d : [];
626
+ const lineIdxBase = rowIdx * 3;
627
+ if (opts.lineStyle !== "none") {
628
+ lines.push(
629
+ rowIdx === 0 ? buildBorderRow(lineIdxBase, lnCh.topLeft, lnCh.topT, lnCh.topRight) : buildBorderRow(lineIdxBase, lnCh.leftT, lnCh.cross, lnCh.rightT)
630
+ );
631
+ }
632
+ let contentLine = "";
633
+ let j = 0;
634
+ contentLine += applyLn(lineIdxBase + 1, j++, lnCh.vertical);
635
+ for (let colIdx = 0; colIdx < colCount; colIdx++) {
636
+ const cell = (_e = row[colIdx]) != null ? _e : "";
637
+ const visLen = stripAnsi(cell).length;
638
+ const extra = ((_f = colWidths[colIdx]) != null ? _f : 0) - visLen;
639
+ const align = (_g = Array.isArray(opts.columnAlign) ? opts.columnAlign[colIdx] : opts.columnAlign) != null ? _g : "left";
640
+ let leftPad;
641
+ let rightPad;
642
+ switch (align) {
643
+ case "right":
644
+ leftPad = opts.minPadding + extra;
645
+ rightPad = opts.minPadding;
646
+ break;
647
+ case "centerLeft":
648
+ leftPad = opts.minPadding + Math.floor(extra / 2);
649
+ rightPad = opts.minPadding + Math.ceil(extra / 2);
650
+ break;
651
+ case "centerRight":
652
+ leftPad = opts.minPadding + Math.ceil(extra / 2);
653
+ rightPad = opts.minPadding + Math.floor(extra / 2);
654
+ break;
655
+ default:
656
+ leftPad = opts.minPadding;
657
+ rightPad = opts.minPadding + extra;
658
+ }
659
+ const [cellBefore = "", cellAfter = ""] = (_h = opts.applyCellStyle(rowIdx, colIdx)) != null ? _h : [];
660
+ contentLine += " ".repeat(leftPad) + cellBefore + cell + cellAfter + " ".repeat(rightPad);
661
+ contentLine += applyLn(lineIdxBase + 1, j++, lnCh.vertical);
662
+ }
663
+ lines.push(contentLine);
664
+ if (opts.lineStyle !== "none" && rowIdx === stringRows.length - 1)
665
+ lines.push(buildBorderRow(lineIdxBase + 2, lnCh.bottomLeft, lnCh.bottomT, lnCh.bottomRight));
666
+ }
667
+ return lines.join("\n");
668
+ }
496
669
  var createNanoEvents = () => ({
497
670
  emit(event, ...args) {
498
671
  for (let callbacks = this.events[event] || [], i = 0, length = callbacks.length; i < length; i++) {
@@ -1199,6 +1372,7 @@ var FileStorageEngine = class extends DataStoreEngine {
1199
1372
  var DataStoreSerializer = class _DataStoreSerializer {
1200
1373
  constructor(stores, options = {}) {
1201
1374
  __publicField(this, "stores");
1375
+ // eslint-disable-line @typescript-eslint/no-explicit-any
1202
1376
  __publicField(this, "options");
1203
1377
  if (!crypto || !crypto.subtle)
1204
1378
  throw new ScriptContextError("DataStoreSerializer has to run in a secure context (HTTPS) or in another environment that implements the subtleCrypto API!");
@@ -1442,8 +1616,8 @@ function debounce(fn, timeout = 200, type = "immediate", nanoEmitterOptions) {
1442
1616
 
1443
1617
  // lib/consts.ts
1444
1618
  var rawConsts = {
1445
- coreUtilsVersion: "3.4.0",
1446
- userUtilsVersion: "10.2.0"
1619
+ coreUtilsVersion: "3.5.0",
1620
+ userUtilsVersion: "10.3.0"
1447
1621
  };
1448
1622
  function getConst(constKey, defaultVal) {
1449
1623
  const val = rawConsts[constKey];
@@ -2678,6 +2852,7 @@ export {
2678
2852
  consumeStringGen,
2679
2853
  createProgressBar,
2680
2854
  createRecurringTask,
2855
+ createTable,
2681
2856
  currentDialogId,
2682
2857
  darkenColor,
2683
2858
  debounce,
@@ -2685,6 +2860,7 @@ export {
2685
2860
  defaultDialogCss,
2686
2861
  defaultPbChars,
2687
2862
  defaultStrings,
2863
+ defaultTableLineCharset,
2688
2864
  digitCount,
2689
2865
  fetchAdvanced,
2690
2866
  formatNumber,
@@ -132,6 +132,7 @@ __export(lib_exports, {
132
132
  consumeStringGen: () => consumeStringGen,
133
133
  createProgressBar: () => createProgressBar,
134
134
  createRecurringTask: () => createRecurringTask,
135
+ createTable: () => createTable,
135
136
  currentDialogId: () => currentDialogId,
136
137
  darkenColor: () => darkenColor,
137
138
  debounce: () => debounce,
@@ -139,6 +140,7 @@ __export(lib_exports, {
139
140
  defaultDialogCss: () => defaultDialogCss,
140
141
  defaultPbChars: () => defaultPbChars,
141
142
  defaultStrings: () => defaultStrings,
143
+ defaultTableLineCharset: () => defaultTableLineCharset,
142
144
  digitCount: () => digitCount,
143
145
  fetchAdvanced: () => fetchAdvanced,
144
146
  formatNumber: () => formatNumber,
@@ -185,7 +187,7 @@ __export(lib_exports, {
185
187
  });
186
188
  module.exports = __toCommonJS(lib_exports);
187
189
 
188
- // node_modules/.pnpm/@sv443-network+coreutils@3.4.0/node_modules/@sv443-network/coreutils/dist/CoreUtils.mjs
190
+ // node_modules/.pnpm/@sv443-network+coreutils@3.5.0/node_modules/@sv443-network/coreutils/dist/CoreUtils.mjs
189
191
  function bitSetHas(bitSet, checkVal) {
190
192
  return (bitSet & checkVal) === checkVal;
191
193
  }
@@ -685,6 +687,178 @@ function truncStr(input, length, endStr = "...") {
685
687
  const finalStr = str.length > length ? str.substring(0, length - endStr.length) + endStr : str;
686
688
  return finalStr.length > length ? finalStr.substring(0, length) : finalStr;
687
689
  }
690
+ var defaultTableLineCharset = {
691
+ single: {
692
+ horizontal: "\u2500",
693
+ vertical: "\u2502",
694
+ topLeft: "\u250C",
695
+ topRight: "\u2510",
696
+ bottomLeft: "\u2514",
697
+ bottomRight: "\u2518",
698
+ leftT: "\u251C",
699
+ rightT: "\u2524",
700
+ topT: "\u252C",
701
+ bottomT: "\u2534",
702
+ cross: "\u253C"
703
+ },
704
+ double: {
705
+ horizontal: "\u2550",
706
+ vertical: "\u2551",
707
+ topLeft: "\u2554",
708
+ topRight: "\u2557",
709
+ bottomLeft: "\u255A",
710
+ bottomRight: "\u255D",
711
+ leftT: "\u2560",
712
+ rightT: "\u2563",
713
+ topT: "\u2566",
714
+ bottomT: "\u2569",
715
+ cross: "\u256C"
716
+ },
717
+ none: {
718
+ horizontal: " ",
719
+ vertical: " ",
720
+ topLeft: " ",
721
+ topRight: " ",
722
+ bottomLeft: " ",
723
+ bottomRight: " ",
724
+ leftT: " ",
725
+ rightT: " ",
726
+ topT: " ",
727
+ bottomT: " ",
728
+ cross: " "
729
+ }
730
+ };
731
+ function createTable(rows, options) {
732
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
733
+ var _a;
734
+ const opts = __spreadValues({
735
+ columnAlign: "left",
736
+ truncateAbove: Infinity,
737
+ truncEndStr: "\u2026",
738
+ minPadding: 1,
739
+ lineStyle: "single",
740
+ applyCellStyle: () => void 0,
741
+ applyLineStyle: () => void 0,
742
+ lineCharset: defaultTableLineCharset
743
+ }, options != null ? options : {});
744
+ const defRange = (val, min, max) => clamp(typeof val !== "number" || isNaN(Number(val)) ? min : val, min, max);
745
+ opts.truncateAbove = defRange(opts.truncateAbove, 0, Infinity);
746
+ opts.minPadding = defRange(opts.minPadding, 0, Infinity);
747
+ const lnCh = opts.lineCharset[opts.lineStyle];
748
+ const stripAnsi = (str) => str.replace(/\u001b\[[0-9;]*m/g, "");
749
+ const stringRows = rows.map((row) => row.map((cell) => String(cell)));
750
+ const colCount = (_a2 = (_a = rows[0]) == null ? void 0 : _a.length) != null ? _a2 : 0;
751
+ if (colCount === 0 || stringRows.length === 0)
752
+ return "";
753
+ if (isFinite(opts.truncateAbove)) {
754
+ const truncAnsi = (str, maxVisible, endStr) => {
755
+ const limit = maxVisible - endStr.length;
756
+ if (limit <= 0)
757
+ return endStr.slice(0, maxVisible);
758
+ let visible = 0;
759
+ let result = "";
760
+ let i = 0;
761
+ let hasAnsi = false;
762
+ while (i < str.length) {
763
+ if (str[i] === "\x1B" && str[i + 1] === "[") {
764
+ const seqEnd = str.indexOf("m", i + 2);
765
+ if (seqEnd !== -1) {
766
+ result += str.slice(i, seqEnd + 1);
767
+ hasAnsi = true;
768
+ i = seqEnd + 1;
769
+ continue;
770
+ }
771
+ }
772
+ if (visible === limit) {
773
+ result += endStr;
774
+ if (hasAnsi)
775
+ result += "\x1B[0m";
776
+ return result;
777
+ }
778
+ result += str[i];
779
+ visible++;
780
+ i++;
781
+ }
782
+ return result;
783
+ };
784
+ for (const row of stringRows)
785
+ for (let j = 0; j < row.length; j++)
786
+ if (stripAnsi((_b = row[j]) != null ? _b : "").length > opts.truncateAbove)
787
+ row[j] = truncAnsi((_c = row[j]) != null ? _c : "", opts.truncateAbove, opts.truncEndStr);
788
+ }
789
+ const colWidths = Array.from(
790
+ { length: colCount },
791
+ (_, j) => Math.max(0, ...stringRows.map((row) => {
792
+ var _a3;
793
+ return stripAnsi((_a3 = row[j]) != null ? _a3 : "").length;
794
+ }))
795
+ );
796
+ const applyLn = (i, j, ch) => {
797
+ var _a3;
798
+ const [before = "", after = ""] = (_a3 = opts.applyLineStyle(i, j)) != null ? _a3 : [];
799
+ return `${before}${ch}${after}`;
800
+ };
801
+ const buildBorderRow = (lineIdx, leftCh, midCh, rightCh) => {
802
+ var _a3;
803
+ let result = "";
804
+ let j = 0;
805
+ result += applyLn(lineIdx, j++, leftCh);
806
+ for (let col = 0; col < colCount; col++) {
807
+ const cellWidth = ((_a3 = colWidths[col]) != null ? _a3 : 0) + opts.minPadding * 2;
808
+ for (let ci = 0; ci < cellWidth; ci++)
809
+ result += applyLn(lineIdx, j++, lnCh.horizontal);
810
+ if (col < colCount - 1)
811
+ result += applyLn(lineIdx, j++, midCh);
812
+ }
813
+ result += applyLn(lineIdx, j++, rightCh);
814
+ return result;
815
+ };
816
+ const lines = [];
817
+ for (let rowIdx = 0; rowIdx < stringRows.length; rowIdx++) {
818
+ const row = (_d = stringRows[rowIdx]) != null ? _d : [];
819
+ const lineIdxBase = rowIdx * 3;
820
+ if (opts.lineStyle !== "none") {
821
+ lines.push(
822
+ rowIdx === 0 ? buildBorderRow(lineIdxBase, lnCh.topLeft, lnCh.topT, lnCh.topRight) : buildBorderRow(lineIdxBase, lnCh.leftT, lnCh.cross, lnCh.rightT)
823
+ );
824
+ }
825
+ let contentLine = "";
826
+ let j = 0;
827
+ contentLine += applyLn(lineIdxBase + 1, j++, lnCh.vertical);
828
+ for (let colIdx = 0; colIdx < colCount; colIdx++) {
829
+ const cell = (_e = row[colIdx]) != null ? _e : "";
830
+ const visLen = stripAnsi(cell).length;
831
+ const extra = ((_f = colWidths[colIdx]) != null ? _f : 0) - visLen;
832
+ const align = (_g = Array.isArray(opts.columnAlign) ? opts.columnAlign[colIdx] : opts.columnAlign) != null ? _g : "left";
833
+ let leftPad;
834
+ let rightPad;
835
+ switch (align) {
836
+ case "right":
837
+ leftPad = opts.minPadding + extra;
838
+ rightPad = opts.minPadding;
839
+ break;
840
+ case "centerLeft":
841
+ leftPad = opts.minPadding + Math.floor(extra / 2);
842
+ rightPad = opts.minPadding + Math.ceil(extra / 2);
843
+ break;
844
+ case "centerRight":
845
+ leftPad = opts.minPadding + Math.ceil(extra / 2);
846
+ rightPad = opts.minPadding + Math.floor(extra / 2);
847
+ break;
848
+ default:
849
+ leftPad = opts.minPadding;
850
+ rightPad = opts.minPadding + extra;
851
+ }
852
+ const [cellBefore = "", cellAfter = ""] = (_h = opts.applyCellStyle(rowIdx, colIdx)) != null ? _h : [];
853
+ contentLine += " ".repeat(leftPad) + cellBefore + cell + cellAfter + " ".repeat(rightPad);
854
+ contentLine += applyLn(lineIdxBase + 1, j++, lnCh.vertical);
855
+ }
856
+ lines.push(contentLine);
857
+ if (opts.lineStyle !== "none" && rowIdx === stringRows.length - 1)
858
+ lines.push(buildBorderRow(lineIdxBase + 2, lnCh.bottomLeft, lnCh.bottomT, lnCh.bottomRight));
859
+ }
860
+ return lines.join("\n");
861
+ }
688
862
  var createNanoEvents = () => ({
689
863
  emit(event, ...args) {
690
864
  for (let callbacks = this.events[event] || [], i = 0, length = callbacks.length; i < length; i++) {
@@ -1423,6 +1597,7 @@ var FileStorageEngine = class extends DataStoreEngine {
1423
1597
  var DataStoreSerializer = class _DataStoreSerializer {
1424
1598
  constructor(stores, options = {}) {
1425
1599
  __publicField(this, "stores");
1600
+ // eslint-disable-line @typescript-eslint/no-explicit-any
1426
1601
  __publicField(this, "options");
1427
1602
  if (!crypto || !crypto.subtle)
1428
1603
  throw new ScriptContextError("DataStoreSerializer has to run in a secure context (HTTPS) or in another environment that implements the subtleCrypto API!");
@@ -1683,8 +1858,8 @@ function debounce(fn, timeout = 200, type = "immediate", nanoEmitterOptions) {
1683
1858
 
1684
1859
  // lib/consts.ts
1685
1860
  var rawConsts = {
1686
- coreUtilsVersion: "3.4.0",
1687
- userUtilsVersion: "10.2.0"
1861
+ coreUtilsVersion: "3.5.0",
1862
+ userUtilsVersion: "10.3.0"
1688
1863
  };
1689
1864
  function getConst(constKey, defaultVal) {
1690
1865
  const val = rawConsts[constKey];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sv443-network/userutils",
3
3
  "libName": "UserUtils",
4
- "version": "10.2.0",
4
+ "version": "10.3.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.4.0",
36
+ "@sv443-network/coreutils": "3.5.0",
37
37
  "nanoevents": "9.1.0"
38
38
  },
39
39
  "devDependencies": {