@axi-engine/utils 0.1.5 → 0.1.6
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 +47 -6
- package/dist/index.d.ts +47 -6
- package/dist/index.js +6 -8
- package/dist/index.mjs +6 -8
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -6,6 +6,47 @@
|
|
|
6
6
|
* ['player', 'stats', 'health']
|
|
7
7
|
*/
|
|
8
8
|
type PathType = string | string[];
|
|
9
|
+
/**
|
|
10
|
+
* Represents a generic constructor for any class.
|
|
11
|
+
*
|
|
12
|
+
* This utility type is essential for implementing higher-order patterns
|
|
13
|
+
* like mixins, where a function takes a class as an argument and returns
|
|
14
|
+
* a new, extended class.
|
|
15
|
+
*
|
|
16
|
+
* The `...args: any[]` signature allows it to represent constructors
|
|
17
|
+
* with any number and type of arguments, making it universally applicable.
|
|
18
|
+
*
|
|
19
|
+
* @template T - The type of the instance created by the constructor. Defaults to `{}`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Used as a constraint for a base class in a mixin
|
|
23
|
+
* function Timestamped<TBase extends Constructor>(Base: TBase) {
|
|
24
|
+
* return class extends Base {
|
|
25
|
+
* timestamp = new Date();
|
|
26
|
+
* };
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* class User {}
|
|
30
|
+
* const TimestampedUser = Timestamped(User);
|
|
31
|
+
* const userInstance = new TimestampedUser();
|
|
32
|
+
* console.log(userInstance.timestamp); // Logs the current date
|
|
33
|
+
*/
|
|
34
|
+
type Constructor<T = {}> = new (...args: any[]) => T;
|
|
35
|
+
/**
|
|
36
|
+
* Defines the public, read-only contract for an event emitter.
|
|
37
|
+
* It allows subscribing to an event but not emitting it.
|
|
38
|
+
* @template T A tuple representing the types of the event arguments.
|
|
39
|
+
*/
|
|
40
|
+
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;
|
|
49
|
+
};
|
|
9
50
|
|
|
10
51
|
/**
|
|
11
52
|
* Generates an array of numbers from 0 to length-1.
|
|
@@ -125,8 +166,12 @@ declare function configure(newConfig: Partial<AxiEngineConfig>): void;
|
|
|
125
166
|
* It does not manage state, it only manages subscribers and event dispatching.
|
|
126
167
|
* @template T A tuple representing the types of the event arguments.
|
|
127
168
|
*/
|
|
128
|
-
declare class Emitter<T extends any[]> {
|
|
169
|
+
declare class Emitter<T extends any[]> implements Subscribable<T> {
|
|
129
170
|
private listeners;
|
|
171
|
+
/**
|
|
172
|
+
* Returns the number of listeners.
|
|
173
|
+
*/
|
|
174
|
+
get listenerCount(): number;
|
|
130
175
|
/**
|
|
131
176
|
* Subscribes a listener to this event.
|
|
132
177
|
* @returns A function to unsubscribe the listener.
|
|
@@ -145,10 +190,6 @@ declare class Emitter<T extends any[]> {
|
|
|
145
190
|
* Clears all listeners.
|
|
146
191
|
*/
|
|
147
192
|
clear(): void;
|
|
148
|
-
/**
|
|
149
|
-
* Returns the number of listeners.
|
|
150
|
-
*/
|
|
151
|
-
get listenerCount(): number;
|
|
152
193
|
}
|
|
153
194
|
|
|
154
195
|
declare function isNullOrUndefined(val: unknown): val is null | undefined;
|
|
@@ -210,4 +251,4 @@ declare function randInt(min: number, max: number): number;
|
|
|
210
251
|
*/
|
|
211
252
|
declare function randId(): string;
|
|
212
253
|
|
|
213
|
-
export { type AxiEngineConfig, Emitter, type PathType, 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 };
|
|
254
|
+
export { type AxiEngineConfig, type Constructor, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,47 @@
|
|
|
6
6
|
* ['player', 'stats', 'health']
|
|
7
7
|
*/
|
|
8
8
|
type PathType = string | string[];
|
|
9
|
+
/**
|
|
10
|
+
* Represents a generic constructor for any class.
|
|
11
|
+
*
|
|
12
|
+
* This utility type is essential for implementing higher-order patterns
|
|
13
|
+
* like mixins, where a function takes a class as an argument and returns
|
|
14
|
+
* a new, extended class.
|
|
15
|
+
*
|
|
16
|
+
* The `...args: any[]` signature allows it to represent constructors
|
|
17
|
+
* with any number and type of arguments, making it universally applicable.
|
|
18
|
+
*
|
|
19
|
+
* @template T - The type of the instance created by the constructor. Defaults to `{}`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Used as a constraint for a base class in a mixin
|
|
23
|
+
* function Timestamped<TBase extends Constructor>(Base: TBase) {
|
|
24
|
+
* return class extends Base {
|
|
25
|
+
* timestamp = new Date();
|
|
26
|
+
* };
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* class User {}
|
|
30
|
+
* const TimestampedUser = Timestamped(User);
|
|
31
|
+
* const userInstance = new TimestampedUser();
|
|
32
|
+
* console.log(userInstance.timestamp); // Logs the current date
|
|
33
|
+
*/
|
|
34
|
+
type Constructor<T = {}> = new (...args: any[]) => T;
|
|
35
|
+
/**
|
|
36
|
+
* Defines the public, read-only contract for an event emitter.
|
|
37
|
+
* It allows subscribing to an event but not emitting it.
|
|
38
|
+
* @template T A tuple representing the types of the event arguments.
|
|
39
|
+
*/
|
|
40
|
+
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;
|
|
49
|
+
};
|
|
9
50
|
|
|
10
51
|
/**
|
|
11
52
|
* Generates an array of numbers from 0 to length-1.
|
|
@@ -125,8 +166,12 @@ declare function configure(newConfig: Partial<AxiEngineConfig>): void;
|
|
|
125
166
|
* It does not manage state, it only manages subscribers and event dispatching.
|
|
126
167
|
* @template T A tuple representing the types of the event arguments.
|
|
127
168
|
*/
|
|
128
|
-
declare class Emitter<T extends any[]> {
|
|
169
|
+
declare class Emitter<T extends any[]> implements Subscribable<T> {
|
|
129
170
|
private listeners;
|
|
171
|
+
/**
|
|
172
|
+
* Returns the number of listeners.
|
|
173
|
+
*/
|
|
174
|
+
get listenerCount(): number;
|
|
130
175
|
/**
|
|
131
176
|
* Subscribes a listener to this event.
|
|
132
177
|
* @returns A function to unsubscribe the listener.
|
|
@@ -145,10 +190,6 @@ declare class Emitter<T extends any[]> {
|
|
|
145
190
|
* Clears all listeners.
|
|
146
191
|
*/
|
|
147
192
|
clear(): void;
|
|
148
|
-
/**
|
|
149
|
-
* Returns the number of listeners.
|
|
150
|
-
*/
|
|
151
|
-
get listenerCount(): number;
|
|
152
193
|
}
|
|
153
194
|
|
|
154
195
|
declare function isNullOrUndefined(val: unknown): val is null | undefined;
|
|
@@ -210,4 +251,4 @@ declare function randInt(min: number, max: number): number;
|
|
|
210
251
|
*/
|
|
211
252
|
declare function randId(): string;
|
|
212
253
|
|
|
213
|
-
export { type AxiEngineConfig, Emitter, type PathType, 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 };
|
|
254
|
+
export { type AxiEngineConfig, type Constructor, 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 };
|
package/dist/index.js
CHANGED
|
@@ -139,8 +139,12 @@ function configure(newConfig) {
|
|
|
139
139
|
|
|
140
140
|
// src/emitter.ts
|
|
141
141
|
var Emitter = class {
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
listeners = /* @__PURE__ */ new Set();
|
|
143
|
+
/**
|
|
144
|
+
* Returns the number of listeners.
|
|
145
|
+
*/
|
|
146
|
+
get listenerCount() {
|
|
147
|
+
return this.listeners.size;
|
|
144
148
|
}
|
|
145
149
|
/**
|
|
146
150
|
* Subscribes a listener to this event.
|
|
@@ -169,12 +173,6 @@ var Emitter = class {
|
|
|
169
173
|
clear() {
|
|
170
174
|
this.listeners.clear();
|
|
171
175
|
}
|
|
172
|
-
/**
|
|
173
|
-
* Returns the number of listeners.
|
|
174
|
-
*/
|
|
175
|
-
get listenerCount() {
|
|
176
|
-
return this.listeners.size;
|
|
177
|
-
}
|
|
178
176
|
};
|
|
179
177
|
|
|
180
178
|
// src/math.ts
|
package/dist/index.mjs
CHANGED
|
@@ -88,8 +88,12 @@ function configure(newConfig) {
|
|
|
88
88
|
|
|
89
89
|
// src/emitter.ts
|
|
90
90
|
var Emitter = class {
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
listeners = /* @__PURE__ */ new Set();
|
|
92
|
+
/**
|
|
93
|
+
* Returns the number of listeners.
|
|
94
|
+
*/
|
|
95
|
+
get listenerCount() {
|
|
96
|
+
return this.listeners.size;
|
|
93
97
|
}
|
|
94
98
|
/**
|
|
95
99
|
* Subscribes a listener to this event.
|
|
@@ -118,12 +122,6 @@ var Emitter = class {
|
|
|
118
122
|
clear() {
|
|
119
123
|
this.listeners.clear();
|
|
120
124
|
}
|
|
121
|
-
/**
|
|
122
|
-
* Returns the number of listeners.
|
|
123
|
-
*/
|
|
124
|
-
get listenerCount() {
|
|
125
|
-
return this.listeners.size;
|
|
126
|
-
}
|
|
127
125
|
};
|
|
128
126
|
|
|
129
127
|
// src/math.ts
|