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