@axi-engine/utils 0.1.8 → 0.1.9
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/arrays.d.ts +72 -0
- package/dist/arrays.d.ts.map +1 -0
- package/dist/arrays.js +115 -0
- package/dist/arrays.js.map +1 -0
- package/dist/assertion.d.ts +31 -0
- package/dist/assertion.d.ts.map +1 -0
- package/dist/assertion.js +41 -0
- package/dist/assertion.js.map +1 -0
- package/dist/config.d.ts +10 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +12 -0
- package/dist/config.js.map +1 -0
- package/dist/constructor-registry.d.ts +40 -0
- package/dist/constructor-registry.d.ts.map +1 -0
- package/dist/constructor-registry.js +52 -0
- package/dist/constructor-registry.js.map +1 -0
- package/dist/emitter.d.ts +32 -0
- package/dist/emitter.d.ts.map +1 -0
- package/dist/emitter.js +43 -0
- package/dist/emitter.js.map +1 -0
- package/dist/guards.d.ts +12 -0
- package/dist/guards.d.ts.map +1 -0
- package/dist/guards.js +24 -0
- package/dist/guards.js.map +1 -0
- package/dist/index.d.mts +72 -84
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +172 -295
- package/dist/math.d.ts +17 -0
- package/dist/math.d.ts.map +1 -0
- package/dist/math.js +26 -0
- package/dist/math.js.map +1 -0
- package/dist/misc.d.ts +7 -0
- package/dist/misc.d.ts.map +1 -0
- package/dist/misc.js +9 -0
- package/dist/misc.js.map +1 -0
- package/dist/path.d.ts +10 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +14 -0
- package/dist/path.js.map +1 -0
- package/dist/random.d.ts +14 -0
- package/dist/random.d.ts.map +1 -0
- package/dist/random.js +21 -0
- package/dist/random.js.map +1 -0
- package/dist/types.d.ts +50 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +38 -38
- package/dist/index.cjs +0 -380
- package/dist/index.d.cts +0 -305
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,355 +1,232 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//#region src/arrays.ts
|
|
4
|
-
/**
|
|
5
|
-
* Generates an array of numbers from 0 to length-1.
|
|
6
|
-
* @param length The desired length of the array.
|
|
7
|
-
* @returns An array of sequential numbers.
|
|
8
|
-
* @example genArray(3); // returns [0, 1, 2]
|
|
9
|
-
*/
|
|
1
|
+
// src/arrays.ts
|
|
10
2
|
function genArray(length) {
|
|
11
|
-
|
|
3
|
+
return Array.from({ length }, (_v, i) => i);
|
|
12
4
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Creates a new array with its elements shuffled in a random order.
|
|
15
|
-
* This function does not mutate the original array.
|
|
16
|
-
* @template T The type of elements in the array.
|
|
17
|
-
* @param array The array to shuffle.
|
|
18
|
-
* @returns A new, shuffled array.
|
|
19
|
-
*/
|
|
20
5
|
function shuffleArray(array) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
6
|
+
const result = [...array];
|
|
7
|
+
for (let i = result.length - 1; i > 0; i--) {
|
|
8
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
9
|
+
[result[i], result[j]] = [result[j], result[i]];
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
27
12
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Checks if the first array is a sequential starting subset of the second array.
|
|
30
|
-
* @param arr1 The potential subset array.
|
|
31
|
-
* @param arr2 The array to check against.
|
|
32
|
-
* @returns `true` if arr1 is a sequential start of arr2, otherwise `false`.
|
|
33
|
-
* @example
|
|
34
|
-
* isSequentialStart([1, 2], [1, 2, 3]); // true
|
|
35
|
-
* isSequentialStart([1, 3], [1, 2, 3]); // false
|
|
36
|
-
*/
|
|
37
13
|
function isSequentialStart(arr1, arr2) {
|
|
38
|
-
|
|
39
|
-
|
|
14
|
+
if (arr1.length > arr2.length) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return arr1.every((element, index) => element === arr2[index]);
|
|
40
18
|
}
|
|
41
|
-
/**
|
|
42
|
-
* Checks if two arrays contain the same elements, ignoring order.
|
|
43
|
-
* Works for arrays of primitives like strings or numbers.
|
|
44
|
-
* @template T The type of elements in the array.
|
|
45
|
-
* @param arr1 The first array.
|
|
46
|
-
* @param arr2 The second array.
|
|
47
|
-
* @returns `true` if both arrays contain the same elements, otherwise `false`.
|
|
48
|
-
* @example
|
|
49
|
-
* haveSameElements(['a', 'b'], ['b', 'a']); // true
|
|
50
|
-
* haveSameElements([1, 2, 3], [3, 1, 2]); // true
|
|
51
|
-
* haveSameElements(['a', 'b'], ['a', 'c']); // false
|
|
52
|
-
*/
|
|
53
19
|
function haveSameElements(arr1, arr2) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
20
|
+
if (!arr1 && !arr2) return true;
|
|
21
|
+
if (!arr1 || !arr2) return false;
|
|
22
|
+
if (arr1.length !== arr2.length) return false;
|
|
23
|
+
const sortedArr1 = [...arr1].sort();
|
|
24
|
+
const sortedArr2 = [...arr2].sort();
|
|
25
|
+
return sortedArr1.every((value, index) => value === sortedArr2[index]);
|
|
60
26
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Checks if two arrays are strictly equal (same elements in the same order).
|
|
63
|
-
* @template T The type of elements in the array.
|
|
64
|
-
* @param arr1 The first array.
|
|
65
|
-
* @param arr2 The second array.
|
|
66
|
-
* @returns `true` if the arrays are strictly equal, otherwise `false`.
|
|
67
|
-
* @example
|
|
68
|
-
* areArraysEqual(['a', 'b'], ['a', 'b']); // true
|
|
69
|
-
* areArraysEqual(['a', 'b'], ['b', 'a']); // false
|
|
70
|
-
* areArraysEqual([1, 2], [1, 2, 3]); // false
|
|
71
|
-
*/
|
|
72
27
|
function areArraysEqual(arr1, arr2) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
28
|
+
if (!arr1 && !arr2) return true;
|
|
29
|
+
if (!arr1 || !arr2) return false;
|
|
30
|
+
if (arr1.length !== arr2.length) return false;
|
|
31
|
+
return arr1.every((value, index) => value === arr2[index]);
|
|
77
32
|
}
|
|
78
|
-
/**
|
|
79
|
-
* Gets the last element of an array.
|
|
80
|
-
* @template T The type of elements in the array.
|
|
81
|
-
* @param array The array to query.
|
|
82
|
-
* @returns The last element of the array, or `undefined` if the array is empty.
|
|
83
|
-
*/
|
|
84
33
|
function last(array) {
|
|
85
|
-
|
|
34
|
+
return array[array.length - 1];
|
|
86
35
|
}
|
|
87
|
-
/**
|
|
88
|
-
* Creates a duplicate-free version of an array.
|
|
89
|
-
* @template T The type of elements in the array.
|
|
90
|
-
* @param array The array to process.
|
|
91
|
-
* @returns A new array with only unique elements.
|
|
92
|
-
*/
|
|
93
36
|
function unique(array) {
|
|
94
|
-
|
|
37
|
+
return [...new Set(array)];
|
|
95
38
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Gets a random element from an array.
|
|
98
|
-
* @template T The type of elements in the array.
|
|
99
|
-
* @param array The array to choose from.
|
|
100
|
-
* @returns A random element from the array, or `undefined` if the array is empty.
|
|
101
|
-
*/
|
|
102
39
|
function getRandomElement(array) {
|
|
103
|
-
|
|
104
|
-
|
|
40
|
+
if (array.length === 0) {
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
43
|
+
const index = Math.floor(Math.random() * array.length);
|
|
44
|
+
return array[index];
|
|
105
45
|
}
|
|
106
46
|
|
|
107
|
-
|
|
108
|
-
//#region src/guards.ts
|
|
47
|
+
// src/guards.ts
|
|
109
48
|
function isNullOrUndefined(val) {
|
|
110
|
-
|
|
49
|
+
return val === void 0 || val === null;
|
|
111
50
|
}
|
|
112
51
|
function isUndefined(val) {
|
|
113
|
-
|
|
52
|
+
return typeof val === "undefined";
|
|
114
53
|
}
|
|
115
54
|
function isNumber(val) {
|
|
116
|
-
|
|
55
|
+
return typeof val === "number";
|
|
117
56
|
}
|
|
118
57
|
function isBoolean(val) {
|
|
119
|
-
|
|
58
|
+
return typeof val === "boolean";
|
|
120
59
|
}
|
|
121
60
|
function isString(val) {
|
|
122
|
-
|
|
61
|
+
return typeof val === "string";
|
|
123
62
|
}
|
|
124
|
-
/**
|
|
125
|
-
* Type guard to check if a value is a string that ends with '%'.
|
|
126
|
-
* @param val The value to check.
|
|
127
|
-
* @returns `true` if the value is a percentage string.
|
|
128
|
-
*/
|
|
129
63
|
function isPercentageString(val) {
|
|
130
|
-
|
|
64
|
+
return typeof val === "string" && val.endsWith("%");
|
|
131
65
|
}
|
|
132
66
|
|
|
133
|
-
|
|
134
|
-
//#region src/assertion.ts
|
|
135
|
-
/**
|
|
136
|
-
* Throws an error if the condition is true.
|
|
137
|
-
* @param conditionForThrow - If true, an error will be thrown.
|
|
138
|
-
* @param exceptionMessage - The message for the error.
|
|
139
|
-
* @throws {Error} if the value is true
|
|
140
|
-
*/
|
|
67
|
+
// src/assertion.ts
|
|
141
68
|
function throwIf(conditionForThrow, exceptionMessage) {
|
|
142
|
-
|
|
69
|
+
if (conditionForThrow) {
|
|
70
|
+
throw new Error(exceptionMessage);
|
|
71
|
+
}
|
|
143
72
|
}
|
|
144
|
-
/**
|
|
145
|
-
* Throws an error if the value is null, undefined, or an empty array.
|
|
146
|
-
*
|
|
147
|
-
* @template T The type of the value being checked.
|
|
148
|
-
* @param value The value to check.
|
|
149
|
-
* @param exceptionMessage The message for the error.
|
|
150
|
-
* @throws {Error} if the value is null, undefined, or an empty array.
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* // Example with a potentially undefined variable
|
|
154
|
-
* const user: { name: string } | undefined = findUser();
|
|
155
|
-
* throwIfEmpty(user, 'User not found');
|
|
156
|
-
* // From here, TypeScript knows `user` is not undefined.
|
|
157
|
-
* console.log(user.name);
|
|
158
|
-
*
|
|
159
|
-
* @example
|
|
160
|
-
* // Example with an array
|
|
161
|
-
* const items: string[] = getItems();
|
|
162
|
-
* throwIfEmpty(items, 'Items array cannot be empty');
|
|
163
|
-
* // From here, you can safely access items[0] without checking for an empty array again.
|
|
164
|
-
* console.log('First item:', items[0]);
|
|
165
|
-
*/
|
|
166
73
|
function throwIfEmpty(value, exceptionMessage) {
|
|
167
|
-
|
|
168
|
-
|
|
74
|
+
const isArrayAndEmpty = Array.isArray(value) && value.length === 0;
|
|
75
|
+
if (isNullOrUndefined(value) || isArrayAndEmpty) {
|
|
76
|
+
throw new Error(exceptionMessage);
|
|
77
|
+
}
|
|
169
78
|
}
|
|
170
79
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
* set up global configuration for axi-engine.
|
|
177
|
-
* @param newConfig - configuration object
|
|
178
|
-
*/
|
|
80
|
+
// src/config.ts
|
|
81
|
+
var defaultConfig = {
|
|
82
|
+
pathSeparator: "/"
|
|
83
|
+
};
|
|
84
|
+
var axiSettings = { ...defaultConfig };
|
|
179
85
|
function configure(newConfig) {
|
|
180
|
-
|
|
86
|
+
Object.assign(axiSettings, newConfig);
|
|
181
87
|
}
|
|
182
88
|
|
|
183
|
-
|
|
184
|
-
//#region src/constructor-registry.ts
|
|
185
|
-
/**
|
|
186
|
-
* A generic registry for mapping string identifiers to class constructors.
|
|
187
|
-
*
|
|
188
|
-
* This utility is fundamental for building extensible systems like dependency injection containers,
|
|
189
|
-
* factories, and serialization engines where types need to be dynamically resolved.
|
|
190
|
-
*
|
|
191
|
-
* @template T - A base type that all registered constructors must produce an instance of.
|
|
192
|
-
*/
|
|
89
|
+
// src/constructor-registry.ts
|
|
193
90
|
var ConstructorRegistry = class {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
91
|
+
items = /* @__PURE__ */ new Map();
|
|
92
|
+
/**
|
|
93
|
+
* Registers a constructor with a unique string identifier.
|
|
94
|
+
*
|
|
95
|
+
* @param typeId - The unique identifier for the constructor (e.g., a static `typeName` property from a class).
|
|
96
|
+
* @param ctor - The class constructor to register.
|
|
97
|
+
* @returns The registry instance for chainable calls.
|
|
98
|
+
* @throws If a constructor with the same `typeId` is already registered.
|
|
99
|
+
*/
|
|
100
|
+
register(typeId, ctor) {
|
|
101
|
+
throwIf(this.items.has(typeId), `A constructor with typeId '${typeId}' is already registered.`);
|
|
102
|
+
this.items.set(typeId, ctor);
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Retrieves a constructor by its identifier.
|
|
107
|
+
*
|
|
108
|
+
* @param typeId - The identifier of the constructor to retrieve.
|
|
109
|
+
* @returns The found class constructor.
|
|
110
|
+
* @throws If no constructor is found for the given `typeId`.
|
|
111
|
+
*/
|
|
112
|
+
get(typeId) {
|
|
113
|
+
const Ctor = this.items.get(typeId);
|
|
114
|
+
throwIfEmpty(Ctor, `No constructor found for typeId '${typeId}'`);
|
|
115
|
+
return Ctor;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Checks if a constructor for a given identifier is registered.
|
|
119
|
+
* @param typeId - The identifier to check.
|
|
120
|
+
* @returns `true` if a constructor is registered, otherwise `false`.
|
|
121
|
+
*/
|
|
122
|
+
has(typeId) {
|
|
123
|
+
return this.items.has(typeId);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Clears all registered constructors from the registry.
|
|
127
|
+
*/
|
|
128
|
+
clear() {
|
|
129
|
+
this.items.clear();
|
|
130
|
+
}
|
|
234
131
|
};
|
|
235
132
|
|
|
236
|
-
|
|
237
|
-
//#region src/emitter.ts
|
|
238
|
-
/**
|
|
239
|
-
* A minimal, type-safe event emitter for a single event.
|
|
240
|
-
* It does not manage state, it only manages subscribers and event dispatching.
|
|
241
|
-
* @template T A tuple representing the types of the event arguments.
|
|
242
|
-
*/
|
|
133
|
+
// src/emitter.ts
|
|
243
134
|
var Emitter = class {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
135
|
+
listeners = /* @__PURE__ */ new Set();
|
|
136
|
+
/**
|
|
137
|
+
* Returns the number of listeners.
|
|
138
|
+
*/
|
|
139
|
+
get listenerCount() {
|
|
140
|
+
return this.listeners.size;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Subscribes a listener to this event.
|
|
144
|
+
* @returns A function to unsubscribe the listener.
|
|
145
|
+
*/
|
|
146
|
+
subscribe(listener) {
|
|
147
|
+
this.listeners.add(listener);
|
|
148
|
+
return () => this.listeners.delete(listener);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Manually unsubscribe by listener
|
|
152
|
+
* @returns returns true if an listener has been removed, or false if the listener does not exist.
|
|
153
|
+
*/
|
|
154
|
+
unsubscribe(listener) {
|
|
155
|
+
return this.listeners.delete(listener);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Dispatches the event to all subscribed listeners.
|
|
159
|
+
*/
|
|
160
|
+
emit(...args) {
|
|
161
|
+
this.listeners.forEach((listener) => listener(...args));
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Clears all listeners.
|
|
165
|
+
*/
|
|
166
|
+
clear() {
|
|
167
|
+
this.listeners.clear();
|
|
168
|
+
}
|
|
278
169
|
};
|
|
279
170
|
|
|
280
|
-
|
|
281
|
-
//#region src/math.ts
|
|
282
|
-
/**
|
|
283
|
-
* Clamps a number between an optional minimum and maximum value.
|
|
284
|
-
* @param val The number to clamp.
|
|
285
|
-
* @param min The minimum value. If null or undefined, it's ignored.
|
|
286
|
-
* @param max The maximum value. If null or undefined, it's ignored.
|
|
287
|
-
* @returns The clamped number.
|
|
288
|
-
*/
|
|
171
|
+
// src/math.ts
|
|
289
172
|
function clampNumber(val, min, max) {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
173
|
+
if (!isNullOrUndefined(min)) val = Math.max(val, min);
|
|
174
|
+
if (!isNullOrUndefined(max)) val = Math.min(val, max);
|
|
175
|
+
return val;
|
|
293
176
|
}
|
|
294
|
-
/**
|
|
295
|
-
* Calculates a percentage of a given value.
|
|
296
|
-
* @param val The base value.
|
|
297
|
-
* @param percents The percentage to get.
|
|
298
|
-
* @returns The calculated percentage of the value.
|
|
299
|
-
* @example getPercentOf(200, 10); // returns 20
|
|
300
|
-
*/
|
|
301
177
|
function getPercentOf(val, percents) {
|
|
302
|
-
|
|
178
|
+
return percents / 100 * val;
|
|
303
179
|
}
|
|
304
180
|
|
|
305
|
-
|
|
306
|
-
//#region src/misc.ts
|
|
307
|
-
/**
|
|
308
|
-
* Returns the first key of an object.
|
|
309
|
-
* @param obj The object from which to get the key.
|
|
310
|
-
* @returns The first key of the object as a string.
|
|
311
|
-
*/
|
|
181
|
+
// src/misc.ts
|
|
312
182
|
function firstKeyOf(obj) {
|
|
313
|
-
|
|
183
|
+
return Object.keys(obj)[0];
|
|
314
184
|
}
|
|
315
185
|
|
|
316
|
-
|
|
317
|
-
//#region src/path.ts
|
|
318
|
-
/**
|
|
319
|
-
* Ensures that the given path is returned as an array of segments.
|
|
320
|
-
*/
|
|
186
|
+
// src/path.ts
|
|
321
187
|
function ensurePathArray(path, separator = axiSettings.pathSeparator) {
|
|
322
|
-
|
|
188
|
+
return Array.isArray(path) ? [...path] : path.split(separator);
|
|
323
189
|
}
|
|
324
|
-
/**
|
|
325
|
-
* Ensures that the given path is returned as a single string.
|
|
326
|
-
*/
|
|
327
190
|
function ensurePathString(path, separator = axiSettings.pathSeparator) {
|
|
328
|
-
|
|
191
|
+
return !Array.isArray(path) ? path : path.join(separator);
|
|
329
192
|
}
|
|
330
193
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Returns a random integer between min (inclusive) and max (exclusive).
|
|
335
|
-
* @param min The minimum integer (inclusive).
|
|
336
|
-
* @param max The maximum integer (exclusive).
|
|
337
|
-
* @returns A random integer.
|
|
338
|
-
* @example randInt(1, 5); // returns 1, 2, 3, or 4
|
|
339
|
-
*/
|
|
194
|
+
// src/random.ts
|
|
195
|
+
import { v4 as uuidv4 } from "uuid";
|
|
340
196
|
function randInt(min, max) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
197
|
+
min = Math.ceil(min);
|
|
198
|
+
max = Math.floor(max);
|
|
199
|
+
return Math.floor(Math.random() * (max - min) + min);
|
|
344
200
|
}
|
|
345
|
-
/**
|
|
346
|
-
* Generates a unique identifier using uuidv4.
|
|
347
|
-
* @returns A unique string ID.
|
|
348
|
-
*/
|
|
349
201
|
function randId() {
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
202
|
+
return uuidv4();
|
|
203
|
+
}
|
|
204
|
+
export {
|
|
205
|
+
ConstructorRegistry,
|
|
206
|
+
Emitter,
|
|
207
|
+
areArraysEqual,
|
|
208
|
+
axiSettings,
|
|
209
|
+
clampNumber,
|
|
210
|
+
configure,
|
|
211
|
+
ensurePathArray,
|
|
212
|
+
ensurePathString,
|
|
213
|
+
firstKeyOf,
|
|
214
|
+
genArray,
|
|
215
|
+
getPercentOf,
|
|
216
|
+
getRandomElement,
|
|
217
|
+
haveSameElements,
|
|
218
|
+
isBoolean,
|
|
219
|
+
isNullOrUndefined,
|
|
220
|
+
isNumber,
|
|
221
|
+
isPercentageString,
|
|
222
|
+
isSequentialStart,
|
|
223
|
+
isString,
|
|
224
|
+
isUndefined,
|
|
225
|
+
last,
|
|
226
|
+
randId,
|
|
227
|
+
randInt,
|
|
228
|
+
shuffleArray,
|
|
229
|
+
throwIf,
|
|
230
|
+
throwIfEmpty,
|
|
231
|
+
unique
|
|
232
|
+
};
|
package/dist/math.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clamps a number between an optional minimum and maximum value.
|
|
3
|
+
* @param val The number to clamp.
|
|
4
|
+
* @param min The minimum value. If null or undefined, it's ignored.
|
|
5
|
+
* @param max The maximum value. If null or undefined, it's ignored.
|
|
6
|
+
* @returns The clamped number.
|
|
7
|
+
*/
|
|
8
|
+
export declare function clampNumber(val: number, min?: number | null, max?: number | null): number;
|
|
9
|
+
/**
|
|
10
|
+
* Calculates a percentage of a given value.
|
|
11
|
+
* @param val The base value.
|
|
12
|
+
* @param percents The percentage to get.
|
|
13
|
+
* @returns The calculated percentage of the value.
|
|
14
|
+
* @example getPercentOf(200, 10); // returns 20
|
|
15
|
+
*/
|
|
16
|
+
export declare function getPercentOf(val: number, percents: number): number;
|
|
17
|
+
//# sourceMappingURL=math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../src/math.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAIzF;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,UAEzD"}
|
package/dist/math.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isNullOrUndefined } from './guards';
|
|
2
|
+
/**
|
|
3
|
+
* Clamps a number between an optional minimum and maximum value.
|
|
4
|
+
* @param val The number to clamp.
|
|
5
|
+
* @param min The minimum value. If null or undefined, it's ignored.
|
|
6
|
+
* @param max The maximum value. If null or undefined, it's ignored.
|
|
7
|
+
* @returns The clamped number.
|
|
8
|
+
*/
|
|
9
|
+
export function clampNumber(val, min, max) {
|
|
10
|
+
if (!isNullOrUndefined(min))
|
|
11
|
+
val = Math.max(val, min);
|
|
12
|
+
if (!isNullOrUndefined(max))
|
|
13
|
+
val = Math.min(val, max);
|
|
14
|
+
return val;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Calculates a percentage of a given value.
|
|
18
|
+
* @param val The base value.
|
|
19
|
+
* @param percents The percentage to get.
|
|
20
|
+
* @returns The calculated percentage of the value.
|
|
21
|
+
* @example getPercentOf(200, 10); // returns 20
|
|
22
|
+
*/
|
|
23
|
+
export function getPercentOf(val, percents) {
|
|
24
|
+
return (percents / 100) * val;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=math.js.map
|
package/dist/math.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.js","sourceRoot":"","sources":["../src/math.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,UAAU,CAAC;AAG3C;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,GAAmB,EAAE,GAAmB;IAC/E,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC;QAAE,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACtD,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC;QAAE,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACtD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,QAAgB;IACxD,OAAO,CAAC,QAAQ,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AAChC,CAAC"}
|
package/dist/misc.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../src/misc.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,UAElC"}
|
package/dist/misc.js
ADDED
package/dist/misc.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../src/misc.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,GAAQ;IACjC,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7B,CAAC"}
|
package/dist/path.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PathType } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Ensures that the given path is returned as an array of segments.
|
|
4
|
+
*/
|
|
5
|
+
export declare function ensurePathArray(path: PathType, separator?: string): string[];
|
|
6
|
+
/**
|
|
7
|
+
* Ensures that the given path is returned as a single string.
|
|
8
|
+
*/
|
|
9
|
+
export declare function ensurePathString(path: PathType, separator?: string): string;
|
|
10
|
+
//# sourceMappingURL=path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AAGjC;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,SAA4B,GAAG,MAAM,EAAE,CAE/F;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,SAA4B,GAAG,MAAM,CAE9F"}
|
package/dist/path.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { axiSettings } from './config';
|
|
2
|
+
/**
|
|
3
|
+
* Ensures that the given path is returned as an array of segments.
|
|
4
|
+
*/
|
|
5
|
+
export function ensurePathArray(path, separator = axiSettings.pathSeparator) {
|
|
6
|
+
return Array.isArray(path) ? [...path] : path.split(separator);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Ensures that the given path is returned as a single string.
|
|
10
|
+
*/
|
|
11
|
+
export function ensurePathString(path, separator = axiSettings.pathSeparator) {
|
|
12
|
+
return !Array.isArray(path) ? path : path.join(separator);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=path.js.map
|
package/dist/path.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.js","sourceRoot":"","sources":["../src/path.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAC,MAAM,UAAU,CAAC;AAErC;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,IAAc,EAAE,SAAS,GAAG,WAAW,CAAC,aAAa;IACnF,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACjE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAc,EAAE,SAAS,GAAG,WAAW,CAAC,aAAa;IACpF,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAC5D,CAAC"}
|
package/dist/random.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a random integer between min (inclusive) and max (exclusive).
|
|
3
|
+
* @param min The minimum integer (inclusive).
|
|
4
|
+
* @param max The maximum integer (exclusive).
|
|
5
|
+
* @returns A random integer.
|
|
6
|
+
* @example randInt(1, 5); // returns 1, 2, 3, or 4
|
|
7
|
+
*/
|
|
8
|
+
export declare function randInt(min: number, max: number): number;
|
|
9
|
+
/**
|
|
10
|
+
* Generates a unique identifier using uuidv4.
|
|
11
|
+
* @returns A unique string ID.
|
|
12
|
+
*/
|
|
13
|
+
export declare function randId(): string;
|
|
14
|
+
//# sourceMappingURL=random.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../src/random.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAIxD;AAED;;;GAGG;AACH,wBAAgB,MAAM,WAErB"}
|