@develia/commons 0.3.19 → 0.3.21
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/develia-commons.js +281 -22
- package/dist/develia-commons.min.js +1 -1
- package/dist/index.cjs.js +281 -22
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +278 -20
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/array-manipulator.ts +53 -0
- package/src/from.ts +20 -3
- package/src/index.ts +2 -2
- package/src/lazy.ts +6 -3
- package/src/math.ts +18 -8
- package/src/pair.ts +6 -0
- package/src/string.ts +49 -0
- package/src/timer.ts +3 -0
- package/src/timespan.ts +3 -0
- package/src/{type.ts → typing.ts} +7 -2
- package/src/utilities.ts +148 -10
- package/src/strings.ts +0 -21
package/dist/develia-commons.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
(function (exports) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Represents different types in JavaScript.
|
|
6
|
+
* @enum {string}
|
|
7
|
+
*/
|
|
8
|
+
exports.Type = void 0;
|
|
5
9
|
(function (Type) {
|
|
6
10
|
Type["Undefined"] = "undefined";
|
|
7
11
|
Type["Number"] = "number";
|
|
@@ -11,9 +15,15 @@
|
|
|
11
15
|
Type["Function"] = "function";
|
|
12
16
|
Type["Symbol"] = "symbol";
|
|
13
17
|
Type["BigInt"] = "bigint";
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
Type["Null"] = "null";
|
|
19
|
+
})(exports.Type || (exports.Type = {}));
|
|
16
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Represents a pair of key and value.
|
|
23
|
+
*
|
|
24
|
+
* @template TKey The type of the key.
|
|
25
|
+
* @template TValue The type of the value.
|
|
26
|
+
*/
|
|
17
27
|
class Pair {
|
|
18
28
|
get value() {
|
|
19
29
|
return this._value;
|
|
@@ -28,55 +38,153 @@
|
|
|
28
38
|
}
|
|
29
39
|
|
|
30
40
|
// noinspection JSUnusedGlobalSymbols
|
|
41
|
+
/**
|
|
42
|
+
* Checks if an object is iterable.
|
|
43
|
+
*
|
|
44
|
+
* @param {any} obj - The object to check.
|
|
45
|
+
* @return {boolean} - Returns true if the object is iterable, otherwise false.
|
|
46
|
+
*/
|
|
31
47
|
function isIterable(obj) {
|
|
32
48
|
return obj[Symbol.iterator] === 'function';
|
|
33
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Checks if a given value is a string.
|
|
52
|
+
*
|
|
53
|
+
* @param {*} value - The value to check.
|
|
54
|
+
* @return {boolean} - Returns true if the value is a string, otherwise returns false.
|
|
55
|
+
*/
|
|
34
56
|
function isString(value) {
|
|
35
57
|
return typeof value === 'string';
|
|
36
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Checks if a value is a number.
|
|
61
|
+
*
|
|
62
|
+
* @param {any} value - The value to check.
|
|
63
|
+
* @return {boolean} - Returns true if the value is a number, otherwise false.
|
|
64
|
+
*/
|
|
37
65
|
function isNumber(value) {
|
|
38
66
|
return typeof value === 'number';
|
|
39
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Checks if a given value is a boolean.
|
|
70
|
+
*
|
|
71
|
+
* @param {any} value - The value to be checked.
|
|
72
|
+
*
|
|
73
|
+
* @return {boolean} - Returns true if the value is a boolean, otherwise false.
|
|
74
|
+
*/
|
|
40
75
|
function isBoolean(value) {
|
|
41
76
|
return typeof value === 'boolean';
|
|
42
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Checks if a value is an object.
|
|
80
|
+
* @param {any} value - The value to be checked.
|
|
81
|
+
* @returns {boolean} - Returns true if the value is an object, otherwise returns false.
|
|
82
|
+
*/
|
|
43
83
|
function isObject(value) {
|
|
44
|
-
return value
|
|
84
|
+
return value != null && typeof value === 'object' && !Array.isArray(value);
|
|
45
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Determines if a value is an array.
|
|
88
|
+
*
|
|
89
|
+
* @param value - The value to be checked.
|
|
90
|
+
*
|
|
91
|
+
* @return Whether the value is an array.
|
|
92
|
+
*/
|
|
46
93
|
function isArray(value) {
|
|
47
94
|
return Array.isArray(value);
|
|
48
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Checks if a value is a function.
|
|
98
|
+
*
|
|
99
|
+
* @param {any} value - The value to be checked.
|
|
100
|
+
* @return {boolean} - Returns true if the value is a function, otherwise returns false.
|
|
101
|
+
*/
|
|
49
102
|
function isFunction(value) {
|
|
50
103
|
return typeof value === 'function';
|
|
51
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Checks if a value is undefined.
|
|
107
|
+
*
|
|
108
|
+
* @param {any} value - The value to check.
|
|
109
|
+
* @returns {boolean} - True if the value is undefined, false otherwise.
|
|
110
|
+
*/
|
|
52
111
|
function isUndefined(value) {
|
|
53
112
|
return typeof value === 'undefined';
|
|
54
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Checks if a value is defined or not.
|
|
116
|
+
*
|
|
117
|
+
* @param {any} value - The value to be checked.
|
|
118
|
+
*
|
|
119
|
+
* @return {boolean} - True if the value is defined, false otherwise.
|
|
120
|
+
*/
|
|
55
121
|
function isDefined(value) {
|
|
56
122
|
return typeof value !== 'undefined';
|
|
57
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Checks if a given value is null.
|
|
126
|
+
*
|
|
127
|
+
* @param {any} value - The value to check for null.
|
|
128
|
+
* @return {boolean} - Returns true if the value is null, otherwise returns false.
|
|
129
|
+
*/
|
|
58
130
|
function isNull(value) {
|
|
59
131
|
return value === null;
|
|
60
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Determines whether the given value is of type bigint.
|
|
135
|
+
* @param {any} value - The value to be checked.
|
|
136
|
+
* @return {boolean} - Returns true if the value is of type bigint, false otherwise.
|
|
137
|
+
*/
|
|
61
138
|
function isBigInt(value) {
|
|
62
139
|
return typeof value === 'bigint';
|
|
63
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Checks if a given value is a symbol.
|
|
143
|
+
*
|
|
144
|
+
* @param {any} value - The value to be checked.
|
|
145
|
+
* @return {boolean} - Returns true if the value is a symbol, false otherwise.
|
|
146
|
+
*/
|
|
64
147
|
function isSymbol(value) {
|
|
65
148
|
return typeof value === 'symbol';
|
|
66
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Checks if a value is null or undefined.
|
|
152
|
+
*
|
|
153
|
+
* @param {any} value - The value to check.
|
|
154
|
+
* @return {boolean} - Returns true if the value is null or undefined, false otherwise.
|
|
155
|
+
*/
|
|
67
156
|
function isNullOrUndefined(value) {
|
|
68
157
|
return value === null || typeof value === 'undefined';
|
|
69
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Checks if a given value is empty.
|
|
161
|
+
*
|
|
162
|
+
* @param {any} value - The value to check.
|
|
163
|
+
* @return {boolean} - Returns true if the value is empty, otherwise returns false.
|
|
164
|
+
*/
|
|
70
165
|
function isEmpty(value) {
|
|
71
166
|
return (Array.isArray(value) && value.length === 0) ||
|
|
72
167
|
(typeof value === 'string' && value === '') ||
|
|
73
168
|
value === null || typeof value === 'undefined';
|
|
74
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Check if a value is empty or contains only whitespace characters.
|
|
172
|
+
*
|
|
173
|
+
* @param {any} value - The value to check.
|
|
174
|
+
* @return {boolean} Returns true if the value is empty or contains only whitespace characters, otherwise returns false.
|
|
175
|
+
*/
|
|
75
176
|
function isEmptyOrWhitespace(value) {
|
|
76
177
|
return (Array.isArray(value) && value.length === 0) ||
|
|
77
178
|
(typeof value === 'string' && value.trim() === '') ||
|
|
78
179
|
value === null || typeof value === 'undefined';
|
|
79
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Submits a form via AJAX and returns a Promise that resolves to the Response object.
|
|
183
|
+
*
|
|
184
|
+
* @param {HTMLFormElement | string} selectorOrElement - The form element or selector.
|
|
185
|
+
* @return {Promise<Response>} A Promise that resolves to the Response object.
|
|
186
|
+
* @throws {Error} If the element is invalid.
|
|
187
|
+
*/
|
|
80
188
|
async function ajaxSubmit(selectorOrElement) {
|
|
81
189
|
const form = typeof selectorOrElement === 'string'
|
|
82
190
|
? document.querySelector(selectorOrElement)
|
|
@@ -90,6 +198,12 @@
|
|
|
90
198
|
body: new FormData(form),
|
|
91
199
|
});
|
|
92
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Converts an object into an array of key-value pairs.
|
|
203
|
+
*
|
|
204
|
+
* @param {Record<string, any>} obj - The object to convert.
|
|
205
|
+
* @return {Pair<string, any>[]} - The array of key-value pairs.
|
|
206
|
+
*/
|
|
93
207
|
function toPairs(obj) {
|
|
94
208
|
let output = [];
|
|
95
209
|
for (const key in obj) {
|
|
@@ -97,6 +211,12 @@
|
|
|
97
211
|
}
|
|
98
212
|
return output;
|
|
99
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Converts a given thing into a Promise.
|
|
216
|
+
* @template T
|
|
217
|
+
* @param {any} thing - The thing to be converted into a Promise.
|
|
218
|
+
* @returns {Promise<T>} - A Promise representing the given thing.
|
|
219
|
+
*/
|
|
100
220
|
function promisify(thing) {
|
|
101
221
|
if (thing instanceof Promise)
|
|
102
222
|
return thing;
|
|
@@ -113,7 +233,7 @@
|
|
|
113
233
|
}
|
|
114
234
|
return Promise.resolve(thing);
|
|
115
235
|
}
|
|
116
|
-
function ajaxSubmission(selectorOrElement, onSuccess =
|
|
236
|
+
function ajaxSubmission(selectorOrElement, onSuccess = undefined, onFailure = undefined) {
|
|
117
237
|
const form = typeof selectorOrElement === 'string'
|
|
118
238
|
? document.querySelector(selectorOrElement)
|
|
119
239
|
: selectorOrElement;
|
|
@@ -131,6 +251,12 @@
|
|
|
131
251
|
}
|
|
132
252
|
});
|
|
133
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* Creates a deep clone of the given object.
|
|
256
|
+
* @template T
|
|
257
|
+
* @param {T} obj - The object to clone.
|
|
258
|
+
* @return {T} - The deep clone of the given object.
|
|
259
|
+
*/
|
|
134
260
|
function deepClone(obj) {
|
|
135
261
|
if (obj === null || typeof obj !== 'object') {
|
|
136
262
|
return obj;
|
|
@@ -150,6 +276,23 @@
|
|
|
150
276
|
}
|
|
151
277
|
return copy;
|
|
152
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Returns the type of the given value.
|
|
281
|
+
*
|
|
282
|
+
* @param {any} value - The value to determine the type of.
|
|
283
|
+
* @return {Type} - The type of the given value.
|
|
284
|
+
*/
|
|
285
|
+
function getType(value) {
|
|
286
|
+
return value === null ? exports.Type.Null : exports.Type[typeof value];
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Converts an object to `FormData` format recursively.
|
|
290
|
+
*
|
|
291
|
+
* @param {Record<string, any>} data - The object data to convert.
|
|
292
|
+
* @param {FormData} formData - The `FormData` instance to append data to.
|
|
293
|
+
* @param {string} parentKey - The parent key to append to child keys in the `FormData`.
|
|
294
|
+
* @returns {FormData} - The `FormData` instance with the converted data.
|
|
295
|
+
*/
|
|
153
296
|
function _objectToFormData(data, formData, parentKey = '') {
|
|
154
297
|
for (const key in data) {
|
|
155
298
|
if (data.hasOwnProperty(key)) {
|
|
@@ -181,44 +324,84 @@
|
|
|
181
324
|
}
|
|
182
325
|
return formData;
|
|
183
326
|
}
|
|
327
|
+
/**
|
|
328
|
+
* Converts an object into FormData.
|
|
329
|
+
*
|
|
330
|
+
* @param {Record<string, any>} data - The object to be converted into FormData.
|
|
331
|
+
* @return {FormData} - The FormData object representing the converted data.
|
|
332
|
+
*/
|
|
184
333
|
function objectToFormData(data) {
|
|
185
334
|
let formData = new FormData();
|
|
186
335
|
return _objectToFormData(data, formData);
|
|
187
336
|
}
|
|
188
337
|
|
|
189
338
|
/**
|
|
190
|
-
*
|
|
339
|
+
* Ensures that a given string has a specific prefix.
|
|
191
340
|
*
|
|
192
|
-
* @
|
|
341
|
+
* @param {string} str - The string to ensure the prefix on.
|
|
342
|
+
* @param {string} prefix - The prefix to ensure on the string.
|
|
343
|
+
* @return {string} - The resulting string with the ensured prefix.
|
|
193
344
|
*/
|
|
194
|
-
function ensurePrefix(
|
|
345
|
+
function ensurePrefix(str, prefix) {
|
|
195
346
|
if (!str.startsWith(prefix))
|
|
196
347
|
return prefix + str;
|
|
197
348
|
return str;
|
|
198
349
|
}
|
|
199
350
|
/**
|
|
200
|
-
*
|
|
351
|
+
* Ensures that a string ends with a specified suffix.
|
|
201
352
|
*
|
|
202
|
-
* @
|
|
353
|
+
* @param {string} str - The original string.
|
|
354
|
+
* @param {string} suffix - The suffix to ensure.
|
|
355
|
+
* @return {string} - The modified string with the suffix added if it was not already present.
|
|
203
356
|
*/
|
|
204
|
-
function ensureSuffix(
|
|
357
|
+
function ensureSuffix(str, suffix) {
|
|
205
358
|
if (!str.endsWith(suffix))
|
|
206
359
|
return str + suffix;
|
|
207
360
|
return str;
|
|
208
361
|
}
|
|
362
|
+
/**
|
|
363
|
+
* Formats a string using a template and provided arguments.
|
|
364
|
+
*
|
|
365
|
+
* @param {string} template - The template string containing placeholders.
|
|
366
|
+
* @param {any[]} args - Optional arguments to replace the placeholders in the template.
|
|
367
|
+
* @return {string} The formatted string.
|
|
368
|
+
*/
|
|
369
|
+
function format(template, ...args) {
|
|
370
|
+
let regex;
|
|
371
|
+
if (args.length === 1 && typeof args[0] === 'object') {
|
|
372
|
+
args = args[0];
|
|
373
|
+
regex = /{(.+?)}/g;
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
regex = /{(\d+?)}/g;
|
|
377
|
+
}
|
|
378
|
+
return template.replace(regex, (match, key) => {
|
|
379
|
+
return typeof args[key] !== 'undefined' ? args[key] : "";
|
|
380
|
+
});
|
|
381
|
+
}
|
|
209
382
|
|
|
210
383
|
/**
|
|
211
|
-
* Linearly
|
|
384
|
+
* Linearly interpolates a number between two ranges.
|
|
385
|
+
*
|
|
386
|
+
* @param {number} n - The number to interpolate.
|
|
387
|
+
* @param {number} inMin - The minimum value of the input range.
|
|
388
|
+
* @param {number} inMax - The maximum value of the input range.
|
|
389
|
+
* @param {number} outMin - The minimum value of the output range.
|
|
390
|
+
* @param {number} outMax - The maximum value of the output range.
|
|
212
391
|
*
|
|
213
|
-
* @
|
|
214
|
-
* @example
|
|
215
|
-
* ```
|
|
216
|
-
* const value = remap(0.5, 0, 1, 200, 400) // value will be 300
|
|
217
|
-
* ```
|
|
392
|
+
* @return {number} - The interpolated value.
|
|
218
393
|
*/
|
|
219
394
|
function lerp(n, inMin, inMax, outMin, outMax) {
|
|
220
395
|
return outMin + (outMax - outMin) * ((n - inMin) / (inMax - inMin));
|
|
221
396
|
}
|
|
397
|
+
/**
|
|
398
|
+
* Clamps a number between a minimum and maximum value.
|
|
399
|
+
*
|
|
400
|
+
* @param {number} n - The value to be clamped.
|
|
401
|
+
* @param {number} min - The minimum value.
|
|
402
|
+
* @param {number} max - The maximum value.
|
|
403
|
+
* @return {number} The clamped value.
|
|
404
|
+
*/
|
|
222
405
|
function clamp(n, min, max) {
|
|
223
406
|
if (n <= min)
|
|
224
407
|
return min;
|
|
@@ -361,14 +544,26 @@
|
|
|
361
544
|
}
|
|
362
545
|
return true;
|
|
363
546
|
}
|
|
364
|
-
any(predicate) {
|
|
547
|
+
any(predicate = undefined) {
|
|
365
548
|
for (let item of this) {
|
|
366
|
-
if (predicate(item)) {
|
|
549
|
+
if (predicate == null || predicate(item)) {
|
|
367
550
|
return true;
|
|
368
551
|
}
|
|
369
552
|
}
|
|
370
553
|
return false;
|
|
371
554
|
}
|
|
555
|
+
get length() {
|
|
556
|
+
return this.count();
|
|
557
|
+
}
|
|
558
|
+
count(predicate = undefined) {
|
|
559
|
+
let output = 0;
|
|
560
|
+
for (let item of this) {
|
|
561
|
+
if (predicate == null || predicate(item)) {
|
|
562
|
+
output++;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return output;
|
|
566
|
+
}
|
|
372
567
|
filter(predicate) {
|
|
373
568
|
const self = this;
|
|
374
569
|
return From.fn(function* () {
|
|
@@ -734,6 +929,9 @@
|
|
|
734
929
|
}
|
|
735
930
|
}
|
|
736
931
|
|
|
932
|
+
/**
|
|
933
|
+
* A class representing a timer that executes a callback function at a specified interval.
|
|
934
|
+
*/
|
|
737
935
|
class Timer {
|
|
738
936
|
/**
|
|
739
937
|
* @param callback Callback
|
|
@@ -785,6 +983,9 @@
|
|
|
785
983
|
}
|
|
786
984
|
}
|
|
787
985
|
|
|
986
|
+
/**
|
|
987
|
+
* Represents a duration of time in milliseconds.
|
|
988
|
+
*/
|
|
788
989
|
class TimeSpan {
|
|
789
990
|
constructor(milliseconds) {
|
|
790
991
|
this.milliseconds = milliseconds;
|
|
@@ -953,6 +1154,10 @@
|
|
|
953
1154
|
TimeSpan.INFINITE = new TimeSpan(Number.POSITIVE_INFINITY);
|
|
954
1155
|
TimeSpan.NEGATIVE_INFINITE = new TimeSpan(Number.NEGATIVE_INFINITY);
|
|
955
1156
|
|
|
1157
|
+
/**
|
|
1158
|
+
* Represents a lazy value that is created only when it is accessed for the first time.
|
|
1159
|
+
* @template T The type of the lazy value.
|
|
1160
|
+
*/
|
|
956
1161
|
class Lazy {
|
|
957
1162
|
constructor(getter) {
|
|
958
1163
|
this._valueCreated = false;
|
|
@@ -962,9 +1167,9 @@
|
|
|
962
1167
|
get valueCreated() {
|
|
963
1168
|
return this._valueCreated;
|
|
964
1169
|
}
|
|
965
|
-
|
|
1170
|
+
get value() {
|
|
966
1171
|
if (!this._valueCreated) {
|
|
967
|
-
this._value =
|
|
1172
|
+
this._value = this._factoryMethod();
|
|
968
1173
|
this._valueCreated = true;
|
|
969
1174
|
}
|
|
970
1175
|
return this._value;
|
|
@@ -975,6 +1180,11 @@
|
|
|
975
1180
|
}
|
|
976
1181
|
}
|
|
977
1182
|
|
|
1183
|
+
/**
|
|
1184
|
+
* Represents a class for manipulating an array of items.
|
|
1185
|
+
*
|
|
1186
|
+
* @template T - The type of items in the array.
|
|
1187
|
+
*/
|
|
978
1188
|
class ArrayManipulator {
|
|
979
1189
|
constructor(array) {
|
|
980
1190
|
this._array = array;
|
|
@@ -982,12 +1192,29 @@
|
|
|
982
1192
|
[Symbol.iterator]() {
|
|
983
1193
|
return this._array[Symbol.iterator]();
|
|
984
1194
|
}
|
|
1195
|
+
/**
|
|
1196
|
+
* Retrieves or sets the value at the specified index in the array.
|
|
1197
|
+
* If `item` is not provided, returns the value at index `n`.
|
|
1198
|
+
* If `item` is provided, sets the value at index `n` to the provided value.
|
|
1199
|
+
*
|
|
1200
|
+
* @param {number} n - The index at which to retrieve or set the value.
|
|
1201
|
+
* @param {T | undefined} [item] - The value to set at index `n`, if provided.
|
|
1202
|
+
*
|
|
1203
|
+
* @return {T | void} - If `item` is not provided, returns the value at index `n`.
|
|
1204
|
+
* - If `item` is provided, does not return anything.
|
|
1205
|
+
*/
|
|
985
1206
|
at(n, item = undefined) {
|
|
986
1207
|
if (item === undefined)
|
|
987
1208
|
return this._array[n];
|
|
988
1209
|
else
|
|
989
1210
|
this._array[n] = item;
|
|
990
1211
|
}
|
|
1212
|
+
/**
|
|
1213
|
+
* Removes the specified item from the array.
|
|
1214
|
+
*
|
|
1215
|
+
* @param {T} item - The item to be removed.
|
|
1216
|
+
* @returns {ArrayManipulator<T>} - The updated ArrayManipulator instance.
|
|
1217
|
+
*/
|
|
991
1218
|
remove(item) {
|
|
992
1219
|
const index = this._array.indexOf(item);
|
|
993
1220
|
if (index !== -1) {
|
|
@@ -995,12 +1222,25 @@
|
|
|
995
1222
|
}
|
|
996
1223
|
return this;
|
|
997
1224
|
}
|
|
1225
|
+
/**
|
|
1226
|
+
* Applies a mapping function to each element in the array, transforming it into a new array.
|
|
1227
|
+
* @template R
|
|
1228
|
+
* @param {UnaryFunction<T, R>} mapFn - The function to be applied to each element.
|
|
1229
|
+
* @return {ArrayManipulator<R>} - The new ArrayManipulator instance with the mapped elements.
|
|
1230
|
+
*/
|
|
998
1231
|
map(mapFn) {
|
|
999
1232
|
for (let i = 0; i < this._array.length; i++) {
|
|
1000
1233
|
this._array[i] = mapFn(this._array[i]);
|
|
1001
1234
|
}
|
|
1002
1235
|
return this;
|
|
1003
1236
|
}
|
|
1237
|
+
/**
|
|
1238
|
+
* Filters the elements of the array based on a given filter function.
|
|
1239
|
+
* The filter function should return a boolean value, indicating whether the element should be included in the filtered array or not.
|
|
1240
|
+
*
|
|
1241
|
+
* @param {Predicate<T>} filterFn - The function that will be used to filter the elements. It should accept an element of type T and return a boolean value.
|
|
1242
|
+
* @returns {ArrayManipulator<T>} - The filtered ArrayManipulator instance with the elements that passed the filter.
|
|
1243
|
+
*/
|
|
1004
1244
|
filter(filterFn) {
|
|
1005
1245
|
for (let i = 0; i < this._array.length; i++) {
|
|
1006
1246
|
if (!filterFn(this._array[i])) {
|
|
@@ -1037,10 +1277,22 @@
|
|
|
1037
1277
|
this._array.splice(0, start);
|
|
1038
1278
|
return this;
|
|
1039
1279
|
}
|
|
1280
|
+
/**
|
|
1281
|
+
* Appends one or more items to the array.
|
|
1282
|
+
*
|
|
1283
|
+
* @param {...T} items - The items to be appended to the array.
|
|
1284
|
+
* @return {ArrayManipulator<T>} - The ArrayManipulator instance.
|
|
1285
|
+
*/
|
|
1040
1286
|
append(...items) {
|
|
1041
1287
|
this._array.push(...items);
|
|
1042
1288
|
return this;
|
|
1043
1289
|
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Prepend items to the beginning of the array.
|
|
1292
|
+
*
|
|
1293
|
+
* @param {...T} items - The items to be prepended.
|
|
1294
|
+
* @return {ArrayManipulator<T>} The ArrayManipulator instance.
|
|
1295
|
+
*/
|
|
1044
1296
|
prepend(...items) {
|
|
1045
1297
|
this._array.unshift(...items);
|
|
1046
1298
|
return this;
|
|
@@ -1049,6 +1301,12 @@
|
|
|
1049
1301
|
return this._array;
|
|
1050
1302
|
}
|
|
1051
1303
|
}
|
|
1304
|
+
/**
|
|
1305
|
+
* Creates an instance of ArrayManipulator with the given array.
|
|
1306
|
+
* @template T
|
|
1307
|
+
* @param {T[]} array - The input array.
|
|
1308
|
+
* @return {ArrayManipulator<T>} - An instance of the ArrayManipulator class.
|
|
1309
|
+
*/
|
|
1052
1310
|
function array(array) {
|
|
1053
1311
|
return new ArrayManipulator(array);
|
|
1054
1312
|
}
|
|
@@ -1060,7 +1318,6 @@
|
|
|
1060
1318
|
exports.Pair = Pair;
|
|
1061
1319
|
exports.TimeSpan = TimeSpan;
|
|
1062
1320
|
exports.Timer = Timer;
|
|
1063
|
-
exports.Type = Type$1;
|
|
1064
1321
|
exports.ajaxSubmission = ajaxSubmission;
|
|
1065
1322
|
exports.ajaxSubmit = ajaxSubmit;
|
|
1066
1323
|
exports.array = array;
|
|
@@ -1068,7 +1325,9 @@
|
|
|
1068
1325
|
exports.deepClone = deepClone;
|
|
1069
1326
|
exports.ensurePrefix = ensurePrefix;
|
|
1070
1327
|
exports.ensureSuffix = ensureSuffix;
|
|
1328
|
+
exports.format = format;
|
|
1071
1329
|
exports.from = from;
|
|
1330
|
+
exports.getType = getType;
|
|
1072
1331
|
exports.isArray = isArray;
|
|
1073
1332
|
exports.isBigInt = isBigInt;
|
|
1074
1333
|
exports.isBoolean = isBoolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t){"use strict";var e;!function(t){t.Undefined="undefined",t.Number="number",t.String="string",t.Boolean="boolean",t.Object="object",t.Function="function",t.Symbol="symbol",t.BigInt="bigint"}(e||(e={}));var r=e;class n{get value(){return this._value}get key(){return this._key}constructor(t,e){this._key=t,this._value=e}}function i(t){return"function"==typeof t}async function s(t){const e="string"==typeof t?document.querySelector(t):t;if(!(e instanceof HTMLFormElement))throw new Error("Invalid element.");return await fetch(e.action,{method:e.method,body:new FormData(e)})}function o(t){let e=[];for(const r in t)e.push(new n(r,t[r]));return e}function l(t){return t instanceof Promise?t:i(t)?new Promise(((e,r)=>{try{e(t())}catch(t){r(t)}})):Promise.resolve(t)}function a(t,e,r=""){for(const n in t)if(t.hasOwnProperty(n)){const i=t[n];i instanceof Date?e.append(r?`${r}[${n}]`:n,i.toISOString()):i instanceof File?e.append(r?`${r}[${n}]`:n,i):"object"!=typeof i||Array.isArray(i)?Array.isArray(i)?i.forEach(((t,i)=>{const s=`${r?`${r}[${n}]`:n}[${i}]`;"object"!=typeof t||Array.isArray(t)?e.append(s,t):a(t,e,s)})):e.append(r?`${r}[${n}]`:n,i):a(i,e,r?`${r}[${n}]`:n)}return e}class u{static object(t){return new u((function(){return o(t)}))}static _shallowEqual(t,e){const r=Object.keys(t),n=Object.keys(e);if(r.length!==n.length)return!1;for(let n of r)if(t[n]!==e[n])return!1;return!0}constructor(t){this._fn=t}static fn(t){return new u(t)}collect(){const t=Array.from(this);return u.iterable(t)}static iterable(t){return u.fn((function*(){for(const e of t)yield e}))}map(t){const e=this;return u.fn((function*(){for(let r of e)yield t(r)}))}*[Symbol.iterator](){yield*this._fn()}all(t){for(let e of this._fn())if(!t(e))return!1;return!0}any(t){for(let e of this)if(t(e))return!0;return!1}filter(t){const e=this;return u.fn((function*(){for(let r of e)t(r)&&(yield r)}))}contains(t){for(let e of this)if(e===t)return!0;return!1}first(t){if(t){for(let e of this)if(!t||t(e))return e}else for(let t of this)return t}append(t){const e=this;return u.fn((function*(){for(let t of e)yield t;yield t}))}prepend(t){const e=this;return u.fn((function*(){yield t;for(let t of e)yield t}))}at(t){let e=0;for(let r of this)if(e++===t)return r}last(t){let e;if(t)for(let r of this)t&&!t(r)||(e=r);else for(let t of this)e=t;return e}mapMany(t){const e=this;return u.fn((function*(){for(const r of e){const e=t(r);for(const t of e)yield t}}))}flatten(){const t=this;return u.fn((function*(){for(let e of t){let t=e;for(let e of t)yield e}}))}sum(t){let e=0;if(t)for(let r of this)e+=t(r);else for(let t of this)e+=t;return e}avg(t){let e=0,r=0;if(t)for(let n of this)e+=t(n),r++;else for(let t of this)e+=t,r++;return r>0?e/r:0}max(t){let e=-1/0;for(let r of this){let n=t(r);e=n>e?n:e}return e}min(t){let e=1/0;for(let r of this){let n=t(r);e=n<e?n:e}return e}maxBy(t){let e,r=-1/0;for(let n of this){let i=t(n);i>r&&(r=i,e=n)}return e}minBy(t){let e,r=1/0;for(let n of this){let i=t(n);i<r&&(r=i,e=n)}return e}orderBy(t){const e=Array.from(this._fn());return e.sort(((e,r)=>{const n=t(e),i=t(r);return n>i?1:n<i?-1:0})),u.iterable(e)}groupBy(t,e){e=null==e?u._shallowEqual:e;const r=this;return u.fn((function*(){const n=[];for(let i of r){const r=t(i);let s=!1;for(let[t,o]of n)if(e(r,t)){o.push(i),s=!0;break}s||n.push([r,[i]])}yield*n.map((([t,e])=>new c(t,e)))}))}head(t){const e=this;return u.fn((function*(){let r=0;for(let n of e){if(!(r++<t))return;yield n}}))}tail(t){const e=this;return u.fn((function*(){let r=[];for(let n of e)r.push(n),r.length>t&&r.shift();yield*r}))}forEach(t){for(let e of this)t(e)}toArray(){return Array.from(this)}instancesOf(t){return this.filter((e=>typeof e===t))}allInstanceOf(t){for(let e of this)if(!(e instanceof t))return!1;return!0}distinct(t){null==t&&(t=u._shallowEqual);const e=this;return u.fn((function*(){const r=[];for(let n of e)u.iterable(r).any((e=>t(e,n)))||(r.push(n),yield n)}))}insert(t,e){const r=this;return u.fn((function*(){let n=0,i=!1;for(let s of r)n===e&&(yield t,i=!0),yield s,n++;i||(yield t)}))}skip(t){const e=this;return u.fn((function*(){let r=0;for(let n of e)r>=t&&(yield n),r++}))}union(t){const e=this;return u.fn((function*(){yield*e,yield*t}))}innerJoin(t,e,r,n){const i=this;return u.fn((()=>{const s=new Map;for(let e of t)s.set(r(e),e);return Array.from(i).filter((t=>s.has(e(t)))).map((t=>n(t,s.get(e(t)))))}))}leftJoin(t,e,r,n){const i=this;return u.fn((()=>{const s=new Map;for(let e of t)s.set(r(e),e);return Array.from(i).map((t=>n(t,s.get(e(t)))))}))}leftGroupJoin(t,e,r,n){const i=this;return u.fn((()=>{const s=new Map;for(let e of t){const t=r(e);s.has(t)||s.set(t,[]),s.get(t).push(e)}return Array.from(i).map((t=>n(t,s.get(e(t))||[])))}))}rightGroupJoin(t,e,r,n){const i=this;return u.fn((()=>{const s=new Map;for(let t of i){const r=e(t);s.has(r)||s.set(r,[]),s.get(r).push(t)}return Array.from(t).map((t=>n(s.get(r(t))||[],t)))}))}rightJoin(t,e,r,n){const i=this;return u.fn((()=>{const s=new Map;for(let t of i)s.set(e(t),t);return Array.from(t).map((t=>n(s.get(r(t)),t)))}))}}class c extends u{get key(){return this._key}constructor(t,e){super((()=>e)),this._key=t}}class f{constructor(t){this.milliseconds=t}seconds(){return this.milliseconds/1e3}minutes(){return this.milliseconds/6e4}hours(){return this.milliseconds/36e5}days(){return this.milliseconds/864e5}weeks(){return this.milliseconds/6048e5}static fromMilliseconds(t){return new f(t)}static fromSeconds(t){return new f(1e3*t)}static fromMinutes(t){return new f(1e3*t*60)}static fromHours(t){return new f(1e3*t*60*60)}static fromDays(t){return new f(1e3*t*60*60*24)}static fromWeeks(t){return new f(1e3*t*60*60*24*7)}addMilliseconds(t){return new f(this.milliseconds+t)}addSeconds(t){return this.addMilliseconds(1e3*t)}addMinutes(t){return this.addMilliseconds(1e3*t*60)}addHours(t){return this.addMilliseconds(1e3*t*60*60)}addDays(t){return this.addMilliseconds(1e3*t*60*60*24)}addWeeks(t){return this.addMilliseconds(1e3*t*60*60*24*7)}subtractMilliseconds(t){return new f(this.milliseconds-t)}subtractSeconds(t){return this.subtractMilliseconds(1e3*t)}subtractMinutes(t){return this.subtractMilliseconds(1e3*t*60)}subtractHours(t){return this.subtractMilliseconds(1e3*t*60*60)}subtractDays(t){return this.subtractMilliseconds(1e3*t*60*60*24)}subtractWeeks(t){return this.subtractMilliseconds(1e3*t*60*60*24*7)}add(t){return new f(this.milliseconds+t.milliseconds)}subtract(t){return new f(this.milliseconds-t.milliseconds)}addTo(t){return new Date(t.getTime()+this.milliseconds)}subtractFrom(t){return new Date(t.getTime()-this.milliseconds)}static fromDifference(t,e){return new f(e.getTime()-t.getTime())}format(t="hh:mm:ss"){const e=t.toLowerCase(),r=e.includes("h"),n=e.includes("m");let i=0,s=0,o=Math.floor(this.milliseconds/1e3);r&&(i=Math.floor(o/3600),o-=3600*i),n&&(s=Math.floor(o/60),o-=60*s);const l=String(i).padStart(2,"0"),a=String(s).padStart(2,"0"),u=String(o).padStart(2,"0");return e.replace("hh",l).replace("h",i.toString()).replace("mm",a).replace("m",s.toString()).replace("ss",u).replace("s",o.toString())}eq(t){return this.milliseconds===t.milliseconds}le(t){return this.milliseconds<=t.milliseconds}lt(t){return this.milliseconds<t.milliseconds}ge(t){return this.milliseconds>=t.milliseconds}gt(t){return this.milliseconds>t.milliseconds}multiply(t){return new f(this.milliseconds*t)}divide(t){return new f(this.milliseconds/t)}abs(){return new f(Math.abs(this.milliseconds))}isInfinite(){return this.milliseconds===Number.POSITIVE_INFINITY||this.milliseconds===Number.NEGATIVE_INFINITY}isPositiveInfinite(){return this.milliseconds===Number.POSITIVE_INFINITY}isNegativeInfinite(){return this.milliseconds===Number.NEGATIVE_INFINITY}}f.INFINITE=new f(Number.POSITIVE_INFINITY),f.NEGATIVE_INFINITE=new f(Number.NEGATIVE_INFINITY);class h{constructor(t){this._array=t}[Symbol.iterator](){return this._array[Symbol.iterator]()}at(t,e=void 0){if(void 0===e)return this._array[t];this._array[t]=e}remove(t){const e=this._array.indexOf(t);return-1!==e&&this._array.splice(e,1),this}map(t){for(let e=0;e<this._array.length;e++)this._array[e]=t(this._array[e]);return this}filter(t){for(let e=0;e<this._array.length;e++)t(this._array[e])||(this._array.splice(e,1),e--);return this}head(t){return this._array.splice(t),this}slice(t,e=void 0){return this._array.splice(0,t),void 0!==e&&this._array.splice(e),this}mapMany(t){let e=0;for(;e<this._array.length;){let r=t(this._array[e]);Array.isArray(r)||(r=Array.from(r)),this._array.splice(e,1,...r),e+=r.length}return this}tail(t){const e=this._array.length-t;return this._array.splice(0,e),this}append(...t){return this._array.push(...t),this}prepend(...t){return this._array.unshift(...t),this}get array(){return this._array}}t.ArrayManipulator=h,t.CacheDictionary=class{constructor(t=null,e=null){this.fallback=t,this.cache={},this.defaultDuration=e,this.expiration={}}getExpiration(t){return this.expiration[t]}setExpiration(t,e){this.expiration[t]=e}setDuration(t,e){if(null===e)delete this.expiration[t];else{const r=new Date;r.setSeconds(r.getSeconds()+e),this.expiration[t]=r}}get(t){if(!this.cache.hasOwnProperty(t)){if(!this.fallback)return null;this.cache[t]=this.fallback(t),this.expiration[t]=this.calculateExpiration(this.defaultDuration)}return this.isExpired(t)?(this.remove(t),null):this.cache[t]}set(t,e,r=null){this.cache[t]=e,this.expiration[t]=this.calculateExpiration(r)}remove(t){delete this.cache[t],delete this.expiration[t]}isExpired(t){const e=this.expiration[t];return e instanceof Date&&e<new Date}calculateExpiration(t){if(null===t)return;const e=new Date;return e.setSeconds(e.getSeconds()+t),e}},t.From=u,t.Lazy=class{constructor(t){this._valueCreated=!1,this._value=null,this._factoryMethod=t}get valueCreated(){return this._valueCreated}async getValue(){return this._valueCreated||(this._value=await l(this._factoryMethod),this._valueCreated=!0),this._value}reset(){this._valueCreated=!1,this._value=null}},t.Pair=n,t.TimeSpan=f,t.Timer=class{constructor(t,e){this._callback=t,this._interval=e,this._intervalId=null}get running(){return null!==this._intervalId&&void 0!==this._intervalId}get interval(){return this._interval}set interval(t){t!=this._interval&&(this._interval=t,this.running&&this.restart())}get callback(){return this._callback}set callback(t){t!=this._callback&&(this._callback=t)}start(){null===this._intervalId&&(this._intervalId=setInterval((()=>{null!=this._callback&&this._callback()}),this._interval))}stop(){null!==this._intervalId&&(clearInterval(this._intervalId),this._intervalId=null)}restart(){this.stop(),this.start()}},t.Type=r,t.ajaxSubmission=function(t,e=null,r=null){const n="string"==typeof t?document.querySelector(t):t;n instanceof HTMLFormElement&&n.addEventListener("submit",(async t=>{t.preventDefault();let i=s(n);i&&(e&&(i=i.then(e)),r&&i.catch(r))}))},t.ajaxSubmit=s,t.array=function(t){return new h(t)},t.clamp=function(t,e,r){return t<=e?e:t>=r?r:t},t.deepClone=function t(e){if(null===e||"object"!=typeof e)return e;if(Array.isArray(e)){const r=[];for(const n of e)r.push(t(n));return r}const r={};for(const n in e)e.hasOwnProperty(n)&&(r[n]=t(e[n]));return r},t.ensurePrefix=function(t,e){return e.startsWith(t)?e:t+e},t.ensureSuffix=function(t,e){return e.endsWith(t)?e:e+t},t.from=function(t){if(null==t)throw"Source is null.";if("function"==typeof t)return u.fn(t);if("function"==typeof t[Symbol.iterator])return u.iterable(t);if("object"==typeof t)return u.object(t);throw"Invalid source."},t.isArray=function(t){return Array.isArray(t)},t.isBigInt=function(t){return"bigint"==typeof t},t.isBoolean=function(t){return"boolean"==typeof t},t.isDefined=function(t){return void 0!==t},t.isEmpty=function(t){return Array.isArray(t)&&0===t.length||"string"==typeof t&&""===t||null==t},t.isEmptyOrWhitespace=function(t){return Array.isArray(t)&&0===t.length||"string"==typeof t&&""===t.trim()||null==t},t.isFunction=i,t.isIterable=function(t){return"function"===t[Symbol.iterator]},t.isNull=function(t){return null===t},t.isNullOrUndefined=function(t){return null==t},t.isNumber=function(t){return"number"==typeof t},t.isObject=function(t){return null!==t&&"object"==typeof t&&!Array.isArray(t)},t.isString=function(t){return"string"==typeof t},t.isSymbol=function(t){return"symbol"==typeof t},t.isUndefined=function(t){return void 0===t},t.lerp=function(t,e,r,n,i){return n+(t-e)/(r-e)*(i-n)},t.objectToFormData=function(t){return a(t,new FormData)},t.promisify=l,t.toPairs=o}(this.window=this.window||{});
|
|
1
|
+
!function(t){"use strict";var e;t.Type=void 0,(e=t.Type||(t.Type={})).Undefined="undefined",e.Number="number",e.String="string",e.Boolean="boolean",e.Object="object",e.Function="function",e.Symbol="symbol",e.BigInt="bigint",e.Null="null";class r{get value(){return this._value}get key(){return this._key}constructor(t,e){this._key=t,this._value=e}}function n(t){return"function"==typeof t}async function i(t){const e="string"==typeof t?document.querySelector(t):t;if(!(e instanceof HTMLFormElement))throw new Error("Invalid element.");return await fetch(e.action,{method:e.method,body:new FormData(e)})}function s(t){let e=[];for(const n in t)e.push(new r(n,t[n]));return e}function o(t,e,r=""){for(const n in t)if(t.hasOwnProperty(n)){const i=t[n];i instanceof Date?e.append(r?`${r}[${n}]`:n,i.toISOString()):i instanceof File?e.append(r?`${r}[${n}]`:n,i):"object"!=typeof i||Array.isArray(i)?Array.isArray(i)?i.forEach(((t,i)=>{const s=`${r?`${r}[${n}]`:n}[${i}]`;"object"!=typeof t||Array.isArray(t)?e.append(s,t):o(t,e,s)})):e.append(r?`${r}[${n}]`:n,i):o(i,e,r?`${r}[${n}]`:n)}return e}class l{static object(t){return new l((function(){return s(t)}))}static _shallowEqual(t,e){const r=Object.keys(t),n=Object.keys(e);if(r.length!==n.length)return!1;for(let n of r)if(t[n]!==e[n])return!1;return!0}constructor(t){this._fn=t}static fn(t){return new l(t)}collect(){const t=Array.from(this);return l.iterable(t)}static iterable(t){return l.fn((function*(){for(const e of t)yield e}))}map(t){const e=this;return l.fn((function*(){for(let r of e)yield t(r)}))}*[Symbol.iterator](){yield*this._fn()}all(t){for(let e of this._fn())if(!t(e))return!1;return!0}any(t=void 0){for(let e of this)if(null==t||t(e))return!0;return!1}get length(){return this.count()}count(t=void 0){let e=0;for(let r of this)(null==t||t(r))&&e++;return e}filter(t){const e=this;return l.fn((function*(){for(let r of e)t(r)&&(yield r)}))}contains(t){for(let e of this)if(e===t)return!0;return!1}first(t){if(t){for(let e of this)if(!t||t(e))return e}else for(let t of this)return t}append(t){const e=this;return l.fn((function*(){for(let t of e)yield t;yield t}))}prepend(t){const e=this;return l.fn((function*(){yield t;for(let t of e)yield t}))}at(t){let e=0;for(let r of this)if(e++===t)return r}last(t){let e;if(t)for(let r of this)t&&!t(r)||(e=r);else for(let t of this)e=t;return e}mapMany(t){const e=this;return l.fn((function*(){for(const r of e){const e=t(r);for(const t of e)yield t}}))}flatten(){const t=this;return l.fn((function*(){for(let e of t){let t=e;for(let e of t)yield e}}))}sum(t){let e=0;if(t)for(let r of this)e+=t(r);else for(let t of this)e+=t;return e}avg(t){let e=0,r=0;if(t)for(let n of this)e+=t(n),r++;else for(let t of this)e+=t,r++;return r>0?e/r:0}max(t){let e=-1/0;for(let r of this){let n=t(r);e=n>e?n:e}return e}min(t){let e=1/0;for(let r of this){let n=t(r);e=n<e?n:e}return e}maxBy(t){let e,r=-1/0;for(let n of this){let i=t(n);i>r&&(r=i,e=n)}return e}minBy(t){let e,r=1/0;for(let n of this){let i=t(n);i<r&&(r=i,e=n)}return e}orderBy(t){const e=Array.from(this._fn());return e.sort(((e,r)=>{const n=t(e),i=t(r);return n>i?1:n<i?-1:0})),l.iterable(e)}groupBy(t,e){e=null==e?l._shallowEqual:e;const r=this;return l.fn((function*(){const n=[];for(let i of r){const r=t(i);let s=!1;for(let[t,o]of n)if(e(r,t)){o.push(i),s=!0;break}s||n.push([r,[i]])}yield*n.map((([t,e])=>new a(t,e)))}))}head(t){const e=this;return l.fn((function*(){let r=0;for(let n of e){if(!(r++<t))return;yield n}}))}tail(t){const e=this;return l.fn((function*(){let r=[];for(let n of e)r.push(n),r.length>t&&r.shift();yield*r}))}forEach(t){for(let e of this)t(e)}toArray(){return Array.from(this)}instancesOf(t){return this.filter((e=>typeof e===t))}allInstanceOf(t){for(let e of this)if(!(e instanceof t))return!1;return!0}distinct(t){null==t&&(t=l._shallowEqual);const e=this;return l.fn((function*(){const r=[];for(let n of e)l.iterable(r).any((e=>t(e,n)))||(r.push(n),yield n)}))}insert(t,e){const r=this;return l.fn((function*(){let n=0,i=!1;for(let s of r)n===e&&(yield t,i=!0),yield s,n++;i||(yield t)}))}skip(t){const e=this;return l.fn((function*(){let r=0;for(let n of e)r>=t&&(yield n),r++}))}union(t){const e=this;return l.fn((function*(){yield*e,yield*t}))}innerJoin(t,e,r,n){const i=this;return l.fn((()=>{const s=new Map;for(let e of t)s.set(r(e),e);return Array.from(i).filter((t=>s.has(e(t)))).map((t=>n(t,s.get(e(t)))))}))}leftJoin(t,e,r,n){const i=this;return l.fn((()=>{const s=new Map;for(let e of t)s.set(r(e),e);return Array.from(i).map((t=>n(t,s.get(e(t)))))}))}leftGroupJoin(t,e,r,n){const i=this;return l.fn((()=>{const s=new Map;for(let e of t){const t=r(e);s.has(t)||s.set(t,[]),s.get(t).push(e)}return Array.from(i).map((t=>n(t,s.get(e(t))||[])))}))}rightGroupJoin(t,e,r,n){const i=this;return l.fn((()=>{const s=new Map;for(let t of i){const r=e(t);s.has(r)||s.set(r,[]),s.get(r).push(t)}return Array.from(t).map((t=>n(s.get(r(t))||[],t)))}))}rightJoin(t,e,r,n){const i=this;return l.fn((()=>{const s=new Map;for(let t of i)s.set(e(t),t);return Array.from(t).map((t=>n(s.get(r(t)),t)))}))}}class a extends l{get key(){return this._key}constructor(t,e){super((()=>e)),this._key=t}}class u{constructor(t){this.milliseconds=t}seconds(){return this.milliseconds/1e3}minutes(){return this.milliseconds/6e4}hours(){return this.milliseconds/36e5}days(){return this.milliseconds/864e5}weeks(){return this.milliseconds/6048e5}static fromMilliseconds(t){return new u(t)}static fromSeconds(t){return new u(1e3*t)}static fromMinutes(t){return new u(1e3*t*60)}static fromHours(t){return new u(1e3*t*60*60)}static fromDays(t){return new u(1e3*t*60*60*24)}static fromWeeks(t){return new u(1e3*t*60*60*24*7)}addMilliseconds(t){return new u(this.milliseconds+t)}addSeconds(t){return this.addMilliseconds(1e3*t)}addMinutes(t){return this.addMilliseconds(1e3*t*60)}addHours(t){return this.addMilliseconds(1e3*t*60*60)}addDays(t){return this.addMilliseconds(1e3*t*60*60*24)}addWeeks(t){return this.addMilliseconds(1e3*t*60*60*24*7)}subtractMilliseconds(t){return new u(this.milliseconds-t)}subtractSeconds(t){return this.subtractMilliseconds(1e3*t)}subtractMinutes(t){return this.subtractMilliseconds(1e3*t*60)}subtractHours(t){return this.subtractMilliseconds(1e3*t*60*60)}subtractDays(t){return this.subtractMilliseconds(1e3*t*60*60*24)}subtractWeeks(t){return this.subtractMilliseconds(1e3*t*60*60*24*7)}add(t){return new u(this.milliseconds+t.milliseconds)}subtract(t){return new u(this.milliseconds-t.milliseconds)}addTo(t){return new Date(t.getTime()+this.milliseconds)}subtractFrom(t){return new Date(t.getTime()-this.milliseconds)}static fromDifference(t,e){return new u(e.getTime()-t.getTime())}format(t="hh:mm:ss"){const e=t.toLowerCase(),r=e.includes("h"),n=e.includes("m");let i=0,s=0,o=Math.floor(this.milliseconds/1e3);r&&(i=Math.floor(o/3600),o-=3600*i),n&&(s=Math.floor(o/60),o-=60*s);const l=String(i).padStart(2,"0"),a=String(s).padStart(2,"0"),u=String(o).padStart(2,"0");return e.replace("hh",l).replace("h",i.toString()).replace("mm",a).replace("m",s.toString()).replace("ss",u).replace("s",o.toString())}eq(t){return this.milliseconds===t.milliseconds}le(t){return this.milliseconds<=t.milliseconds}lt(t){return this.milliseconds<t.milliseconds}ge(t){return this.milliseconds>=t.milliseconds}gt(t){return this.milliseconds>t.milliseconds}multiply(t){return new u(this.milliseconds*t)}divide(t){return new u(this.milliseconds/t)}abs(){return new u(Math.abs(this.milliseconds))}isInfinite(){return this.milliseconds===Number.POSITIVE_INFINITY||this.milliseconds===Number.NEGATIVE_INFINITY}isPositiveInfinite(){return this.milliseconds===Number.POSITIVE_INFINITY}isNegativeInfinite(){return this.milliseconds===Number.NEGATIVE_INFINITY}}u.INFINITE=new u(Number.POSITIVE_INFINITY),u.NEGATIVE_INFINITE=new u(Number.NEGATIVE_INFINITY);class c{constructor(t){this._array=t}[Symbol.iterator](){return this._array[Symbol.iterator]()}at(t,e=void 0){if(void 0===e)return this._array[t];this._array[t]=e}remove(t){const e=this._array.indexOf(t);return-1!==e&&this._array.splice(e,1),this}map(t){for(let e=0;e<this._array.length;e++)this._array[e]=t(this._array[e]);return this}filter(t){for(let e=0;e<this._array.length;e++)t(this._array[e])||(this._array.splice(e,1),e--);return this}head(t){return this._array.splice(t),this}slice(t,e=void 0){return this._array.splice(0,t),void 0!==e&&this._array.splice(e),this}mapMany(t){let e=0;for(;e<this._array.length;){let r=t(this._array[e]);Array.isArray(r)||(r=Array.from(r)),this._array.splice(e,1,...r),e+=r.length}return this}tail(t){const e=this._array.length-t;return this._array.splice(0,e),this}append(...t){return this._array.push(...t),this}prepend(...t){return this._array.unshift(...t),this}get array(){return this._array}}t.ArrayManipulator=c,t.CacheDictionary=class{constructor(t=null,e=null){this.fallback=t,this.cache={},this.defaultDuration=e,this.expiration={}}getExpiration(t){return this.expiration[t]}setExpiration(t,e){this.expiration[t]=e}setDuration(t,e){if(null===e)delete this.expiration[t];else{const r=new Date;r.setSeconds(r.getSeconds()+e),this.expiration[t]=r}}get(t){if(!this.cache.hasOwnProperty(t)){if(!this.fallback)return null;this.cache[t]=this.fallback(t),this.expiration[t]=this.calculateExpiration(this.defaultDuration)}return this.isExpired(t)?(this.remove(t),null):this.cache[t]}set(t,e,r=null){this.cache[t]=e,this.expiration[t]=this.calculateExpiration(r)}remove(t){delete this.cache[t],delete this.expiration[t]}isExpired(t){const e=this.expiration[t];return e instanceof Date&&e<new Date}calculateExpiration(t){if(null===t)return;const e=new Date;return e.setSeconds(e.getSeconds()+t),e}},t.From=l,t.Lazy=class{constructor(t){this._valueCreated=!1,this._value=null,this._factoryMethod=t}get valueCreated(){return this._valueCreated}get value(){return this._valueCreated||(this._value=this._factoryMethod(),this._valueCreated=!0),this._value}reset(){this._valueCreated=!1,this._value=null}},t.Pair=r,t.TimeSpan=u,t.Timer=class{constructor(t,e){this._callback=t,this._interval=e,this._intervalId=null}get running(){return null!==this._intervalId&&void 0!==this._intervalId}get interval(){return this._interval}set interval(t){t!=this._interval&&(this._interval=t,this.running&&this.restart())}get callback(){return this._callback}set callback(t){t!=this._callback&&(this._callback=t)}start(){null===this._intervalId&&(this._intervalId=setInterval((()=>{null!=this._callback&&this._callback()}),this._interval))}stop(){null!==this._intervalId&&(clearInterval(this._intervalId),this._intervalId=null)}restart(){this.stop(),this.start()}},t.ajaxSubmission=function(t,e=void 0,r=void 0){const n="string"==typeof t?document.querySelector(t):t;n instanceof HTMLFormElement&&n.addEventListener("submit",(async t=>{t.preventDefault();let s=i(n);s&&(e&&(s=s.then(e)),r&&s.catch(r))}))},t.ajaxSubmit=i,t.array=function(t){return new c(t)},t.clamp=function(t,e,r){return t<=e?e:t>=r?r:t},t.deepClone=function t(e){if(null===e||"object"!=typeof e)return e;if(Array.isArray(e)){const r=[];for(const n of e)r.push(t(n));return r}const r={};for(const n in e)e.hasOwnProperty(n)&&(r[n]=t(e[n]));return r},t.ensurePrefix=function(t,e){return t.startsWith(e)?t:e+t},t.ensureSuffix=function(t,e){return t.endsWith(e)?t:t+e},t.format=function(t,...e){let r;return 1===e.length&&"object"==typeof e[0]?(e=e[0],r=/{(.+?)}/g):r=/{(\d+?)}/g,t.replace(r,((t,r)=>void 0!==e[r]?e[r]:""))},t.from=function(t){if(null==t)throw"Source is null.";if("function"==typeof t)return l.fn(t);if("function"==typeof t[Symbol.iterator])return l.iterable(t);if("object"==typeof t)return l.object(t);throw"Invalid source."},t.getType=function(e){return null===e?t.Type.Null:t.Type[typeof e]},t.isArray=function(t){return Array.isArray(t)},t.isBigInt=function(t){return"bigint"==typeof t},t.isBoolean=function(t){return"boolean"==typeof t},t.isDefined=function(t){return void 0!==t},t.isEmpty=function(t){return Array.isArray(t)&&0===t.length||"string"==typeof t&&""===t||null==t},t.isEmptyOrWhitespace=function(t){return Array.isArray(t)&&0===t.length||"string"==typeof t&&""===t.trim()||null==t},t.isFunction=n,t.isIterable=function(t){return"function"===t[Symbol.iterator]},t.isNull=function(t){return null===t},t.isNullOrUndefined=function(t){return null==t},t.isNumber=function(t){return"number"==typeof t},t.isObject=function(t){return null!=t&&"object"==typeof t&&!Array.isArray(t)},t.isString=function(t){return"string"==typeof t},t.isSymbol=function(t){return"symbol"==typeof t},t.isUndefined=function(t){return void 0===t},t.lerp=function(t,e,r,n,i){return n+(t-e)/(r-e)*(i-n)},t.objectToFormData=function(t){return o(t,new FormData)},t.promisify=function(t){return t instanceof Promise?t:n(t)?new Promise(((e,r)=>{try{e(t())}catch(t){r(t)}})):Promise.resolve(t)},t.toPairs=s}(this.window=this.window||{});
|