@axi-engine/utils 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Generates an array of numbers from 0 to length-1.
3
+ * @param length The desired length of the array.
4
+ * @returns An array of sequential numbers.
5
+ * @example genArray(3); // returns [0, 1, 2]
6
+ */
7
+ export declare function genArray(length: number): number[];
8
+ /**
9
+ * Creates a new array with its elements shuffled in a random order.
10
+ * This function does not mutate the original array.
11
+ * @template T The type of elements in the array.
12
+ * @param array The array to shuffle.
13
+ * @returns A new, shuffled array.
14
+ */
15
+ export declare function shuffleArray<T>(array: T[]): T[];
16
+ /**
17
+ * Checks if the first array is a sequential starting subset of the second array.
18
+ * @param arr1 The potential subset array.
19
+ * @param arr2 The array to check against.
20
+ * @returns `true` if arr1 is a sequential start of arr2, otherwise `false`.
21
+ * @example
22
+ * isSequentialStart([1, 2], [1, 2, 3]); // true
23
+ * isSequentialStart([1, 3], [1, 2, 3]); // false
24
+ */
25
+ export declare function isSequentialStart<T>(arr1: T[], arr2: T[]): boolean;
26
+ /**
27
+ * Checks if two arrays contain the same elements, ignoring order.
28
+ * Works for arrays of primitives like strings or numbers.
29
+ * @template T The type of elements in the array.
30
+ * @param arr1 The first array.
31
+ * @param arr2 The second array.
32
+ * @returns `true` if both arrays contain the same elements, otherwise `false`.
33
+ * @example
34
+ * haveSameElements(['a', 'b'], ['b', 'a']); // true
35
+ * haveSameElements([1, 2, 3], [3, 1, 2]); // true
36
+ * haveSameElements(['a', 'b'], ['a', 'c']); // false
37
+ */
38
+ export declare function haveSameElements<T>(arr1?: T[], arr2?: T[]): boolean;
39
+ /**
40
+ * Checks if two arrays are strictly equal (same elements in the same order).
41
+ * @template T The type of elements in the array.
42
+ * @param arr1 The first array.
43
+ * @param arr2 The second array.
44
+ * @returns `true` if the arrays are strictly equal, otherwise `false`.
45
+ * @example
46
+ * areArraysEqual(['a', 'b'], ['a', 'b']); // true
47
+ * areArraysEqual(['a', 'b'], ['b', 'a']); // false
48
+ * areArraysEqual([1, 2], [1, 2, 3]); // false
49
+ */
50
+ export declare function areArraysEqual<T>(arr1?: T[], arr2?: T[]): boolean;
51
+ /**
52
+ * Gets the last element of an array.
53
+ * @template T The type of elements in the array.
54
+ * @param array The array to query.
55
+ * @returns The last element of the array, or `undefined` if the array is empty.
56
+ */
57
+ export declare function last<T>(array: T[]): T | undefined;
58
+ /**
59
+ * Creates a duplicate-free version of an array.
60
+ * @template T The type of elements in the array.
61
+ * @param array The array to process.
62
+ * @returns A new array with only unique elements.
63
+ */
64
+ export declare function unique<T>(array: T[]): T[];
65
+ /**
66
+ * Gets a random element from an array.
67
+ * @template T The type of elements in the array.
68
+ * @param array The array to choose from.
69
+ * @returns A random element from the array, or `undefined` if the array is empty.
70
+ */
71
+ export declare function getRandomElement<T>(array: T[]): T | undefined;
72
+ //# sourceMappingURL=arrays.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arrays.d.ts","sourceRoot":"","sources":["../src/arrays.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,YAEtC;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAO/C;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,OAAO,CAKlE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,GAAG,OAAO,CAUnE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,GAAG,OAAO,CAMjE;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,CAEjD;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAEzC;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,CAM7D"}
package/dist/arrays.js ADDED
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Generates an array of numbers from 0 to length-1.
3
+ * @param length The desired length of the array.
4
+ * @returns An array of sequential numbers.
5
+ * @example genArray(3); // returns [0, 1, 2]
6
+ */
7
+ export function genArray(length) {
8
+ return Array.from({ length }, (_v, i) => i);
9
+ }
10
+ /**
11
+ * Creates a new array with its elements shuffled in a random order.
12
+ * This function does not mutate the original array.
13
+ * @template T The type of elements in the array.
14
+ * @param array The array to shuffle.
15
+ * @returns A new, shuffled array.
16
+ */
17
+ export function shuffleArray(array) {
18
+ const result = [...array];
19
+ for (let i = result.length - 1; i > 0; i--) {
20
+ const j = Math.floor(Math.random() * (i + 1));
21
+ [result[i], result[j]] = [result[j], result[i]];
22
+ }
23
+ return result;
24
+ }
25
+ /**
26
+ * Checks if the first array is a sequential starting subset of the second array.
27
+ * @param arr1 The potential subset array.
28
+ * @param arr2 The array to check against.
29
+ * @returns `true` if arr1 is a sequential start of arr2, otherwise `false`.
30
+ * @example
31
+ * isSequentialStart([1, 2], [1, 2, 3]); // true
32
+ * isSequentialStart([1, 3], [1, 2, 3]); // false
33
+ */
34
+ export function isSequentialStart(arr1, arr2) {
35
+ if (arr1.length > arr2.length) {
36
+ return false;
37
+ }
38
+ return arr1.every((element, index) => element === arr2[index]);
39
+ }
40
+ /**
41
+ * Checks if two arrays contain the same elements, ignoring order.
42
+ * Works for arrays of primitives like strings or numbers.
43
+ * @template T The type of elements in the array.
44
+ * @param arr1 The first array.
45
+ * @param arr2 The second array.
46
+ * @returns `true` if both arrays contain the same elements, otherwise `false`.
47
+ * @example
48
+ * haveSameElements(['a', 'b'], ['b', 'a']); // true
49
+ * haveSameElements([1, 2, 3], [3, 1, 2]); // true
50
+ * haveSameElements(['a', 'b'], ['a', 'c']); // false
51
+ */
52
+ export function haveSameElements(arr1, arr2) {
53
+ if (!arr1 && !arr2)
54
+ return true;
55
+ if (!arr1 || !arr2)
56
+ return false;
57
+ if (arr1.length !== arr2.length)
58
+ return false;
59
+ // Create sorted copies to compare
60
+ const sortedArr1 = [...arr1].sort();
61
+ const sortedArr2 = [...arr2].sort();
62
+ return sortedArr1.every((value, index) => value === sortedArr2[index]);
63
+ }
64
+ /**
65
+ * Checks if two arrays are strictly equal (same elements in the same order).
66
+ * @template T The type of elements in the array.
67
+ * @param arr1 The first array.
68
+ * @param arr2 The second array.
69
+ * @returns `true` if the arrays are strictly equal, otherwise `false`.
70
+ * @example
71
+ * areArraysEqual(['a', 'b'], ['a', 'b']); // true
72
+ * areArraysEqual(['a', 'b'], ['b', 'a']); // false
73
+ * areArraysEqual([1, 2], [1, 2, 3]); // false
74
+ */
75
+ export function areArraysEqual(arr1, arr2) {
76
+ if (!arr1 && !arr2)
77
+ return true;
78
+ if (!arr1 || !arr2)
79
+ return false;
80
+ if (arr1.length !== arr2.length)
81
+ return false;
82
+ return arr1.every((value, index) => value === arr2[index]);
83
+ }
84
+ /**
85
+ * Gets the last element of an array.
86
+ * @template T The type of elements in the array.
87
+ * @param array The array to query.
88
+ * @returns The last element of the array, or `undefined` if the array is empty.
89
+ */
90
+ export function last(array) {
91
+ return array[array.length - 1];
92
+ }
93
+ /**
94
+ * Creates a duplicate-free version of an array.
95
+ * @template T The type of elements in the array.
96
+ * @param array The array to process.
97
+ * @returns A new array with only unique elements.
98
+ */
99
+ export function unique(array) {
100
+ return [...new Set(array)];
101
+ }
102
+ /**
103
+ * Gets a random element from an array.
104
+ * @template T The type of elements in the array.
105
+ * @param array The array to choose from.
106
+ * @returns A random element from the array, or `undefined` if the array is empty.
107
+ */
108
+ export function getRandomElement(array) {
109
+ if (array.length === 0) {
110
+ return undefined;
111
+ }
112
+ const index = Math.floor(Math.random() * array.length);
113
+ return array[index];
114
+ }
115
+ //# sourceMappingURL=arrays.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arrays.js","sourceRoot":"","sources":["../src/arrays.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Throws an error if the condition is true.
3
+ * @param conditionForThrow - If true, an error will be thrown.
4
+ * @param exceptionMessage - The message for the error.
5
+ * @throws {Error} if the value is true
6
+ */
7
+ export declare function throwIf(conditionForThrow: boolean, exceptionMessage: string): void | never;
8
+ /**
9
+ * Throws an error if the value is null, undefined, or an empty array.
10
+ *
11
+ * @template T The type of the value being checked.
12
+ * @param value The value to check.
13
+ * @param exceptionMessage The message for the error.
14
+ * @throws {Error} if the value is null, undefined, or an empty array.
15
+ *
16
+ * @example
17
+ * // Example with a potentially undefined variable
18
+ * const user: { name: string } | undefined = findUser();
19
+ * throwIfEmpty(user, 'User not found');
20
+ * // From here, TypeScript knows `user` is not undefined.
21
+ * console.log(user.name);
22
+ *
23
+ * @example
24
+ * // Example with an array
25
+ * const items: string[] = getItems();
26
+ * throwIfEmpty(items, 'Items array cannot be empty');
27
+ * // From here, you can safely access items[0] without checking for an empty array again.
28
+ * console.log('First item:', items[0]);
29
+ */
30
+ export declare function throwIfEmpty<T>(value: T, exceptionMessage: string): asserts value is NonNullable<T>;
31
+ //# sourceMappingURL=assertion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertion.d.ts","sourceRoot":"","sources":["../src/assertion.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,iBAAiB,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,KAAK,CAI1F;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,KAAK,EAAE,CAAC,EACR,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,KAAK,IAAI,WAAW,CAAC,CAAC,CAAC,CAMjC"}
@@ -0,0 +1,41 @@
1
+ import { isNullOrUndefined } from './guards';
2
+ /**
3
+ * Throws an error if the condition is true.
4
+ * @param conditionForThrow - If true, an error will be thrown.
5
+ * @param exceptionMessage - The message for the error.
6
+ * @throws {Error} if the value is true
7
+ */
8
+ export function throwIf(conditionForThrow, exceptionMessage) {
9
+ if (conditionForThrow) {
10
+ throw new Error(exceptionMessage);
11
+ }
12
+ }
13
+ /**
14
+ * Throws an error if the value is null, undefined, or an empty array.
15
+ *
16
+ * @template T The type of the value being checked.
17
+ * @param value The value to check.
18
+ * @param exceptionMessage The message for the error.
19
+ * @throws {Error} if the value is null, undefined, or an empty array.
20
+ *
21
+ * @example
22
+ * // Example with a potentially undefined variable
23
+ * const user: { name: string } | undefined = findUser();
24
+ * throwIfEmpty(user, 'User not found');
25
+ * // From here, TypeScript knows `user` is not undefined.
26
+ * console.log(user.name);
27
+ *
28
+ * @example
29
+ * // Example with an array
30
+ * const items: string[] = getItems();
31
+ * throwIfEmpty(items, 'Items array cannot be empty');
32
+ * // From here, you can safely access items[0] without checking for an empty array again.
33
+ * console.log('First item:', items[0]);
34
+ */
35
+ export function throwIfEmpty(value, exceptionMessage) {
36
+ const isArrayAndEmpty = Array.isArray(value) && value.length === 0;
37
+ if (isNullOrUndefined(value) || isArrayAndEmpty) {
38
+ throw new Error(exceptionMessage);
39
+ }
40
+ }
41
+ //# sourceMappingURL=assertion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertion.js","sourceRoot":"","sources":["../src/assertion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,UAAU,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,iBAA0B,EAAE,gBAAwB;IAC1E,IAAI,iBAAiB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACpC,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAQ,EACR,gBAAwB;IAExB,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;IAEnE,IAAI,iBAAiB,CAAC,KAAK,CAAC,IAAI,eAAe,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;IACpC,CAAC;AACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ export interface AxiEngineConfig {
2
+ pathSeparator: string;
3
+ }
4
+ export declare const axiSettings: AxiEngineConfig;
5
+ /**
6
+ * set up global configuration for axi-engine.
7
+ * @param newConfig - configuration object
8
+ */
9
+ export declare function configure(newConfig: Partial<AxiEngineConfig>): void;
10
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,MAAM,CAAC;CAKvB;AAMD,eAAO,MAAM,WAAW,EAAE,eAAsC,CAAC;AAEjE;;;GAGG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI,CAEnE"}
package/dist/config.js ADDED
@@ -0,0 +1,12 @@
1
+ const defaultConfig = {
2
+ pathSeparator: '/'
3
+ };
4
+ export const axiSettings = { ...defaultConfig };
5
+ /**
6
+ * set up global configuration for axi-engine.
7
+ * @param newConfig - configuration object
8
+ */
9
+ export function configure(newConfig) {
10
+ Object.assign(axiSettings, newConfig);
11
+ }
12
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAQA,MAAM,aAAa,GAAoB;IACrC,aAAa,EAAE,GAAG;CACnB,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAoB,EAAE,GAAG,aAAa,EAAE,CAAC;AAEjE;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,SAAmC;IAC3D,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AACxC,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { Constructor } from './types';
2
+ /**
3
+ * A generic registry for mapping string identifiers to class constructors.
4
+ *
5
+ * This utility is fundamental for building extensible systems like dependency injection containers,
6
+ * factories, and serialization engines where types need to be dynamically resolved.
7
+ *
8
+ * @template T - A base type that all registered constructors must produce an instance of.
9
+ */
10
+ export declare class ConstructorRegistry<T> {
11
+ private readonly items;
12
+ /**
13
+ * Registers a constructor with a unique string identifier.
14
+ *
15
+ * @param typeId - The unique identifier for the constructor (e.g., a static `typeName` property from a class).
16
+ * @param ctor - The class constructor to register.
17
+ * @returns The registry instance for chainable calls.
18
+ * @throws If a constructor with the same `typeId` is already registered.
19
+ */
20
+ register(typeId: string, ctor: Constructor<T>): this;
21
+ /**
22
+ * Retrieves a constructor by its identifier.
23
+ *
24
+ * @param typeId - The identifier of the constructor to retrieve.
25
+ * @returns The found class constructor.
26
+ * @throws If no constructor is found for the given `typeId`.
27
+ */
28
+ get(typeId: string): Constructor<T>;
29
+ /**
30
+ * Checks if a constructor for a given identifier is registered.
31
+ * @param typeId - The identifier to check.
32
+ * @returns `true` if a constructor is registered, otherwise `false`.
33
+ */
34
+ has(typeId: string): boolean;
35
+ /**
36
+ * Clears all registered constructors from the registry.
37
+ */
38
+ clear(): void;
39
+ }
40
+ //# sourceMappingURL=constructor-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constructor-registry.d.ts","sourceRoot":"","sources":["../src/constructor-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAGpC;;;;;;;GAOG;AACH,qBAAa,mBAAmB,CAAC,CAAC;IAChC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqC;IAE3D;;;;;;;OAOG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI;IAMpD;;;;;;OAMG;IACH,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC;IAMnC;;;;OAIG;IACH,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAI5B;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd"}
@@ -0,0 +1,52 @@
1
+ import { throwIf, throwIfEmpty } from './assertion';
2
+ /**
3
+ * A generic registry for mapping string identifiers to class constructors.
4
+ *
5
+ * This utility is fundamental for building extensible systems like dependency injection containers,
6
+ * factories, and serialization engines where types need to be dynamically resolved.
7
+ *
8
+ * @template T - A base type that all registered constructors must produce an instance of.
9
+ */
10
+ export class ConstructorRegistry {
11
+ items = new Map();
12
+ /**
13
+ * Registers a constructor with a unique string identifier.
14
+ *
15
+ * @param typeId - The unique identifier for the constructor (e.g., a static `typeName` property from a class).
16
+ * @param ctor - The class constructor to register.
17
+ * @returns The registry instance for chainable calls.
18
+ * @throws If a constructor with the same `typeId` is already registered.
19
+ */
20
+ register(typeId, ctor) {
21
+ throwIf(this.items.has(typeId), `A constructor with typeId '${typeId}' is already registered.`);
22
+ this.items.set(typeId, ctor);
23
+ return this;
24
+ }
25
+ /**
26
+ * Retrieves a constructor by its identifier.
27
+ *
28
+ * @param typeId - The identifier of the constructor to retrieve.
29
+ * @returns The found class constructor.
30
+ * @throws If no constructor is found for the given `typeId`.
31
+ */
32
+ get(typeId) {
33
+ const Ctor = this.items.get(typeId);
34
+ throwIfEmpty(Ctor, `No constructor found for typeId '${typeId}'`);
35
+ return Ctor;
36
+ }
37
+ /**
38
+ * Checks if a constructor for a given identifier is registered.
39
+ * @param typeId - The identifier to check.
40
+ * @returns `true` if a constructor is registered, otherwise `false`.
41
+ */
42
+ has(typeId) {
43
+ return this.items.has(typeId);
44
+ }
45
+ /**
46
+ * Clears all registered constructors from the registry.
47
+ */
48
+ clear() {
49
+ this.items.clear();
50
+ }
51
+ }
52
+ //# sourceMappingURL=constructor-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constructor-registry.js","sourceRoot":"","sources":["../src/constructor-registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAE,YAAY,EAAC,MAAM,aAAa,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,OAAO,mBAAmB;IACb,KAAK,GAAG,IAAI,GAAG,EAA0B,CAAC;IAE3D;;;;;;;OAOG;IACH,QAAQ,CAAC,MAAc,EAAE,IAAoB;QAC3C,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,8BAA8B,MAAM,0BAA0B,CAAC,CAAC;QAChG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACH,GAAG,CAAC,MAAc;QAChB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACpC,YAAY,CAAC,IAAI,EAAE,oCAAoC,MAAM,GAAG,CAAC,CAAC;QAClE,OAAO,IAAK,CAAC;IACf,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,MAAc;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,32 @@
1
+ import { Subscribable } from './types';
2
+ /**
3
+ * A minimal, type-safe event emitter for a single event.
4
+ * It does not manage state, it only manages subscribers and event dispatching.
5
+ * @template T A tuple representing the types of the event arguments.
6
+ */
7
+ export declare class Emitter<T extends any[]> implements Subscribable<T> {
8
+ private listeners;
9
+ /**
10
+ * Returns the number of listeners.
11
+ */
12
+ get listenerCount(): number;
13
+ /**
14
+ * Subscribes a listener to this event.
15
+ * @returns A function to unsubscribe the listener.
16
+ */
17
+ subscribe(listener: (...args: T) => void): () => void;
18
+ /**
19
+ * Manually unsubscribe by listener
20
+ * @returns returns true if an listener has been removed, or false if the listener does not exist.
21
+ */
22
+ unsubscribe(listener: (...args: T) => void): boolean;
23
+ /**
24
+ * Dispatches the event to all subscribed listeners.
25
+ */
26
+ emit(...args: T): void;
27
+ /**
28
+ * Clears all listeners.
29
+ */
30
+ clear(): void;
31
+ }
32
+ //# sourceMappingURL=emitter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitter.d.ts","sourceRoot":"","sources":["../src/emitter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,YAAY,EAAC,MAAM,SAAS,CAAC;AAErC;;;;GAIG;AACH,qBAAa,OAAO,CAAC,CAAC,SAAS,GAAG,EAAE,CAAE,YAAW,YAAY,CAAC,CAAC,CAAC;IAC9D,OAAO,CAAC,SAAS,CAAwC;IAEzD;;OAEG;IACH,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED;;;OAGG;IACH,SAAS,CAAC,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI;IAKrD;;;OAGG;IACH,WAAW,CAAC,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,IAAI;IAI1C;;OAEG;IACH,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI;IAItB;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd"}
@@ -0,0 +1,43 @@
1
+ // file: packages/utils/src/emitter.ts
2
+ /**
3
+ * A minimal, type-safe event emitter for a single event.
4
+ * It does not manage state, it only manages subscribers and event dispatching.
5
+ * @template T A tuple representing the types of the event arguments.
6
+ */
7
+ export class Emitter {
8
+ listeners = new Set();
9
+ /**
10
+ * Returns the number of listeners.
11
+ */
12
+ get listenerCount() {
13
+ return this.listeners.size;
14
+ }
15
+ /**
16
+ * Subscribes a listener to this event.
17
+ * @returns A function to unsubscribe the listener.
18
+ */
19
+ subscribe(listener) {
20
+ this.listeners.add(listener);
21
+ return () => this.listeners.delete(listener);
22
+ }
23
+ /**
24
+ * Manually unsubscribe by listener
25
+ * @returns returns true if an listener has been removed, or false if the listener does not exist.
26
+ */
27
+ unsubscribe(listener) {
28
+ return this.listeners.delete(listener);
29
+ }
30
+ /**
31
+ * Dispatches the event to all subscribed listeners.
32
+ */
33
+ emit(...args) {
34
+ this.listeners.forEach(listener => listener(...args));
35
+ }
36
+ /**
37
+ * Clears all listeners.
38
+ */
39
+ clear() {
40
+ this.listeners.clear();
41
+ }
42
+ }
43
+ //# sourceMappingURL=emitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitter.js","sourceRoot":"","sources":["../src/emitter.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAItC;;;;GAIG;AACH,MAAM,OAAO,OAAO;IACV,SAAS,GAA8B,IAAI,GAAG,EAAE,CAAC;IAEzD;;OAEG;IACH,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,SAAS,CAAC,QAA8B;QACtC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC7B,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAED;;;OAGG;IACH,WAAW,CAAC,QAA8B;QACxC,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,IAAI,CAAC,GAAG,IAAO;QACb,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IACxD,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ export declare function isNullOrUndefined(val: unknown): val is null | undefined;
2
+ export declare function isUndefined(val: unknown): val is undefined;
3
+ export declare function isNumber(val: unknown): val is number;
4
+ export declare function isBoolean(val: unknown): val is boolean;
5
+ export declare function isString(val: unknown): val is string;
6
+ /**
7
+ * Type guard to check if a value is a string that ends with '%'.
8
+ * @param val The value to check.
9
+ * @returns `true` if the value is a percentage string.
10
+ */
11
+ export declare function isPercentageString(val: unknown): val is string;
12
+ //# sourceMappingURL=guards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,IAAI,GAAG,SAAS,CAEvE;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,SAAS,CAE1D;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAEpD;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,OAAO,CAEtD;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAE9D"}
package/dist/guards.js ADDED
@@ -0,0 +1,24 @@
1
+ export function isNullOrUndefined(val) {
2
+ return val === undefined || val === null;
3
+ }
4
+ export function isUndefined(val) {
5
+ return typeof val === 'undefined';
6
+ }
7
+ export function isNumber(val) {
8
+ return typeof val === "number";
9
+ }
10
+ export function isBoolean(val) {
11
+ return typeof val === "boolean";
12
+ }
13
+ export function isString(val) {
14
+ return typeof val === "string";
15
+ }
16
+ /**
17
+ * Type guard to check if a value is a string that ends with '%'.
18
+ * @param val The value to check.
19
+ * @returns `true` if the value is a percentage string.
20
+ */
21
+ export function isPercentageString(val) {
22
+ return typeof val === "string" && val.endsWith("%");
23
+ }
24
+ //# sourceMappingURL=guards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guards.js","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,iBAAiB,CAAC,GAAY;IAC5C,OAAO,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,OAAO,OAAO,GAAG,KAAK,WAAW,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,GAAY;IACnC,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,GAAY;IACpC,OAAO,OAAO,GAAG,KAAK,SAAS,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,GAAY;IACnC,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC;AACjC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC7C,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AACtD,CAAC"}