@axi-engine/utils 0.1.7 → 0.1.8

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.d.mts CHANGED
@@ -1,3 +1,4 @@
1
+ //#region src/types.d.ts
1
2
  /**
2
3
  * Represents a path that can be provided as a single string
3
4
  * or an array of segments.
@@ -38,16 +39,17 @@ type Constructor<T = {}> = new (...args: any[]) => T;
38
39
  * @template T A tuple representing the types of the event arguments.
39
40
  */
40
41
  type Subscribable<T extends any[]> = {
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;
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;
49
50
  };
50
-
51
+ //#endregion
52
+ //#region src/arrays.d.ts
51
53
  /**
52
54
  * Generates an array of numbers from 0 to length-1.
53
55
  * @param length The desired length of the array.
@@ -119,7 +121,8 @@ declare function unique<T>(array: T[]): T[];
119
121
  * @returns A random element from the array, or `undefined` if the array is empty.
120
122
  */
121
123
  declare function getRandomElement<T>(array: T[]): T | undefined;
122
-
124
+ //#endregion
125
+ //#region src/assertion.d.ts
123
126
  /**
124
127
  * Throws an error if the condition is true.
125
128
  * @param conditionForThrow - If true, an error will be thrown.
@@ -150,9 +153,10 @@ declare function throwIf(conditionForThrow: boolean, exceptionMessage: string):
150
153
  * console.log('First item:', items[0]);
151
154
  */
152
155
  declare function throwIfEmpty<T>(value: T, exceptionMessage: string): asserts value is NonNullable<T>;
153
-
156
+ //#endregion
157
+ //#region src/config.d.ts
154
158
  interface AxiEngineConfig {
155
- pathSeparator: string;
159
+ pathSeparator: string;
156
160
  }
157
161
  declare const axiSettings: AxiEngineConfig;
158
162
  /**
@@ -160,7 +164,8 @@ declare const axiSettings: AxiEngineConfig;
160
164
  * @param newConfig - configuration object
161
165
  */
162
166
  declare function configure(newConfig: Partial<AxiEngineConfig>): void;
163
-
167
+ //#endregion
168
+ //#region src/constructor-registry.d.ts
164
169
  /**
165
170
  * A generic registry for mapping string identifiers to class constructors.
166
171
  *
@@ -170,67 +175,69 @@ declare function configure(newConfig: Partial<AxiEngineConfig>): void;
170
175
  * @template T - A base type that all registered constructors must produce an instance of.
171
176
  */
172
177
  declare class ConstructorRegistry<T> {
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;
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;
201
206
  }
202
-
207
+ //#endregion
208
+ //#region src/emitter.d.ts
203
209
  /**
204
210
  * A minimal, type-safe event emitter for a single event.
205
211
  * It does not manage state, it only manages subscribers and event dispatching.
206
212
  * @template T A tuple representing the types of the event arguments.
207
213
  */
208
214
  declare class Emitter<T extends any[]> implements Subscribable<T> {
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;
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;
232
238
  }
233
-
239
+ //#endregion
240
+ //#region src/guards.d.ts
234
241
  declare function isNullOrUndefined(val: unknown): val is null | undefined;
235
242
  declare function isUndefined(val: unknown): val is undefined;
236
243
  declare function isNumber(val: unknown): val is number;
@@ -242,7 +249,8 @@ declare function isString(val: unknown): val is string;
242
249
  * @returns `true` if the value is a percentage string.
243
250
  */
244
251
  declare function isPercentageString(val: unknown): val is string;
245
-
252
+ //#endregion
253
+ //#region src/math.d.ts
246
254
  /**
247
255
  * Clamps a number between an optional minimum and maximum value.
248
256
  * @param val The number to clamp.
@@ -259,14 +267,16 @@ declare function clampNumber(val: number, min?: number | null, max?: number | nu
259
267
  * @example getPercentOf(200, 10); // returns 20
260
268
  */
261
269
  declare function getPercentOf(val: number, percents: number): number;
262
-
270
+ //#endregion
271
+ //#region src/misc.d.ts
263
272
  /**
264
273
  * Returns the first key of an object.
265
274
  * @param obj The object from which to get the key.
266
275
  * @returns The first key of the object as a string.
267
276
  */
268
277
  declare function firstKeyOf(obj: any): string;
269
-
278
+ //#endregion
279
+ //#region src/path.d.ts
270
280
  /**
271
281
  * Ensures that the given path is returned as an array of segments.
272
282
  */
@@ -275,7 +285,8 @@ declare function ensurePathArray(path: PathType, separator?: string): string[];
275
285
  * Ensures that the given path is returned as a single string.
276
286
  */
277
287
  declare function ensurePathString(path: PathType, separator?: string): string;
278
-
288
+ //#endregion
289
+ //#region src/random.d.ts
279
290
  /**
280
291
  * Returns a random integer between min (inclusive) and max (exclusive).
281
292
  * @param min The minimum integer (inclusive).
@@ -289,5 +300,6 @@ declare function randInt(min: number, max: number): number;
289
300
  * @returns A unique string ID.
290
301
  */
291
302
  declare function randId(): string;
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 };
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/arrays.ts","../src/assertion.ts","../src/config.ts","../src/constructor-registry.ts","../src/emitter.ts","../src/guards.ts","../src/math.ts","../src/misc.ts","../src/path.ts","../src/random.ts"],"mappings":";;AAOA;AA2BA;AAOA;;;;KAlCY,QAAA;AAAA;AA2BZ;AAOA;;;;ACnCA;AAWA;AAkBA;AAmBA;AAuBA;AAcA;AAUA;AAUA;;;;ACvGA;AA4BA;;;;;;;AF7BY,KA2BA,WAAA,mBAAA,IAAA,YAA8C,CAAA;AAAA;AAO1D;;;;AAP0D,KAO9C,YAAA;EAAA,SAAA,aAAA;EAAA;;;;EAAA,SAAA,CAAA,QAAA,MAAA,IAAA,EAOoB,CAAA;EAAA,WAAA,CAAA,QAAA,MAAA,IAAA,EAEE,CAAA;EAAA,KAAA;AAAA;;;;AC5ClC;AAWA;AAkBA;AAmBA;AAuBA;iBAvEgB,QAAA,CAAA,MAAA;AAAA;AAWhB;AAkBA;AAmBA;AAuBA;AAcA;AAUA;AA/FgB,iBAWA,YAAA,GAAA,CAAA,KAAA,EAAuB,CAAA,KAAM,CAAA;AAAA;AAkB7C;AAmBA;AAuBA;AAcA;AAUA;AAUA;;;AA9F6C,iBAkB7B,iBAAA,GAAA,CAAA,IAAA,EAA2B,CAAA,IAAA,IAAA,EAAW,CAAA;AAAA;AAmBtD;AAuBA;AAcA;AAUA;AAUA;;;;ACvGA;AA4BA;;ADDsD,iBAmBtC,gBAAA,GAAA,CAAA,IAAA,GAA2B,CAAA,IAAA,IAAA,GAAY,CAAA;AA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