@oscarpalmer/timer 0.42.0 → 0.44.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/README.md CHANGED
@@ -64,7 +64,7 @@ function callback(index) {
64
64
  // 'index' is the current step
65
65
  // starts at 0, goes up to a maximum of count - 1
66
66
  // for this example: 0 → 9
67
- };
67
+ }
68
68
  ```
69
69
 
70
70
  When you create a repeated timer, you can also provide a callback to run when the timer stops, as below:
@@ -1,6 +1,4 @@
1
- import { Timer } from "./timer.mjs";
2
- import { TimerType, WorkHandlerType } from "./models.mjs";
3
-
1
+ import { Timer, TimerName, WorkHandlerType } from "./models.mjs";
4
2
  //#region src/constants.d.ts
5
3
  /**
6
4
  * Buffer value to use when evaluating if a specific time is within a certain range
@@ -23,9 +21,9 @@ declare const TIMERS_ACTIVE: Set<Timer>;
23
21
  * A set of timers that were paused due to the document being hidden
24
22
  */
25
23
  declare const TIMERS_HIDDEN: Set<Timer>;
26
- declare const TYPE_REPEAT: TimerType;
27
- declare const TYPE_WAIT: TimerType;
28
- declare const TYPE_WHEN: TimerType;
24
+ declare const TYPE_REPEAT: TimerName;
25
+ declare const TYPE_WAIT: TimerName;
26
+ declare const TYPE_WHEN: TimerName;
29
27
  declare const WORK_CONTINUE: WorkHandlerType;
30
28
  declare const WORK_PAUSE: WorkHandlerType;
31
29
  declare const WORK_RESTART: WorkHandlerType;
package/dist/delay.d.mts CHANGED
@@ -1,3 +1,2 @@
1
1
  import { delay } from "@oscarpalmer/atoms/promise/delay";
2
- import { PromiseOptions } from "@oscarpalmer/atoms/promise/models";
3
- export { type PromiseOptions, delay };
2
+ export { delay };
package/dist/get.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { GenericCallback } from "@oscarpalmer/atoms/models";
2
-
3
2
  //#region src/get.d.ts
4
3
  declare function getCallback(value: unknown): GenericCallback;
5
4
  declare function getValidTimeout(value: unknown): number;
package/dist/global.d.mts CHANGED
@@ -1,5 +1,4 @@
1
- import { Timer } from "./timer.mjs";
2
-
1
+ import { Timer } from "./models.mjs";
3
2
  //#region src/global.d.ts
4
3
  declare global {
5
4
  var _oscarpalmer_timer_debug: boolean | undefined;
package/dist/index.d.mts CHANGED
@@ -24,49 +24,7 @@ type RepeatOptions = {
24
24
  */
25
25
  timeout: number;
26
26
  };
27
- type TimerOptions = {
28
- onAfter: ((finished: boolean) => void) | undefined;
29
- onError: (() => void) | undefined;
30
- count: number;
31
- interval: number;
32
- timeout: number;
33
- };
34
- 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
- type TimerType = 'repeat' | 'wait' | 'when';
46
- /**
47
- * Options for a conditional timer
48
- */
49
- type WhenOptions = {
50
- /**
51
- * How many times the timer should check the condition
52
- */
53
- count: number;
54
- /**
55
- * Then interval between each condtional check
56
- */
57
- interval: number;
58
- /**
59
- * The timeout for the timer _(any value above `0` will enable the timeout)_
60
- */
61
- timeout: number;
62
- };
63
- //#endregion
64
- //#region src/timer.d.ts
65
- declare class Timer {
66
- #private;
67
- protected readonly options: TimerOptions;
68
- private readonly $timer;
69
- protected readonly state: TimerState;
27
+ type Timer = {
70
28
  /**
71
29
  * Is the timer active?
72
30
  */
@@ -83,7 +41,6 @@ declare class Timer {
83
41
  * Get the timer's origin _(if debugging is enabled)_
84
42
  */
85
43
  get trace(): string | undefined;
86
- constructor(type: TimerType, state: Pick<TimerState, 'callback' | 'trace'>, options: TimerOptions, start: boolean);
87
44
  /**
88
45
  * Continue running the timer _(if it's paused)_
89
46
  */
@@ -108,45 +65,15 @@ declare class Timer {
108
65
  * Stop the timer _(if it's running)_
109
66
  */
110
67
  stop(): Timer;
111
- }
112
- //#endregion
113
- //#region src/global.d.ts
114
- declare global {
115
- var _oscarpalmer_timer_debug: boolean | undefined;
116
- var _oscarpalmer_timers: Timer[] | undefined;
117
- }
118
- //#endregion
119
- //#region node_modules/@oscarpalmer/atoms/dist/promise/models.d.mts
120
- type PromiseOptions = {
121
- /**
122
- * AbortSignal for aborting the promise; when aborted, the promise will reject with the reason of the signal
123
- */
124
- signal?: AbortSignal;
125
- /**
126
- * How long to wait for (in milliseconds; defaults to `0`)
127
- */
128
- time?: number;
129
68
  };
130
- //#endregion
131
- //#region node_modules/@oscarpalmer/atoms/dist/promise/delay.d.mts
132
- //#region src/promise/delay.d.ts
133
- /**
134
- * Create a delayed promise that resolves after a certain amount of time, or rejects if aborted
135
- * @param options Options for the delay
136
- * @returns Delayed promise
137
- */
138
- declare function delay(options?: PromiseOptions): Promise<void>;
139
- /**
140
- * Create a delayed promise that resolves after a certain amount of time
141
- * @param time How long to wait for _(in milliseconds; defaults to `0`)_
142
- * @returns Delayed promise
143
- */
144
- declare function delay(time?: number): Promise<void>; //#endregion
145
- //#endregion
146
- //#region src/when.d.ts
147
- declare class When {
148
- private readonly $timer;
149
- private readonly state;
69
+ type TimerOptions = {
70
+ onAfter: ((finished: boolean) => void) | undefined;
71
+ onError: (() => void) | undefined;
72
+ count: number;
73
+ interval: number;
74
+ timeout: number;
75
+ };
76
+ type When = {
150
77
  /**
151
78
  * Is the timer active?
152
79
  */
@@ -163,7 +90,6 @@ declare class When {
163
90
  * Get the timer's origin _(if debugging is enabled)_
164
91
  */
165
92
  get trace(): string | undefined;
166
- constructor(condition: () => boolean, options?: Partial<WhenOptions>);
167
93
  /**
168
94
  * Continues the timer _(if it was paused)_
169
95
  */
@@ -178,31 +104,71 @@ declare class When {
178
104
  pause(): When;
179
105
  /**
180
106
  * Start the timer
107
+ *
181
108
  * @param resolve Optional resolve callback
182
- * @param reject Optional reject callback
183
109
  * @returns Promise that resolves when the condition is met
184
110
  */
185
- start(resolve?: (() => void) | null, reject?: (() => void) | null): Promise<void>;
111
+ start(resolve?: (() => void) | null): Promise<void>;
186
112
  /**
187
113
  * Stops the timer _(if it was running)_
188
114
  */
189
115
  stop(): When;
116
+ };
117
+ /**
118
+ * Options for a conditional timer
119
+ */
120
+ type WhenOptions = {
190
121
  /**
191
- * Start the timer
192
- * @deprecated Use `start()` instead
193
- * @param resolve Optional resolve callback
194
- * @param reject Optional reject callback
195
- * @returns Promise that resolves when the condition is met
122
+ * How many times the timer should check the condition
123
+ */
124
+ count: number;
125
+ /**
126
+ * Then interval between each condtional check
127
+ */
128
+ interval: number;
129
+ /**
130
+ * The timeout for the timer _(any value above `0` will enable the timeout)_
196
131
  */
197
- then(resolve?: (() => void) | null, reject?: (() => void) | null): Promise<void>;
132
+ timeout: number;
133
+ };
134
+ //#endregion
135
+ //#region src/global.d.ts
136
+ declare global {
137
+ var _oscarpalmer_timer_debug: boolean | undefined;
138
+ var _oscarpalmer_timers: Timer[] | undefined;
198
139
  }
140
+ //#endregion
141
+ //#region node_modules/@oscarpalmer/atoms/dist/promise/models.d.mts
199
142
  /**
200
- * Create a conditional timer
201
- * @param condition Condition to check
202
- * @param options Timer options
203
- * @returns Timer instance
143
+ * Options for a _Promise_-handling function
204
144
  */
205
- declare function when(condition: () => boolean, options?: Partial<WhenOptions>): When;
145
+ type PromiseOptions = {
146
+ /**
147
+ * AbortSignal for aborting the _Promise_; when aborted, the _Promise_ will reject with the reason of the signal
148
+ */
149
+ signal?: AbortSignal;
150
+ /**
151
+ * How long to wait for _(in milliseconds; defaults to `0`)_
152
+ */
153
+ time?: number;
154
+ };
155
+ //#endregion
156
+ //#region node_modules/@oscarpalmer/atoms/dist/promise/delay.d.mts
157
+ //#region src/promise/delay.d.ts
158
+ /**
159
+ * Create a delayed promise that resolves after a certain amount of time, or rejects if aborted
160
+ *
161
+ * @param options Options for the delay
162
+ * @returns Delayed promise
163
+ */
164
+ declare function delay(options?: PromiseOptions): Promise<void>;
165
+ /**
166
+ * Create a delayed promise that resolves after a certain amount of time
167
+ *
168
+ * @param time How long to wait for _(in milliseconds; defaults to `0`)_
169
+ * @returns Delayed promise
170
+ */
171
+ declare function delay(time?: number): Promise<void>;
206
172
  //#endregion
207
173
  //#region src/is.d.ts
208
174
  /**
@@ -233,6 +199,7 @@ declare function isWhen(value: unknown): value is When;
233
199
  //#region src/repeat.d.ts
234
200
  /**
235
201
  * Create a repeating timer
202
+ *
236
203
  * @param callback Callback to run on each interval
237
204
  * @param options Timer options
238
205
  * @returns Timer instance
@@ -242,9 +209,19 @@ declare function repeat(callback: (index: number) => void, options?: Partial<Rep
242
209
  //#region src/wait.d.ts
243
210
  /**
244
211
  * Create a waiting timer
212
+ *
245
213
  * @param callback Callback to run when the timer has finished
246
214
  * @param time How long to wait for _(in milliseconds; defaults to screen refresh rate)_
247
215
  */
248
216
  declare function wait(callback: () => void, time?: number): Timer;
249
217
  //#endregion
250
- export { PromiseOptions, type RepeatOptions, type Timer, type When, delay, isRepeated, isTimer, isWaited, isWhen, repeat, wait, when };
218
+ //#region src/when.d.ts
219
+ /**
220
+ * Create a conditional timer
221
+ * @param condition Condition to check
222
+ * @param options Timer options
223
+ * @returns Timer instance
224
+ */
225
+ declare function when(condition: () => boolean, options?: Partial<WhenOptions>): When;
226
+ //#endregion
227
+ export { type RepeatOptions, type Timer, type TimerOptions, type When, type WhenOptions, delay, isRepeated, isTimer, isWaited, isWhen, repeat, wait, when };