@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.
Files changed (56) hide show
  1. package/dist/arrays.d.ts +72 -0
  2. package/dist/arrays.d.ts.map +1 -0
  3. package/dist/arrays.js +115 -0
  4. package/dist/arrays.js.map +1 -0
  5. package/dist/assertion.d.ts +31 -0
  6. package/dist/assertion.d.ts.map +1 -0
  7. package/dist/assertion.js +41 -0
  8. package/dist/assertion.js.map +1 -0
  9. package/dist/config.d.ts +10 -0
  10. package/dist/config.d.ts.map +1 -0
  11. package/dist/config.js +12 -0
  12. package/dist/config.js.map +1 -0
  13. package/dist/constructor-registry.d.ts +40 -0
  14. package/dist/constructor-registry.d.ts.map +1 -0
  15. package/dist/constructor-registry.js +52 -0
  16. package/dist/constructor-registry.js.map +1 -0
  17. package/dist/emitter.d.ts +32 -0
  18. package/dist/emitter.d.ts.map +1 -0
  19. package/dist/emitter.js +43 -0
  20. package/dist/emitter.js.map +1 -0
  21. package/dist/guards.d.ts +12 -0
  22. package/dist/guards.d.ts.map +1 -0
  23. package/dist/guards.js +24 -0
  24. package/dist/guards.js.map +1 -0
  25. package/dist/index.d.mts +72 -84
  26. package/dist/index.d.ts +12 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +12 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/index.mjs +172 -295
  31. package/dist/math.d.ts +17 -0
  32. package/dist/math.d.ts.map +1 -0
  33. package/dist/math.js +26 -0
  34. package/dist/math.js.map +1 -0
  35. package/dist/misc.d.ts +7 -0
  36. package/dist/misc.d.ts.map +1 -0
  37. package/dist/misc.js +9 -0
  38. package/dist/misc.js.map +1 -0
  39. package/dist/path.d.ts +10 -0
  40. package/dist/path.d.ts.map +1 -0
  41. package/dist/path.js +14 -0
  42. package/dist/path.js.map +1 -0
  43. package/dist/random.d.ts +14 -0
  44. package/dist/random.d.ts.map +1 -0
  45. package/dist/random.js +21 -0
  46. package/dist/random.js.map +1 -0
  47. package/dist/types.d.ts +50 -0
  48. package/dist/types.d.ts.map +1 -0
  49. package/dist/types.js +2 -0
  50. package/dist/types.js.map +1 -0
  51. package/package.json +38 -38
  52. package/dist/index.cjs +0 -380
  53. package/dist/index.d.cts +0 -305
  54. package/dist/index.d.cts.map +0 -1
  55. package/dist/index.d.mts.map +0 -1
  56. package/dist/index.mjs.map +0 -1
package/dist/index.d.mts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/types.d.ts
2
1
  /**
3
2
  * Represents a path that can be provided as a single string
4
3
  * or an array of segments.
@@ -39,17 +38,16 @@ type Constructor<T = {}> = new (...args: any[]) => T;
39
38
  * @template T A tuple representing the types of the event arguments.
40
39
  */
41
40
  type Subscribable<T extends any[]> = {
42
- readonly listenerCount: number;
43
- /**
44
- * Subscribes a listener to this event.
45
- * @returns A function to unsubscribe the listener.
46
- */
47
- subscribe(listener: (...args: T) => void): () => void;
48
- unsubscribe(listener: (...args: T) => void): boolean;
49
- clear(): void;
41
+ readonly listenerCount: number;
42
+ /**
43
+ * Subscribes a listener to this event.
44
+ * @returns A function to unsubscribe the listener.
45
+ */
46
+ subscribe(listener: (...args: T) => void): () => void;
47
+ unsubscribe(listener: (...args: T) => void): boolean;
48
+ clear(): void;
50
49
  };
51
- //#endregion
52
- //#region src/arrays.d.ts
50
+
53
51
  /**
54
52
  * Generates an array of numbers from 0 to length-1.
55
53
  * @param length The desired length of the array.
@@ -121,8 +119,7 @@ declare function unique<T>(array: T[]): T[];
121
119
  * @returns A random element from the array, or `undefined` if the array is empty.
122
120
  */
123
121
  declare function getRandomElement<T>(array: T[]): T | undefined;
124
- //#endregion
125
- //#region src/assertion.d.ts
122
+
126
123
  /**
127
124
  * Throws an error if the condition is true.
128
125
  * @param conditionForThrow - If true, an error will be thrown.
@@ -153,10 +150,9 @@ declare function throwIf(conditionForThrow: boolean, exceptionMessage: string):
153
150
  * console.log('First item:', items[0]);
154
151
  */
