@tspro/ts-utils-lib 1.13.0 → 1.15.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/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /* TsUtilsLib v1.13.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
1
+ /* TsUtilsLib v1.15.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
2
2
  var __defProp = Object.defineProperty;
3
3
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
4
  var __export = (target, all) => {
@@ -37,136 +37,175 @@ __export(arr_exports, {
37
37
  toArray: () => toArray
38
38
  });
39
39
 
40
- // src/utils/math/index.ts
41
- var math_exports = {};
42
- __export(math_exports, {
43
- avg: () => avg,
44
- calcNormal: () => calcNormal,
45
- clamp: () => clamp,
46
- cmp: () => cmp,
47
- interpolateCoord: () => interpolateCoord,
48
- interpolateY: () => interpolateY,
40
+ // src/utils/is/index.ts
41
+ var is_exports = {};
42
+ __export(is_exports, {
43
+ isArray: () => isArray,
44
+ isArrayOrUndefined: () => isArrayOrUndefined,
45
+ isBoolean: () => isBoolean,
46
+ isBooleanOrUndefined: () => isBooleanOrUndefined,
47
+ isEmptyArray: () => isEmptyArray,
48
+ isEmptyArrayOrUndefined: () => isEmptyArrayOrUndefined,
49
+ isEmptyString: () => isEmptyString,
50
+ isEmptyStringOrUndefined: () => isEmptyStringOrUndefined,
51
+ isEnumValue: () => isEnumValue,
52
+ isEnumValueOrUndefined: () => isEnumValueOrUndefined,
53
+ isFinite: () => isFinite2,
54
+ isFunction: () => isFunction,
55
+ isFunctionOrUndefined: () => isFunctionOrUndefined,
56
+ isInfinity: () => isInfinity,
49
57
  isInteger: () => isInteger,
50
- linearToDecibels: () => linearToDecibels,
51
- mod: () => mod,
52
- romanize: () => romanize,
53
- sum: () => sum,
54
- toOrdinalNumber: () => toOrdinalNumber
58
+ isIntegerBetween: () => isIntegerBetween,
59
+ isIntegerEq: () => isIntegerEq,
60
+ isIntegerGt: () => isIntegerGt,
61
+ isIntegerGte: () => isIntegerGte,
62
+ isIntegerLt: () => isIntegerLt,
63
+ isIntegerLte: () => isIntegerLte,
64
+ isIntegerOrUndefined: () => isIntegerOrUndefined,
65
+ isNaNValue: () => isNaNValue,
66
+ isNegInfinity: () => isNegInfinity,
67
+ isNonEmptyArray: () => isNonEmptyArray,
68
+ isNonEmptyArrayOrUndefined: () => isNonEmptyArrayOrUndefined,
69
+ isNonEmptyString: () => isNonEmptyString,
70
+ isNonEmptyStringOrUndefined: () => isNonEmptyStringOrUndefined,
71
+ isNull: () => isNull,
72
+ isNullish: () => isNullish,
73
+ isNumber: () => isNumber,
74
+ isNumberOrUndefined: () => isNumberOrUndefined,
75
+ isObject: () => isObject,
76
+ isObjectOrUndefined: () => isObjectOrUndefined,
77
+ isPosInfinity: () => isPosInfinity,
78
+ isString: () => isString,
79
+ isStringOrUndefined: () => isStringOrUndefined,
80
+ isUndefined: () => isUndefined
81
+ });
82
+
83
+ // src/utils/enum/index.ts
84
+ var enum_exports = {};
85
+ __export(enum_exports, {
86
+ getEnumValues: () => getEnumValues
55
87
  });
88
+ function getEnumValues(e) {
89
+ return Object.keys(e).filter((key) => Number.isNaN(Number(key))).map((key) => e[key]);
90
+ }
91
+
92
+ // src/utils/is/index.ts
93
+ function isUndefined(value) {
94
+ return value === void 0;
95
+ }
96
+ function isNull(value) {
97
+ return value === null;
98
+ }
99
+ function isNullish(value) {
100
+ return value === void 0 || value === null;
101
+ }
102
+ function isObject(value) {
103
+ return typeof value === "object" && value !== null && !isArray(value);
104
+ }
105
+ function isObjectOrUndefined(value) {
106
+ return value === void 0 || isObject(value);
107
+ }
108
+ function isArray(a) {
109
+ return !!a && Object.prototype.toString.call(a) === "[object Array]";
110
+ }
111
+ function isArrayOrUndefined(value) {
112
+ return value === void 0 || isArray(value);
113
+ }
114
+ function isEmptyArray(a) {
115
+ return isArray(a) && a.length === 0;
116
+ }
117
+ function isNonEmptyArray(a) {
118
+ return isArray(a) && a.length > 0;
119
+ }
120
+ function isEmptyArrayOrUndefined(a) {
121
+ return isArray(a) && a.length === 0 || a === void 0;
122
+ }
123
+ function isNonEmptyArrayOrUndefined(a) {
124
+ return isArray(a) && a.length > 0 || a === void 0;
125
+ }
126
+ function isString(value) {
127
+ return typeof value === "string";
128
+ }
129
+ function isEmptyString(value) {
130
+ return typeof value === "string" && value.length === 0;
131
+ }
132
+ function isNonEmptyString(value) {
133
+ return typeof value === "string" && value.length > 0;
134
+ }
135
+ function isStringOrUndefined(value) {
136
+ return value === void 0 || typeof value === "string";
137
+ }
138
+ function isEmptyStringOrUndefined(value) {
139
+ return typeof value === "string" && value.length === 0 || value === void 0;
140
+ }
141
+ function isNonEmptyStringOrUndefined(value) {
142
+ return typeof value === "string" && value.length > 0 || value === void 0;
143
+ }
144
+ function isBoolean(value) {
145
+ return typeof value === "boolean";
146
+ }
147
+ function isBooleanOrUndefined(value) {
148
+ return value === void 0 || typeof value === "boolean";
149
+ }
150
+ function isFunction(value) {
151
+ return typeof value === "function";
152
+ }
153
+ function isFunctionOrUndefined(value) {
154
+ return value === void 0 || typeof value === "function";
155
+ }
156
+ function isEnumValue(value, enumObj, name = "value") {
157
+ return getEnumValues(enumObj).some((v) => v === value);
158
+ }
159
+ function isEnumValueOrUndefined(value, enumObj, name = "value") {
160
+ return value === void 0 || getEnumValues(enumObj).some((v) => v === value);
161
+ }
162
+ function isNumber(value) {
163
+ return typeof value === "number";
164
+ }
165
+ function isNumberOrUndefined(value) {
166
+ return typeof value === "number" || value === void 0;
167
+ }
168
+ function isFinite2(value) {
169
+ return typeof value === "number" && Number.isFinite(value);
170
+ }
56
171
  function isInteger(n) {
57
- return typeof n === "number" && isFinite(n) && n === Math.trunc(n);
172
+ return typeof n === "number" && isFinite2(n) && n === Math.trunc(n);
58
173
  }
59
- function linearToDecibels(linearVolume) {
60
- if (!isFinite(linearVolume)) {
61
- throw new Error("linearToDecibel: Invalid linearVolume = " + linearVolume);
62
- } else if (linearVolume <= 0) {
63
- return -Infinity;
64
- } else {
65
- return 20 * Math.log10(linearVolume);
66
- }
174
+ function isIntegerOrUndefined(n) {
175
+ return typeof n === "number" && isFinite2(n) && n === Math.trunc(n) || n === void 0;
67
176
  }
68
- function mod(m, n) {
69
- return (m % n + n) % n;
177
+ function isIntegerEq(value, compareTo) {
178
+ return isInteger(value) && value === compareTo;
70
179
  }
71
- function romanize(n) {
72
- if (!isInteger(n) || n < 0) {
73
- throw new Error("romanize: Invalid n = " + n);
74
- }
75
- var digits = String(+n).split("");
76
- var key = [
77
- "",
78
- "C",
79
- "CC",
80
- "CCC",
81
- "CD",
82
- "D",
83
- "DC",
84
- "DCC",
85
- "DCCC",
86
- "CM",
87
- "",
88
- "X",
89
- "XX",
90
- "XXX",
91
- "XL",
92
- "L",
93
- "LX",
94
- "LXX",
95
- "LXXX",
96
- "XC",
97
- "",
98
- "I",
99
- "II",
100
- "III",
101
- "IV",
102
- "V",
103
- "VI",
104
- "VII",
105
- "VIII",
106
- "IX"
107
- ];
108
- var roman = "", i = 3;
109
- while (i--) roman = (key[+digits.pop() + i * 10] || "") + roman;
110
- return Array(+digits.join("") + 1).join("M") + roman;
180
+ function isIntegerGt(value, compareTo) {
181
+ return isInteger(value) && value > compareTo;
111
182
  }
112
- function toOrdinalNumber(n) {
113
- if (!isInteger(n)) {
114
- throw new Error("toOrdinalNumber: Invalid n = " + n);
115
- }
116
- const nStr = n.toString();
117
- const lastDigit = Number(nStr.charAt(nStr.length - 1));
118
- if (n === 1 || n >= 20 && lastDigit === 1) {
119
- return nStr + "st";
120
- } else if (n === 2 || n >= 20 && lastDigit === 2) {
121
- return nStr + "nd";
122
- } else if (n === 3 || n >= 20 && lastDigit === 3) {
123
- return nStr + "rd";
124
- } else {
125
- return nStr + "th";
126
- }
183
+ function isIntegerGte(value, compareTo) {
184
+ return isInteger(value) && value >= compareTo;
127
185
  }
128
- function interpolateCoord(startX, startY, endX, endY, t) {
129
- return {
130
- x: startX + (endX - startX) * t,
131
- y: startY + (endY - startY) * t
132
- };
186
+ function isIntegerLt(value, compareTo) {
187
+ return isInteger(value) && value < compareTo;
133
188
  }
134
- function interpolateY(startX, startY, endX, endY, x) {
135
- let t = (x - startX) / (endX - startX);
136
- return startY + (endY - startY) * t;
189
+ function isIntegerLte(value, compareTo) {
190
+ return isInteger(value) && value <= compareTo;
137
191
  }
138
- function clamp(num, min, max) {
139
- return Math.min(Math.max(num, min), max);
192
+ function isIntegerBetween(value, min, max) {
193
+ return isInteger(value) && value >= min && value <= max;
140
194
  }
141
- function calcNormal(x1, y1, x2, y2) {
142
- let dx = x2 - x1;
143
- let dy = y2 - y1;
144
- let nx = -dy;
145
- let ny = dx;
146
- let len = Math.sqrt(nx * nx + ny * ny);
147
- if (len > 0) {
148
- nx /= len;
149
- ny /= len;
150
- } else {
151
- nx = 0;
152
- ny = 1;
153
- }
154
- return { nx, ny };
195
+ function isNaNValue(value) {
196
+ return typeof value === "number" && Number.isNaN(value);
155
197
  }
156
- function sum(arr) {
157
- return arr.reduce((prev, cur) => cur + prev, 0);
198
+ function isInfinity(value) {
199
+ return typeof value === "number" && Math.abs(value) === Infinity;
158
200
  }
159
- function avg(...values) {
160
- return sum(values) / values.length;
201
+ function isPosInfinity(value) {
202
+ return typeof value === "number" && value === Infinity;
161
203
  }
162
- function cmp(a, b) {
163
- return a < b ? -1 : a > b ? 1 : 0;
204
+ function isNegInfinity(value) {
205
+ return typeof value === "number" && value === -Infinity;
164
206
  }
165
207
 
166
208
  // src/utils/arr/index.ts
167
- function isArray(a) {
168
- return !!a && Object.prototype.toString.call(a) === "[object Array]";
169
- }
170
209
  function toArray(a) {
171
210
  return isArray(a) ? a : [a];
172
211
  }
@@ -253,15 +292,6 @@ __export(dom_exports, {
253
292
  styleLayoutChanged: () => styleLayoutChanged
254
293
  });
255
294
 
256
- // src/utils/enum/index.ts
257
- var enum_exports = {};
258
- __export(enum_exports, {
259
- getEnumValues: () => getEnumValues
260
- });
261
- function getEnumValues(e) {
262
- return Object.keys(e).filter((key) => Number.isNaN(Number(key))).map((key) => e[key]);
263
- }
264
-
265
295
  // src/modules/assert.ts
266
296
  var Assert;
267
297
  ((Assert2) => {
@@ -681,172 +711,139 @@ function getCanvasTextWidth(text, font) {
681
711
  return ctx.measureText(text).width;
682
712
  }
683
713
 
684
- // src/utils/is/index.ts
685
- var is_exports = {};
686
- __export(is_exports, {
687
- isArray: () => isArray2,
688
- isArrayOrUndefined: () => isArrayOrUndefined,
689
- isBoolean: () => isBoolean,
690
- isBooleanOrUndefined: () => isBooleanOrUndefined,
691
- isEmptyArray: () => isEmptyArray,
692
- isEmptyArrayOrUndefined: () => isEmptyArrayOrUndefined,
693
- isEmptyString: () => isEmptyString,
694
- isEmptyStringOrUndefined: () => isEmptyStringOrUndefined,
695
- isEnumValue: () => isEnumValue,
696
- isEnumValueOrUndefined: () => isEnumValueOrUndefined,
697
- isFinite: () => isFinite2,
698
- isFunction: () => isFunction,
699
- isFunctionOrUndefined: () => isFunctionOrUndefined,
700
- isInfinity: () => isInfinity,
701
- isInteger: () => isInteger2,
702
- isIntegerBetween: () => isIntegerBetween,
703
- isIntegerEq: () => isIntegerEq,
704
- isIntegerGt: () => isIntegerGt,
705
- isIntegerGte: () => isIntegerGte,
706
- isIntegerLt: () => isIntegerLt,
707
- isIntegerLte: () => isIntegerLte,
708
- isIntegerOrUndefined: () => isIntegerOrUndefined,
709
- isNaNValue: () => isNaNValue,
710
- isNegInfinity: () => isNegInfinity,
711
- isNonEmptyArray: () => isNonEmptyArray,
712
- isNonEmptyArrayOrUndefined: () => isNonEmptyArrayOrUndefined,
713
- isNonEmptyString: () => isNonEmptyString,
714
- isNonEmptyStringOrUndefined: () => isNonEmptyStringOrUndefined,
715
- isNull: () => isNull,
716
- isNullish: () => isNullish,
717
- isNumber: () => isNumber,
718
- isNumberOrUndefined: () => isNumberOrUndefined,
719
- isObject: () => isObject,
720
- isObjectOrUndefined: () => isObjectOrUndefined,
721
- isPosInfinity: () => isPosInfinity,
722
- isString: () => isString,
723
- isStringOrUndefined: () => isStringOrUndefined,
724
- isUndefined: () => isUndefined
714
+ // src/utils/map/index.ts
715
+ var map_exports = {};
716
+ __export(map_exports, {
717
+ getMapKeys: () => getMapKeys
725
718
  });
726
- function isUndefined(value) {
727
- return value === void 0;
728
- }
729
- function isNull(value) {
730
- return value === null;
731
- }
732
- function isNullish(value) {
733
- return value === void 0 || value === null;
734
- }
735
- function isObject(value) {
736
- return typeof value === "object" && value !== null && !isArray2(value);
737
- }
738
- function isObjectOrUndefined(value) {
739
- return value === void 0 || isObject(value);
740
- }
741
- function isArray2(a) {
742
- return !!a && Object.prototype.toString.call(a) === "[object Array]";
743
- }
744
- function isArrayOrUndefined(value) {
745
- return value === void 0 || isArray2(value);
746
- }
747
- function isEmptyArray(a) {
748
- return isArray2(a) && a.length === 0;
749
- }
750
- function isNonEmptyArray(a) {
751
- return isArray2(a) && a.length > 0;
752
- }
753
- function isEmptyArrayOrUndefined(a) {
754
- return isArray2(a) && a.length === 0 || a === void 0;
755
- }
756
- function isNonEmptyArrayOrUndefined(a) {
757
- return isArray2(a) && a.length > 0 || a === void 0;
758
- }
759
- function isString(value) {
760
- return typeof value === "string";
761
- }
762
- function isEmptyString(value) {
763
- return typeof value === "string" && value.length === 0;
764
- }
765
- function isNonEmptyString(value) {
766
- return typeof value === "string" && value.length > 0;
767
- }
768
- function isStringOrUndefined(value) {
769
- return value === void 0 || typeof value === "string";
770
- }
771
- function isEmptyStringOrUndefined(value) {
772
- return typeof value === "string" && value.length === 0 || value === void 0;
773
- }
774
- function isNonEmptyStringOrUndefined(value) {
775
- return typeof value === "string" && value.length > 0 || value === void 0;
776
- }
777
- function isBoolean(value) {
778
- return typeof value === "boolean";
779
- }
780
- function isBooleanOrUndefined(value) {
781
- return value === void 0 || typeof value === "boolean";
782
- }
783
- function isFunction(value) {
784
- return typeof value === "function";
785
- }
786
- function isFunctionOrUndefined(value) {
787
- return value === void 0 || typeof value === "function";
788
- }
789
- function isEnumValue(value, enumObj, name = "value") {
790
- return getEnumValues(enumObj).some((v) => v === value);
791
- }
792
- function isEnumValueOrUndefined(value, enumObj, name = "value") {
793
- return value === void 0 || getEnumValues(enumObj).some((v) => v === value);
794
- }
795
- function isNumber(value) {
796
- return typeof value === "number";
797
- }
798
- function isNumberOrUndefined(value) {
799
- return typeof value === "number" || value === void 0;
800
- }
801
- function isFinite2(value) {
802
- return typeof value === "number" && Number.isFinite(value);
803
- }
804
- function isInteger2(n) {
805
- return typeof n === "number" && isFinite2(n) && n === Math.trunc(n);
806
- }
807
- function isIntegerOrUndefined(n) {
808
- return typeof n === "number" && isFinite2(n) && n === Math.trunc(n) || n === void 0;
719
+ function getMapKeys(map) {
720
+ let keys = [];
721
+ map.forEach((value, key) => keys.push(key));
722
+ return keys;
809
723
  }
810
- function isIntegerEq(value, compareTo) {
811
- return isInteger2(value) && value === compareTo;
724
+
725
+ // src/utils/math/index.ts
726
+ var math_exports = {};
727
+ __export(math_exports, {
728
+ avg: () => avg,
729
+ calcNormal: () => calcNormal,
730
+ clamp: () => clamp,
731
+ cmp: () => cmp,
732
+ interpolateCoord: () => interpolateCoord,
733
+ interpolateY: () => interpolateY,
734
+ isInteger: () => isInteger,
735
+ isNumber: () => isNumber,
736
+ linearToDecibels: () => linearToDecibels,
737
+ mod: () => mod,
738
+ romanize: () => romanize,
739
+ sum: () => sum,
740
+ toOrdinalNumber: () => toOrdinalNumber
741
+ });
742
+ function linearToDecibels(linearVolume) {
743
+ if (!isFinite(linearVolume)) {
744
+ throw new Error("linearToDecibel: Invalid linearVolume = " + linearVolume);
745
+ } else if (linearVolume <= 0) {
746
+ return -Infinity;
747
+ } else {
748
+ return 20 * Math.log10(linearVolume);
749
+ }
812
750
  }
813
- function isIntegerGt(value, compareTo) {
814
- return isInteger2(value) && value > compareTo;
751
+ function mod(m, n) {
752
+ return (m % n + n) % n;
815
753
  }
816
- function isIntegerGte(value, compareTo) {
817
- return isInteger2(value) && value >= compareTo;
754
+ function romanize(n) {
755
+ if (!isInteger(n) || n < 0) {
756
+ throw new Error("romanize: Invalid n = " + n);
757
+ }
758
+ var digits = String(+n).split("");
759
+ var key = [
760
+ "",
761
+ "C",
762
+ "CC",
763
+ "CCC",
764
+ "CD",
765
+ "D",
766
+ "DC",
767
+ "DCC",
768
+ "DCCC",
769
+ "CM",
770
+ "",
771
+ "X",
772
+ "XX",
773
+ "XXX",
774
+ "XL",
775
+ "L",
776
+ "LX",
777
+ "LXX",
778
+ "LXXX",
779
+ "XC",
780
+ "",
781
+ "I",
782
+ "II",
783
+ "III",
784
+ "IV",
785
+ "V",
786
+ "VI",
787
+ "VII",
788
+ "VIII",
789
+ "IX"
790
+ ];
791
+ var roman = "", i = 3;
792
+ while (i--) roman = (key[+digits.pop() + i * 10] || "") + roman;
793
+ return Array(+digits.join("") + 1).join("M") + roman;
818
794
  }
819
- function isIntegerLt(value, compareTo) {
820
- return isInteger2(value) && value < compareTo;
795
+ function toOrdinalNumber(n) {
796
+ if (!isInteger(n)) {
797
+ throw new Error("toOrdinalNumber: Invalid n = " + n);
798
+ }
799
+ const nStr = n.toString();
800
+ const lastDigit = Number(nStr.charAt(nStr.length - 1));
801
+ if (n === 1 || n >= 20 && lastDigit === 1) {
802
+ return nStr + "st";
803
+ } else if (n === 2 || n >= 20 && lastDigit === 2) {
804
+ return nStr + "nd";
805
+ } else if (n === 3 || n >= 20 && lastDigit === 3) {
806
+ return nStr + "rd";
807
+ } else {
808
+ return nStr + "th";
809
+ }
821
810
  }
822
- function isIntegerLte(value, compareTo) {
823
- return isInteger2(value) && value <= compareTo;
811
+ function interpolateCoord(startX, startY, endX, endY, t) {
812
+ return {
813
+ x: startX + (endX - startX) * t,
814
+ y: startY + (endY - startY) * t
815
+ };
824
816
  }
825
- function isIntegerBetween(value, min, max) {
826
- return isInteger2(value) && value >= min && value <= max;
817
+ function interpolateY(startX, startY, endX, endY, x) {
818
+ let t = (x - startX) / (endX - startX);
819
+ return startY + (endY - startY) * t;
827
820
  }
828
- function isNaNValue(value) {
829
- return typeof value === "number" && Number.isNaN(value);
821
+ function clamp(num, min, max) {
822
+ return Math.min(Math.max(num, min), max);
830
823
  }
831
- function isInfinity(value) {
832
- return typeof value === "number" && Math.abs(value) === Infinity;
824
+ function calcNormal(x1, y1, x2, y2) {
825
+ let dx = x2 - x1;
826
+ let dy = y2 - y1;
827
+ let nx = -dy;
828
+ let ny = dx;
829
+ let len = Math.sqrt(nx * nx + ny * ny);
830
+ if (len > 0) {
831
+ nx /= len;
832
+ ny /= len;
833
+ } else {
834
+ nx = 0;
835
+ ny = 1;
836
+ }
837
+ return { nx, ny };
833
838
  }
834
- function isPosInfinity(value) {
835
- return typeof value === "number" && value === Infinity;
839
+ function sum(arr) {
840
+ return arr.reduce((prev, cur) => cur + prev, 0);
836
841
  }
837
- function isNegInfinity(value) {
838
- return typeof value === "number" && value === -Infinity;
842
+ function avg(...values) {
843
+ return sum(values) / values.length;
839
844
  }
840
-
841
- // src/utils/map/index.ts
842
- var map_exports = {};
843
- __export(map_exports, {
844
- getMapKeys: () => getMapKeys
845
- });
846
- function getMapKeys(map) {
847
- let keys = [];
848
- map.forEach((value, key) => keys.push(key));
849
- return keys;
845
+ function cmp(a, b) {
846
+ return a < b ? -1 : a > b ? 1 : 0;
850
847
  }
851
848
 
852
849
  // src/utils/obj/index.ts
@@ -854,13 +851,10 @@ var obj_exports = {};
854
851
  __export(obj_exports, {
855
852
  deepEqual: () => deepEqual,
856
853
  hasProperties: () => hasProperties,
857
- isObject: () => isObject2
854
+ isObject: () => isObject
858
855
  });
859
- function isObject2(obj) {
860
- return typeof obj === "object" && obj !== null && !isArray(obj);
861
- }
862
856
  function hasProperties(obj, props) {
863
- return isObject2(obj) && props.every((p) => p in obj);
857
+ return isObject(obj) && props.every((p) => p in obj);
864
858
  }
865
859
  function deepEqual(a, b) {
866
860
  if (a === b) return true;
@@ -887,6 +881,7 @@ __export(str_exports, {
887
881
  charCount: () => charCount,
888
882
  chunkString: () => chunkString,
889
883
  insertAt: () => insertAt,
884
+ isString: () => isString,
890
885
  makeSentenceFromPascal: () => makeSentenceFromPascal,
891
886
  removeAt: () => removeAt,
892
887
  repeatString: () => repeatString,
@@ -1262,6 +1257,444 @@ var SmallIntCache = class {
1262
1257
  }
1263
1258
  };
1264
1259
 
1260
+ // src/core/index-array.ts
1261
+ var IndexArray = class _IndexArray {
1262
+ constructor(entries) {
1263
+ // for indexes >= 0
1264
+ __publicField(this, "posEl");
1265
+ __publicField(this, "hasPos");
1266
+ // number of elems
1267
+ __publicField(this, "elCount");
1268
+ if (entries instanceof _IndexArray) {
1269
+ this.posEl = entries.posEl.slice();
1270
+ this.hasPos = entries.hasPos.slice();
1271
+ this.elCount = entries.elCount;
1272
+ } else {
1273
+ this.posEl = [];
1274
+ this.hasPos = [];
1275
+ this.elCount = 0;
1276
+ if (entries) {
1277
+ for (const [id, el] of entries) {
1278
+ this.set(id, el);
1279
+ }
1280
+ }
1281
+ }
1282
+ }
1283
+ static toNegIndex(id) {
1284
+ return -id - 1;
1285
+ }
1286
+ static validateIndex(id) {
1287
+ if (!isIntegerGte(id, 0)) throw new Error(`Invalid index ${id} - must be an integer >= 0!`);
1288
+ return id;
1289
+ }
1290
+ get size() {
1291
+ return this.elCount;
1292
+ }
1293
+ get posLen() {
1294
+ return this.hasPos.length;
1295
+ }
1296
+ has(id) {
1297
+ _IndexArray.validateIndex(id);
1298
+ return this.hasPos[id] === true;
1299
+ }
1300
+ set(id, el) {
1301
+ _IndexArray.validateIndex(id);
1302
+ if (this.hasPos[id] !== true) this.elCount++;
1303
+ this.posEl[id] = el;
1304
+ this.hasPos[id] = true;
1305
+ }
1306
+ get(id) {
1307
+ _IndexArray.validateIndex(id);
1308
+ return this.hasPos[id] ? this.posEl[id] : void 0;
1309
+ }
1310
+ getOrDefault(id, defaultValue) {
1311
+ return this.get(id) ?? defaultValue;
1312
+ }
1313
+ getOrCreate(id, creatorOrValue) {
1314
+ if (!this.has(id)) {
1315
+ const value = isFunction(creatorOrValue) ? creatorOrValue() : creatorOrValue;
1316
+ this.set(id, value);
1317
+ return value;
1318
+ }
1319
+ return this.get(id);
1320
+ }
1321
+ delete(id) {
1322
+ _IndexArray.validateIndex(id);
1323
+ if (!this.hasPos[id]) return false;
1324
+ this.posEl[id] = void 0;
1325
+ this.hasPos[id] = false;
1326
+ this.elCount--;
1327
+ return true;
1328
+ }
1329
+ clear() {
1330
+ this.posEl = [];
1331
+ this.hasPos = [];
1332
+ this.elCount = 0;
1333
+ }
1334
+ forEach(callbackfn, thisArg) {
1335
+ for (const [id, el] of this.entries()) {
1336
+ callbackfn.call(thisArg, el, id, this);
1337
+ }
1338
+ }
1339
+ *indices() {
1340
+ for (let id = 0; id < this.posLen; id++) {
1341
+ if (this.hasPos[id]) yield id;
1342
+ }
1343
+ }
1344
+ indicesArray() {
1345
+ return [...this.indices()];
1346
+ }
1347
+ *values() {
1348
+ for (let id = 0; id < this.posLen; id++) {
1349
+ if (this.hasPos[id]) yield this.posEl[id];
1350
+ }
1351
+ }
1352
+ valuesArray() {
1353
+ return [...this.values()];
1354
+ }
1355
+ *entries() {
1356
+ for (let id = 0; id < this.posLen; id++) {
1357
+ if (this.hasPos[id]) yield [id, this.posEl[id]];
1358
+ }
1359
+ }
1360
+ entriesArray() {
1361
+ return [...this.entries()];
1362
+ }
1363
+ *[Symbol.iterator]() {
1364
+ yield* this.entries();
1365
+ }
1366
+ clone() {
1367
+ return new _IndexArray(this);
1368
+ }
1369
+ merge(other, conflictResolver) {
1370
+ for (const [id, value] of other.entries()) {
1371
+ if (this.has(id) && conflictResolver) {
1372
+ this.set(id, conflictResolver(this.get(id), value, id));
1373
+ } else {
1374
+ this.set(id, value);
1375
+ }
1376
+ }
1377
+ return this;
1378
+ }
1379
+ some(fn) {
1380
+ for (const [id, el] of this.entries()) {
1381
+ if (fn(el, id)) return true;
1382
+ }
1383
+ return false;
1384
+ }
1385
+ every(fn) {
1386
+ for (const [id, el] of this.entries()) {
1387
+ if (!fn(el, id)) return false;
1388
+ }
1389
+ return true;
1390
+ }
1391
+ filter(fn) {
1392
+ let result = new _IndexArray();
1393
+ for (const [id, el] of this.entries()) {
1394
+ if (fn(el, id)) result.set(id, el);
1395
+ }
1396
+ return result;
1397
+ }
1398
+ reduce(fn, init) {
1399
+ let iterator = this.entries();
1400
+ let first = iterator.next();
1401
+ if (first.done) {
1402
+ if (arguments.length < 2) {
1403
+ throw new TypeError("Reduce of empty IndexArray with no initial value!");
1404
+ }
1405
+ return init;
1406
+ }
1407
+ let acc;
1408
+ let start;
1409
+ if (arguments.length < 2) {
1410
+ acc = first.value[1];
1411
+ start = iterator.next();
1412
+ } else {
1413
+ acc = init;
1414
+ start = first;
1415
+ }
1416
+ for (let current = start; !current.done; current = iterator.next()) {
1417
+ const [id, el] = current.value;
1418
+ acc = fn(acc, el, id);
1419
+ }
1420
+ return acc;
1421
+ }
1422
+ mapToArray(fn) {
1423
+ let result = [];
1424
+ for (const [id, el] of this.entries()) {
1425
+ result.push(fn(el, id));
1426
+ }
1427
+ return result;
1428
+ }
1429
+ map(fn) {
1430
+ let result = new _IndexArray();
1431
+ for (const [id, el] of this.entries()) {
1432
+ result.set(id, fn(el, id));
1433
+ }
1434
+ return result;
1435
+ }
1436
+ equals(other, eq) {
1437
+ if (this.size !== other.size) return false;
1438
+ eq ?? (eq = (a, b) => a === b);
1439
+ const posLen = Math.max(this.posLen, other.posLen);
1440
+ for (let i = 0; i < posLen; ++i) {
1441
+ const hasA = this.hasPos[i];
1442
+ const hasB = other.hasPos[i];
1443
+ if (hasA !== hasB) return false;
1444
+ if (hasA && !eq(this.posEl[i], other.posEl[i])) return false;
1445
+ }
1446
+ return true;
1447
+ }
1448
+ toString() {
1449
+ if (this.size === 0) return `IndexArray[ ]`;
1450
+ const entries = this.entriesArray().map(([id, el]) => `${id}: ${el}`).join(", ");
1451
+ return `IndexArray[ ${entries} ]`;
1452
+ }
1453
+ };
1454
+
1455
+ // src/core/signed-index-array.ts
1456
+ var SignedIndexArray = class _SignedIndexArray {
1457
+ constructor(entries) {
1458
+ // for indexes >= 0
1459
+ __publicField(this, "posEl");
1460
+ __publicField(this, "hasPos");
1461
+ // for indexes < 0
1462
+ __publicField(this, "negEl");
1463
+ __publicField(this, "hasNeg");
1464
+ // number of elems
1465
+ __publicField(this, "elCount");
1466
+ if (entries instanceof _SignedIndexArray) {
1467
+ this.negEl = entries.negEl.slice();
1468
+ this.hasNeg = entries.hasNeg.slice();
1469
+ this.posEl = entries.posEl.slice();
1470
+ this.hasPos = entries.hasPos.slice();
1471
+ this.elCount = entries.elCount;
1472
+ } else {
1473
+ this.negEl = [];
1474
+ this.hasNeg = [];
1475
+ this.posEl = [];
1476
+ this.hasPos = [];
1477
+ this.elCount = 0;
1478
+ if (entries) {
1479
+ for (const [id, el] of entries) {
1480
+ this.set(id, el);
1481
+ }
1482
+ }
1483
+ }
1484
+ }
1485
+ static toNegIndex(id) {
1486
+ return -id - 1;
1487
+ }
1488
+ static validateIndex(id) {
1489
+ if (!isInteger(id)) throw new Error(`Invalid index ${id} - must be an integer!`);
1490
+ return id;
1491
+ }
1492
+ get size() {
1493
+ return this.elCount;
1494
+ }
1495
+ get posLen() {
1496
+ return this.hasPos.length;
1497
+ }
1498
+ get negLen() {
1499
+ return this.hasNeg.length;
1500
+ }
1501
+ has(id) {
1502
+ _SignedIndexArray.validateIndex(id);
1503
+ if (id >= 0) {
1504
+ return this.hasPos[id] === true;
1505
+ } else {
1506
+ return this.hasNeg[_SignedIndexArray.toNegIndex(id)] === true;
1507
+ }
1508
+ }
1509
+ set(id, el) {
1510
+ _SignedIndexArray.validateIndex(id);
1511
+ if (id >= 0) {
1512
+ if (this.hasPos[id] !== true) this.elCount++;
1513
+ this.posEl[id] = el;
1514
+ this.hasPos[id] = true;
1515
+ } else {
1516
+ let negId = _SignedIndexArray.toNegIndex(id);
1517
+ if (this.hasNeg[negId] !== true) this.elCount++;
1518
+ this.negEl[negId] = el;
1519
+ this.hasNeg[negId] = true;
1520
+ }
1521
+ }
1522
+ get(id) {
1523
+ _SignedIndexArray.validateIndex(id);
1524
+ if (id >= 0) {
1525
+ return this.hasPos[id] ? this.posEl[id] : void 0;
1526
+ } else {
1527
+ let negId = _SignedIndexArray.toNegIndex(id);
1528
+ return this.hasNeg[negId] ? this.negEl[negId] : void 0;
1529
+ }
1530
+ }
1531
+ getOrDefault(id, defaultValue) {
1532
+ return this.get(id) ?? defaultValue;
1533
+ }
1534
+ getOrCreate(id, creatorOrValue) {
1535
+ if (!this.has(id)) {
1536
+ const value = isFunction(creatorOrValue) ? creatorOrValue() : creatorOrValue;
1537
+ this.set(id, value);
1538
+ return value;
1539
+ }
1540
+ return this.get(id);
1541
+ }
1542
+ delete(id) {
1543
+ _SignedIndexArray.validateIndex(id);
1544
+ const isPos = id >= 0;
1545
+ const arr = isPos ? this.posEl : this.negEl;
1546
+ const has = isPos ? this.hasPos : this.hasNeg;
1547
+ const idx = isPos ? id : _SignedIndexArray.toNegIndex(id);
1548
+ if (!has[idx]) return false;
1549
+ arr[idx] = void 0;
1550
+ has[idx] = false;
1551
+ this.elCount--;
1552
+ return true;
1553
+ }
1554
+ clear() {
1555
+ this.negEl = [];
1556
+ this.hasNeg = [];
1557
+ this.posEl = [];
1558
+ this.hasPos = [];
1559
+ this.elCount = 0;
1560
+ }
1561
+ forEach(callbackfn, thisArg) {
1562
+ for (const [id, el] of this.entries()) {
1563
+ callbackfn.call(thisArg, el, id, this);
1564
+ }
1565
+ }
1566
+ *indices() {
1567
+ for (let id = this.negLen - 1; id >= 0; id--) {
1568
+ if (this.hasNeg[id]) yield _SignedIndexArray.toNegIndex(id);
1569
+ }
1570
+ for (let id = 0; id < this.posLen; id++) {
1571
+ if (this.hasPos[id]) yield id;
1572
+ }
1573
+ }
1574
+ indicesArray() {
1575
+ return [...this.indices()];
1576
+ }
1577
+ *values() {
1578
+ for (let id = this.negLen - 1; id >= 0; id--) {
1579
+ if (this.hasNeg[id]) yield this.negEl[id];
1580
+ }
1581
+ for (let id = 0; id < this.posLen; id++) {
1582
+ if (this.hasPos[id]) yield this.posEl[id];
1583
+ }
1584
+ }
1585
+ valuesArray() {
1586
+ return [...this.values()];
1587
+ }
1588
+ *entries() {
1589
+ for (let id = this.negLen - 1; id >= 0; id--) {
1590
+ if (this.hasNeg[id]) yield [_SignedIndexArray.toNegIndex(id), this.negEl[id]];
1591
+ }
1592
+ for (let id = 0; id < this.posLen; id++) {
1593
+ if (this.hasPos[id]) yield [id, this.posEl[id]];
1594
+ }
1595
+ }
1596
+ entriesArray() {
1597
+ return [...this.entries()];
1598
+ }
1599
+ *[Symbol.iterator]() {
1600
+ yield* this.entries();
1601
+ }
1602
+ clone() {
1603
+ return new _SignedIndexArray(this);
1604
+ }
1605
+ merge(other, conflictResolver) {
1606
+ for (const [id, value] of other.entries()) {
1607
+ if (this.has(id) && conflictResolver) {
1608
+ this.set(id, conflictResolver(this.get(id), value, id));
1609
+ } else {
1610
+ this.set(id, value);
1611
+ }
1612
+ }
1613
+ return this;
1614
+ }
1615
+ some(fn) {
1616
+ for (const [id, el] of this.entries()) {
1617
+ if (fn(el, id)) return true;
1618
+ }
1619
+ return false;
1620
+ }
1621
+ every(fn) {
1622
+ for (const [id, el] of this.entries()) {
1623
+ if (!fn(el, id)) return false;
1624
+ }
1625
+ return true;
1626
+ }
1627
+ filter(fn) {
1628
+ let result = new _SignedIndexArray();
1629
+ for (const [id, el] of this.entries()) {
1630
+ if (fn(el, id)) result.set(id, el);
1631
+ }
1632
+ return result;
1633
+ }
1634
+ reduce(fn, init) {
1635
+ let iterator = this.entries();
1636
+ let first = iterator.next();
1637
+ if (first.done) {
1638
+ if (arguments.length < 2) {
1639
+ throw new TypeError("Reduce of empty SignedIndexArray with no initial value!");
1640
+ }
1641
+ return init;
1642
+ }
1643
+ let acc;
1644
+ let start;
1645
+ if (arguments.length < 2) {
1646
+ acc = first.value[1];
1647
+ start = iterator.next();
1648
+ } else {
1649
+ acc = init;
1650
+ start = first;
1651
+ }
1652
+ for (let current = start; !current.done; current = iterator.next()) {
1653
+ const [id, el] = current.value;
1654
+ acc = fn(acc, el, id);
1655
+ }
1656
+ return acc;
1657
+ }
1658
+ mapToArray(fn) {
1659
+ let result = [];
1660
+ for (const [id, el] of this.entries()) {
1661
+ result.push(fn(el, id));
1662
+ }
1663
+ return result;
1664
+ }
1665
+ map(fn) {
1666
+ let result = new _SignedIndexArray();
1667
+ for (const [id, el] of this.entries()) {
1668
+ result.set(id, fn(el, id));
1669
+ }
1670
+ return result;
1671
+ }
1672
+ equals(other, eq) {
1673
+ if (this.size !== other.size) return false;
1674
+ eq ?? (eq = (a, b) => a === b);
1675
+ const posLen = Math.max(this.posLen, other.posLen);
1676
+ for (let i = 0; i < posLen; ++i) {
1677
+ const hasA = this.hasPos[i];
1678
+ const hasB = other.hasPos[i];
1679
+ if (hasA !== hasB) return false;
1680
+ if (hasA && !eq(this.posEl[i], other.posEl[i])) return false;
1681
+ }
1682
+ const negLen = Math.max(this.negLen, other.negLen);
1683
+ for (let i = 0; i < negLen; ++i) {
1684
+ const hasA = this.hasNeg[i];
1685
+ const hasB = other.hasNeg[i];
1686
+ if (hasA !== hasB) return false;
1687
+ if (hasA && !eq(this.negEl[i], other.negEl[i])) return false;
1688
+ }
1689
+ return true;
1690
+ }
1691
+ toString() {
1692
+ if (this.size === 0) return `SignedIndexArray[ ]`;
1693
+ const entries = this.entriesArray().map(([id, el]) => `${id}: ${el}`).join(", ");
1694
+ return `SignedIndexArray[ ${entries} ]`;
1695
+ }
1696
+ };
1697
+
1265
1698
  // src/core/map.ts
1266
1699
  var Map1 = class _Map1 {
1267
1700
  constructor(entries) {
@@ -1281,12 +1714,13 @@ var Map1 = class _Map1 {
1281
1714
  getOrDefault(key1, defaultValue) {
1282
1715
  return this.get(key1) ?? defaultValue;
1283
1716
  }
1284
- getOrCreate(key1, creator) {
1285
- let value = this.get(key1);
1286
- if (!value) {
1287
- this.set(key1, value = creator());
1717
+ getOrCreate(key1, creatorOrValue) {
1718
+ if (!this.has(key1)) {
1719
+ const value = isFunction(creatorOrValue) ? creatorOrValue() : creatorOrValue;
1720
+ this.set(key1, value);
1721
+ return value;
1288
1722
  }
1289
- return value;
1723
+ return this.get(key1);
1290
1724
  }
1291
1725
  delete(key1) {
1292
1726
  return this.map1.delete(key1);
@@ -1410,12 +1844,13 @@ var Map2 = class _Map2 {
1410
1844
  getOrDefault(key1, key2, defaultValue) {
1411
1845
  return this.get(key1, key2) ?? defaultValue;
1412
1846
  }
1413
- getOrCreate(key1, key2, creator) {
1414
- let value = this.get(key1, key2);
1415
- if (!value) {
1416
- this.set(key1, key2, value = creator());
1847
+ getOrCreate(key1, key2, creatorOrValue) {
1848
+ if (!this.has(key1, key2)) {
1849
+ const value = isFunction(creatorOrValue) ? creatorOrValue() : creatorOrValue;
1850
+ this.set(key1, key2, value);
1851
+ return value;
1417
1852
  }
1418
- return value;
1853
+ return this.get(key1, key2);
1419
1854
  }
1420
1855
  delete(key1, key2) {
1421
1856
  if (key2 === void 0) return this.map1.delete(key1);
@@ -1586,12 +2021,13 @@ var Map3 = class _Map3 {
1586
2021
  getOrDefault(key1, key2, key3, defaultValue) {
1587
2022
  return this.get(key1, key2, key3) ?? defaultValue;
1588
2023
  }
1589
- getOrCreate(key1, key2, key3, creator) {
1590
- let value = this.get(key1, key2, key3);
1591
- if (!value) {
1592
- this.set(key1, key2, key3, value = creator());
2024
+ getOrCreate(key1, key2, key3, creatorOrValue) {
2025
+ if (!this.has(key1, key2, key3)) {
2026
+ const value = isFunction(creatorOrValue) ? creatorOrValue() : creatorOrValue;
2027
+ this.set(key1, key2, key3, value);
2028
+ return value;
1593
2029
  }
1594
- return value;
2030
+ return this.get(key1, key2, key3);
1595
2031
  }
1596
2032
  delete(key1, key2, key3) {
1597
2033
  if (key3 === void 0) {
@@ -1756,17 +2192,61 @@ var Map3 = class _Map3 {
1756
2192
  return `Map3(${this.size}) { ${entries.join(", ")} }`;
1757
2193
  }
1758
2194
  };
2195
+
2196
+ // src/core/multi-container.ts
2197
+ var MultiContainer = class {
2198
+ constructor(base) {
2199
+ this.base = base;
2200
+ }
2201
+ add(...keysAndValue) {
2202
+ const keys = keysAndValue.slice(0, -1);
2203
+ const value = keysAndValue[keysAndValue.length - 1];
2204
+ const arr = this.base.get(...keys);
2205
+ this.base.set(...[...keys, arr ? [...arr, value] : [value]]);
2206
+ return value;
2207
+ }
2208
+ remove(...keysAndValue) {
2209
+ const keys = keysAndValue.slice(0, -1);
2210
+ const value = keysAndValue[keysAndValue.length - 1];
2211
+ const arr = this.base.get(...keys);
2212
+ if (!arr) return false;
2213
+ const i = arr.indexOf(value);
2214
+ if (i === -1) return false;
2215
+ arr.splice(i, 1);
2216
+ if (arr.length === 0) this.base.delete(...keys);
2217
+ return true;
2218
+ }
2219
+ getAll(...keys) {
2220
+ return this.base.get(...keys) ?? [];
2221
+ }
2222
+ *iterAll(...keys) {
2223
+ const arr = this.getAll(...keys);
2224
+ for (const v of arr) {
2225
+ yield v;
2226
+ }
2227
+ }
2228
+ clear() {
2229
+ this.base.clear?.();
2230
+ }
2231
+ };
2232
+ function asMulti(base) {
2233
+ return new MultiContainer(base);
2234
+ }
1759
2235
  export {
1760
2236
  Assert,
1761
2237
  Cookies,
1762
2238
  Device,
2239
+ IndexArray,
1763
2240
  LRUCache,
1764
2241
  Map1,
1765
2242
  Map2,
1766
2243
  Map3,
2244
+ MultiContainer,
2245
+ SignedIndexArray,
1767
2246
  SmallIntCache,
1768
2247
  Stack,
1769
2248
  utils_exports as Utils,
1770
- Vec2
2249
+ Vec2,
2250
+ asMulti
1771
2251
  };
1772
2252
  //# sourceMappingURL=index.mjs.map