@oscarpalmer/timer 0.41.4 → 0.42.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.
package/types/index.d.ts DELETED
@@ -1,235 +0,0 @@
1
- declare global {
2
- var _oscarpalmer_timer_debug: boolean | undefined;
3
- var _oscarpalmer_timers: Timer[] | undefined;
4
- }
5
-
6
- // Generated by dts-bundle-generator v9.5.1
7
-
8
- /**
9
- * Options for a repeating timer
10
- */
11
- export type RepeatOptions = {
12
- /**
13
- * Callback to be called when the timer has stopped, either manually or by completing its work
14
- */
15
- onAfter: (finished: boolean) => void;
16
- /**
17
- * Callback to be called after the timer has timed out
18
- */
19
- onTimeout: () => void;
20
- /**
21
- * How many times the timer should repeat
22
- */
23
- count: number;
24
- /**
25
- * The interval between each repeat
26
- */
27
- interval: number;
28
- /**
29
- * The timeout for the timer _(any value above `0` will enable the timeout)_
30
- */
31
- timeout: number;
32
- };
33
- export type TimerOptions = {
34
- onAfter: ((finished: boolean) => void) | undefined;
35
- onError: (() => void) | undefined;
36
- count: number;
37
- interval: number;
38
- timeout: number;
39
- };
40
- export type TimerState = {
41
- active: boolean;
42
- callback: () => void;
43
- destroyed: boolean;
44
- elapsed: number;
45
- frame: number | undefined;
46
- index: number;
47
- paused: boolean;
48
- total: number;
49
- trace: string | undefined;
50
- };
51
- export type TimerType = "repeat" | "wait" | "when";
52
- /**
53
- * Options for a conditional timer
54
- */
55
- export type WhenOptions = {
56
- /**
57
- * How many times the timer should check the condition
58
- */
59
- count: number;
60
- /**
61
- * Then interval between each condtional check
62
- */
63
- interval: number;
64
- /**
65
- * The timeout for the timer _(any value above `0` will enable the timeout)_
66
- */
67
- timeout: number;
68
- };
69
- export declare class Timer {
70
- #private;
71
- protected readonly options: TimerOptions;
72
- private readonly $timer;
73
- protected readonly state: TimerState;
74
- /**
75
- * Is the timer active?
76
- */
77
- get active(): boolean;
78
- /**
79
- * Is the timer destroyed?
80
- */
81
- get destroyed(): boolean;
82
- /**
83
- * Is the timer paused?
84
- */
85
- get paused(): boolean;
86
- /**
87
- * Get the timer's origin _(if debugging is enabled)_
88
- */
89
- get trace(): string | undefined;
90
- constructor(type: TimerType, state: Pick<TimerState, "callback" | "trace">, options: TimerOptions, start: boolean);
91
- /**
92
- * Continue running the timer _(if it's paused)_
93
- */
94
- continue(): Timer;
95
- /**
96
- * Destroy the timer
97
- */
98
- destroy(): void;
99
- /**
100
- * Pause the timer _(if it's running)_
101
- */
102
- pause(): Timer;
103
- /**
104
- * Restart the timer _(or start it, if it's not running)_
105
- */
106
- restart(): Timer;
107
- /**
108
- * Start the timer _(if it's not running)_
109
- */
110
- start(): Timer;
111
- /**
112
- * Stop the timer _(if it's running)_
113
- */
114
- stop(): Timer;
115
- }
116
- export type PromiseOptions = {
117
- /**
118
- * AbortSignal for aborting the promise; when aborted, the promise will reject with the reason of the signal
119
- */
120
- signal?: AbortSignal;
121
- /**
122
- * How long to wait for (in milliseconds; defaults to `0`)
123
- */
124
- time?: number;
125
- };
126
- /**
127
- * Create a delayed promise that resolves after a certain amount of time, or rejects if aborted
128
- * @param options Options for the delay
129
- * @returns Delayed promise
130
- */
131
- export declare function delay(options?: PromiseOptions): Promise<void>;
132
- /**
133
- * Create a delayed promise that resolves after a certain amount of time
134
- * @param time How long to wait for _(in milliseconds; defaults to `0`)_
135
- * @returns Delayed promise
136
- */
137
- export declare function delay(time?: number): Promise<void>;
138
- export declare class When {
139
- private readonly $timer;
140
- private readonly state;
141
- /**
142
- * Is the timer active?
143
- */
144
- get active(): boolean;
145
- /**
146
- * Is the timer destroyed?
147
- */
148
- get destroyed(): boolean;
149
- /**
150
- * Is the timer paused?
151
- */
152
- get paused(): boolean;
153
- /**
154
- * Get the timer's origin _(if debugging is enabled)_
155
- */
156
- get trace(): string | undefined;
157
- constructor(condition: () => boolean, options?: Partial<WhenOptions>);
158
- /**
159
- * Continues the timer _(if it was paused)_
160
- */
161
- continue(): When;
162
- /**
163
- * Destroys the timer _(and stops it,if it was running)_
164
- */
165
- destroy(): void;
166
- /**
167
- * Pauses the timer _(if it was running)_
168
- */
169
- pause(): When;
170
- /**
171
- * Start the timer
172
- * @param resolve Optional resolve callback
173
- * @param reject Optional reject callback
174
- * @returns Promise that resolves when the condition is met
175
- */
176
- start(resolve?: (() => void) | null, reject?: (() => void) | null): Promise<void>;
177
- /**
178
- * Stops the timer _(if it was running)_
179
- */
180
- stop(): When;
181
- /**
182
- * Start the timer
183
- * @deprecated Use `start()` instead
184
- * @param resolve Optional resolve callback
185
- * @param reject Optional reject callback
186
- * @returns Promise that resolves when the condition is met
187
- */
188
- then(resolve?: (() => void) | null, reject?: (() => void) | null): Promise<void>;
189
- }
190
- /**
191
- * Create a conditional timer
192
- * @param condition Condition to check
193
- * @param options Timer options
194
- * @returns Timer instance
195
- */
196
- export declare function when(condition: () => boolean, options?: Partial<WhenOptions>): When;
197
- /**
198
- * Is the value a repeating timer?
199
- * @param value Value to check
200
- * @returns `true` if the value is a repeating timer
201
- */
202
- export declare function isRepeated(value: unknown): value is Timer;
203
- /**
204
- * Is the value a timer?
205
- * @param value Value to check
206
- * @returns `true` if the value is a timer
207
- */
208
- export declare function isTimer(value: unknown): value is Timer;
209
- /**
210
- * Is the value a waiting timer?
211
- * @param value Value to check
212
- * @returns `true` if the value is a waiting timer
213
- */
214
- export declare function isWaited(value: unknown): value is Timer;
215
- /**
216
- * Is the value a conditional timer?
217
- * @param value Value to check
218
- * @returns `true` if the value is a conditional timer
219
- */
220
- export declare function isWhen(value: unknown): value is When;
221
- /**
222
- * Create a repeating timer
223
- * @param callback Callback to run on each interval
224
- * @param options Timer options
225
- * @returns Timer instance
226
- */
227
- export declare function repeat(callback: (index: number) => void, options?: Partial<RepeatOptions>): Timer;
228
- /**
229
- * Create a waiting timer
230
- * @param callback Callback to run when the timer has finished
231
- * @param time How long to wait for _(in milliseconds; defaults to screen refresh rate)_
232
- */
233
- export declare function wait(callback: () => void, time?: number): Timer;
234
-
235
- export {};
package/types/models.d.ts DELETED
@@ -1,78 +0,0 @@
1
- import type { Timer } from './timer';
2
- /**
3
- * Options for a repeating timer
4
- */
5
- export type RepeatOptions = {
6
- /**
7
- * Callback to be called when the timer has stopped, either manually or by completing its work
8
- */
9
- onAfter: (finished: boolean) => void;
10
- /**
11
- * Callback to be called after the timer has timed out
12
- */
13
- onTimeout: () => void;
14
- /**
15
- * How many times the timer should repeat
16
- */
17
- count: number;
18
- /**
19
- * The interval between each repeat
20
- */
21
- interval: number;
22
- /**
23
- * The timeout for the timer _(any value above `0` will enable the timeout)_
24
- */
25
- timeout: number;
26
- };
27
- export type TimerOptions = {
28
- onAfter: ((finished: boolean) => void) | undefined;
29
- onError: (() => void) | undefined;
30
- count: number;
31
- interval: number;
32
- timeout: number;
33
- };
34
- export type TimerState = {
35
- active: boolean;
36
- callback: () => void;
37
- destroyed: boolean;
38
- elapsed: number;
39
- frame: number | undefined;
40
- index: number;
41
- paused: boolean;
42
- total: number;
43
- trace: string | undefined;
44
- };
45
- export declare class TimerTrace extends Error {
46
- constructor();
47
- }
48
- export type TimerType = 'repeat' | 'wait' | 'when';
49
- /**
50
- * Options for a conditional timer
51
- */
52
- export type WhenOptions = {
53
- /**
54
- * How many times the timer should check the condition
55
- */
56
- count: number;
57
- /**
58
- * Then interval between each condtional check
59
- */
60
- interval: number;
61
- /**
62
- * The timeout for the timer _(any value above `0` will enable the timeout)_
63
- */
64
- timeout: number;
65
- };
66
- export type WhenState = {
67
- promise: Promise<void>;
68
- rejecter?: () => void;
69
- resolver?: () => void;
70
- started: boolean;
71
- timer: Timer;
72
- };
73
- export type WorkHandler = (type: WorkHandlerType, timer: WorkHandlerTimer, state: TimerState, options: TimerOptions) => Timer;
74
- export type WorkHandlerTimer = {
75
- instance: Timer;
76
- type: TimerType;
77
- };
78
- export type WorkHandlerType = 'continue' | 'pause' | 'restart' | 'start' | 'stop';
package/types/repeat.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import './global';
2
- import { type RepeatOptions } from './models';
3
- import { Timer } from './timer';
4
- /**
5
- * Create a repeating timer
6
- * @param callback Callback to run on each interval
7
- * @param options Timer options
8
- * @returns Timer instance
9
- */
10
- export declare function repeat(callback: (index: number) => void, options?: Partial<RepeatOptions>): Timer;
11
- export type { RepeatOptions, Timer };
package/types/timer.d.ts DELETED
@@ -1,48 +0,0 @@
1
- import type { TimerOptions, TimerState, TimerType } from './models';
2
- export declare class Timer {
3
- #private;
4
- protected readonly options: TimerOptions;
5
- private readonly $timer;
6
- protected readonly state: TimerState;
7
- /**
8
- * Is the timer active?
9
- */
10
- get active(): boolean;
11
- /**
12
- * Is the timer destroyed?
13
- */
14
- get destroyed(): boolean;
15
- /**
16
- * Is the timer paused?
17
- */
18
- get paused(): boolean;
19
- /**
20
- * Get the timer's origin _(if debugging is enabled)_
21
- */
22
- get trace(): string | undefined;
23
- constructor(type: TimerType, state: Pick<TimerState, 'callback' | 'trace'>, options: TimerOptions, start: boolean);
24
- /**
25
- * Continue running the timer _(if it's paused)_
26
- */
27
- continue(): Timer;
28
- /**
29
- * Destroy the timer
30
- */
31
- destroy(): void;
32
- /**
33
- * Pause the timer _(if it's running)_
34
- */
35
- pause(): Timer;
36
- /**
37
- * Restart the timer _(or start it, if it's not running)_
38
- */
39
- restart(): Timer;
40
- /**
41
- * Start the timer _(if it's not running)_
42
- */
43
- start(): Timer;
44
- /**
45
- * Stop the timer _(if it's running)_
46
- */
47
- stop(): Timer;
48
- }
package/types/when.d.ts DELETED
@@ -1,62 +0,0 @@
1
- import './global';
2
- import { type WhenOptions } from './models';
3
- declare class When {
4
- private readonly $timer;
5
- private readonly state;
6
- /**
7
- * Is the timer active?
8
- */
9
- get active(): boolean;
10
- /**
11
- * Is the timer destroyed?
12
- */
13
- get destroyed(): boolean;
14
- /**
15
- * Is the timer paused?
16
- */
17
- get paused(): boolean;
18
- /**
19
- * Get the timer's origin _(if debugging is enabled)_
20
- */
21
- get trace(): string | undefined;
22
- constructor(condition: () => boolean, options?: Partial<WhenOptions>);
23
- /**
24
- * Continues the timer _(if it was paused)_
25
- */
26
- continue(): When;
27
- /**
28
- * Destroys the timer _(and stops it,if it was running)_
29
- */
30
- destroy(): void;
31
- /**
32
- * Pauses the timer _(if it was running)_
33
- */
34
- pause(): When;
35
- /**
36
- * Start the timer
37
- * @param resolve Optional resolve callback
38
- * @param reject Optional reject callback
39
- * @returns Promise that resolves when the condition is met
40
- */
41
- start(resolve?: (() => void) | null, reject?: (() => void) | null): Promise<void>;
42
- /**
43
- * Stops the timer _(if it was running)_
44
- */
45
- stop(): When;
46
- /**
47
- * Start the timer
48
- * @deprecated Use `start()` instead
49
- * @param resolve Optional resolve callback
50
- * @param reject Optional reject callback
51
- * @returns Promise that resolves when the condition is met
52
- */
53
- then(resolve?: (() => void) | null, reject?: (() => void) | null): Promise<void>;
54
- }
55
- /**
56
- * Create a conditional timer
57
- * @param condition Condition to check
58
- * @param options Timer options
59
- * @returns Timer instance
60
- */
61
- export declare function when(condition: () => boolean, options?: Partial<WhenOptions>): When;
62
- export type { When };
package/types/work.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import type { TimerOptions, TimerState, WorkHandlerTimer, WorkHandlerType } from './models';
2
- import type { Timer } from './timer';
3
- export declare function stop(timer: WorkHandlerTimer, state: TimerState, options: TimerOptions): Timer;
4
- export declare function work(type: WorkHandlerType, timer: WorkHandlerTimer, state: TimerState, options: TimerOptions): Timer;