155
152
  declare function throwIfEmpty<T>(value: T, exceptionMessage: string): asserts value is NonNullable<T>;
156
- //#endregion
157
- //#region src/config.d.ts
153
+
158
154
  interface AxiEngineConfig {
159
- pathSeparator: string;
155
+ pathSeparator: string;
160
156
  }
161
157
  declare const axiSettings: AxiEngineConfig;
162
158
  /**
@@ -164,8 +160,7 @@ declare const axiSettings: AxiEngineConfig;
164
160
  * @param newConfig - configuration object
165
161
  */
166
162
  declare function configure(newConfig: Partial<AxiEngineConfig>): void;
167
- //#endregion
168
- //#region src/constructor-registry.d.ts
163
+
169
164
  /**
170
165
  * A generic registry for mapping string identifiers to class constructors.
171
166
  *
@@ -175,69 +170,67 @@ declare function configure(newConfig: Partial<AxiEngineConfig>): void;
175
170
  * @template T - A base type that all registered constructors must produce an instance of.
176
171
  */
177
172
  declare class ConstructorRegistry<T> {
178
- private readonly items;
179
- /**
180
- * Registers a constructor with a unique string identifier.
181
- *
182
- * @param typeId - The unique identifier for the constructor (e.g., a static `typeName` property from a class).
183
- * @param ctor - The class constructor to register.
184
- * @returns The registry instance for chainable calls.
185
- * @throws If a constructor with the same `typeId` is already registered.
186
- */
187
- register(typeId: string, ctor: Constructor<T>): this;
188
- /**
189
- * Retrieves a constructor by its identifier.
190
- *
191
- * @param typeId - The identifier of the constructor to retrieve.
192
- * @returns The found class constructor.
193
- * @throws If no constructor is found for the given `typeId`.
194
- */
195
- get(typeId: string): Constructor<T>;
196
- /**
197
- * Checks if a constructor for a given identifier is registered.
198
- * @param typeId - The identifier to check.
199
- * @returns `true` if a constructor is registered, otherwise `false`.
200
- */
201
- has(typeId: string): boolean;
202
- /**
203
- * Clears all registered constructors from the registry.
204
- */
205
- clear(): void;
173
+ private readonly items;
174
+ /**
175
+ * Registers a constructor with a unique string identifier.
176
+ *
177
+ * @param typeId - The unique identifier for the constructor (e.g., a static `typeName` property from a class).
178
+ * @param ctor - The class constructor to register.
179
+ * @returns The registry instance for chainable calls.
180
+ * @throws If a constructor with the same `typeId` is already registered.
181
+ */
182
+ register(typeId: string, ctor: Constructor<T>): this;
183
+ /**
184
+ * Retrieves a constructor by its identifier.
185
+ *
186
+ * @param typeId - The identifier of the constructor to retrieve.
187
+ * @returns The found class constructor.
188
+ * @throws If no constructor is found for the given `typeId`.
189
+ */
190
+ get(typeId: string): Constructor<T>;
191
+ /**
192
+ * Checks if a constructor for a given identifier is registered.
193
+ * @param typeId - The identifier to check.
194
+ * @returns `true` if a constructor is registered, otherwise `false`.
195
+ */
196
+ has(typeId: string): boolean;
197
+ /**
198
+ * Clears all registered constructors from the registry.
199
+ */
200
+ clear(): void;
206
201
  }
207
- //#endregion
208
- //#region src/emitter.d.ts
202
+
209
203
  /**
210
204
  * A minimal, type-safe event emitter for a single event.
211
205
  * It does not manage state, it only manages subscribers and event dispatching.
212
206
  * @template T A tuple representing the types of the event arguments.
213
207
  */
214
208
  declare class Emitter<T extends any[]> implements Subscribable<T> {
215
- private listeners;
216
- /**
217
- * Returns the number of listeners.
218
- */
219
- get listenerCount(): number;
220
- /**
221
- * Subscribes a listener to this event.
222
- * @returns A function to unsubscribe the listener.
223
- */
224
- subscribe(listener: (...args: T) => void): () => void;
225
- /**
226
- * Manually unsubscribe by listener
227
- * @returns returns true if an listener has been removed, or false if the listener does not exist.
228
- */
229
- unsubscribe(listener: (...args: T) => void): boolean;
230
- /**
231
- * Dispatches the event to all subscribed listeners.
232
- */
233
- emit(...args: T): void;
234
- /**
235
- * Clears all listeners.
236
- */
237
- clear(): void;
209
+ private listeners;
210
+ /**
211
+ * Returns the number of listeners.
212
+ */
213
+ get listenerCount(): number;
214
+ /**
215
+ * Subscribes a listener to this event.
216
+ * @returns A function to unsubscribe the listener.
217
+ */
218
+ subscribe(listener: (...args: T) => void): () => void;
219
+ /**
220
+ * Manually unsubscribe by listener
221
+ * @returns returns true if an listener has been removed, or false if the listener does not exist.
222
+ */
223
+ unsubscribe(listener: (...args: T) => void): boolean;
224
+ /**
225
+ * Dispatches the event to all subscribed listeners.
226
+ */
227
+ emit(...args: T): void;
228
+ /**
229
+ * Clears all listeners.
230
+ */
231
+ clear(): void;
238
232
  }
239
- //#endregion
240
- //#region src/guards.d.ts
233
+
241
234
  declare function isNullOrUndefined(val: unknown): val is null | undefined;
242
235
  declare function isUndefined(val: unknown): val is undefined;
243
236
  declare function isNumber(val: unknown): val is number;
@@ -249,8 +242,7 @@ declare function isString(val: unknown): val is string;
249
242
  * @returns `true` if the value is a percentage string.
250
243
  */
251
244
  declare function isPercentageString(val: unknown): val is string;
252
- //#endregion
253
- //#region src/math.d.ts
245
+
254
246
  /**
255
247
  * Clamps a number between an optional minimum and maximum value.
256
248
  * @param val The number to clamp.
@@ -267,16 +259,14 @@ declare function clampNumber(val: number, min?: number | null, max?: number | nu
267
259
  * @example getPercentOf(200, 10); // returns 20
268
260
  */
269
261
  declare function getPercentOf(val: number, percents: number): number;
270
- //#endregion
271
- //#region src/misc.d.ts
262
+
272
263
  /**
273
264
  * Returns the first key of an object.
274
265
  * @param obj The object from which to get the key.
275
266
  * @returns The first key of the object as a string.
276
267
  */
277
268
  declare function firstKeyOf(obj: any): string;
278
- //#endregion
279
- //#region src/path.d.ts
269
+
280
270
  /**
281
271
  * Ensures that the given path is returned as an array of segments.
282
272
  */
@@ -285,8 +275,7 @@ declare function ensurePathArray(path: PathType, separator?: string): string[];
285
275
  * Ensures that the given path is returned as a single string.
286
276
  */
287
277
  declare function ensurePathString(path: PathType, separator?: string): string;
288
- //#endregion
289
- //#region src/random.d.ts
278
+
290
279
  /**
291
280
  * Returns a random integer between min (inclusive) and max (exclusive).
292
281
  * @param min The minimum integer (inclusive).
@@ -300,6 +289,5 @@ declare function randInt(min: number, max: number): number;
300
289
  * @returns A unique string ID.
301
290
  */
302
291
  declare function randId(): string;
303
- //#endregion
304
- export { AxiEngineConfig, Constructor, ConstructorRegistry, Emitter, PathType, Subscribable, areArraysEqual, axiSettings, clampNumber, configure, ensurePathArray, ensurePathString, firstKeyOf, genArray, getPercentOf, getRandomElement, haveSameElements, isBoolean, isNullOrUndefined, isNumber, isPercentageString, isSequentialStart, isString, isUndefined, last, randId, randInt, shuffleArray, throwIf, throwIfEmpty, unique };
305
- //# sourceMappingURL=index.d.mts.map
292
+
293
+ export { type AxiEngineConfig, type Constructor, ConstructorRegistry, Emitter, type PathType, type Subscribable, areArraysEqual, axiSettings, clampNumber, configure, ensurePathArray, ensurePathString, firstKeyOf, genArray, getPercentOf, getRandomElement, haveSameElements, isBoolean, isNullOrUndefined, isNumber, isPercentageString, isSequentialStart, isString, isUndefined, last, randId, randInt, shuffleArray, throwIf, throwIfEmpty, unique };
@@ -0,0 +1,12 @@
1
+ export type * from './types';
2
+ export * from './arrays';
3
+ export * from './assertion';
4
+ export * from './config';
5
+ export * from './constructor-registry';
6
+ export * from './emitter';
7
+ export * from './guards';
8
+ export * from './math';
9
+ export * from './misc';
10
+ export * from './path';
11
+ export * from './random';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,SAAS,CAAC;AAG7B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,wBAAwB,CAAC;AACvC,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ //
2
+ export * from './arrays';
3
+ export * from './assertion';
4
+ export * from './config';
5
+ export * from './constructor-registry';
6
+ export * from './emitter';
7
+ export * from './guards';
8
+ export * from './math';
9
+ export * from './misc';
10
+ export * from './path';
11
+ export * from './random';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,EAAE;AACF,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,wBAAwB,CAAC;AACvC,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}