@oscarpalmer/timer 0.25.0 → 0.27.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.
@@ -0,0 +1,135 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ declare abstract class BasicTimer<State> {
4
+ protected readonly $timer: string;
5
+ protected readonly state: State;
6
+ constructor(type: "repeat" | "wait" | "when", state: State);
7
+ /**
8
+ * Is the timer running?
9
+ */
10
+ abstract readonly active: boolean;
11
+ /**
12
+ * Is the timer destroyed?
13
+ */
14
+ abstract readonly destroyed: boolean;
15
+ /**
16
+ * Is the timer paused?
17
+ */
18
+ abstract readonly paused: boolean;
19
+ /**
20
+ * Gets the traced location of the timer
21
+ */
22
+ abstract readonly trace: string | undefined;
23
+ }
24
+ declare class Timer extends BasicTimer<TimerState> {
25
+ private readonly options;
26
+ get active(): boolean;
27
+ get destroyed(): boolean;
28
+ get paused(): boolean;
29
+ get trace(): string | undefined;
30
+ constructor(type: "repeat" | "wait", state: TimerState, options: TimerOptions);
31
+ /**
32
+ * Continues the timer _(if it was paused)_
33
+ */
34
+ continue(): Timer;
35
+ /**
36
+ * Destroys the timer _(after stopping it, if it was running)_
37
+ */
38
+ destroy(): void;
39
+ /**
40
+ * Pauses the timer _(if it was running)_
41
+ */
42
+ pause(): Timer;
43
+ /**
44
+ * Restarts the timer _(if it was running)_
45
+ */
46
+ restart(): Timer;
47
+ /**
48
+ * Starts the timer _(if it was stopped)_
49
+ */
50
+ start(): Timer;
51
+ /**
52
+ * Stops the timer _(if it was running)_
53
+ */
54
+ stop(): Timer;
55
+ }
56
+ /**
57
+ * Callback that runs after the timer has finished (or is stopped)
58
+ * - `finished` is `true` if the timer was allowed to finish, and `false` if it was stopped
59
+ */
60
+ export type AfterCallback = (finished: boolean) => void;
61
+ export type AnyCallback = (() => void) | IndexedCallback;
62
+ /**
63
+ * Callback that runs for each iteration of the timer
64
+ */
65
+ export type IndexedCallback = (index: number) => void;
66
+ export type BaseOptions = {
67
+ /**
68
+ * Interval between each callback
69
+ */
70
+ interval: number;
71
+ /**
72
+ * Maximum amount of time the timer may run for
73
+ */
74
+ timeout: number;
75
+ };
76
+ export type OptionsWithCount = {
77
+ /**
78
+ * How many times the timer should repeat
79
+ */
80
+ count: number;
81
+ } & BaseOptions;
82
+ export type OptionsWithError = {
83
+ /**
84
+ * Callback to run when an error occurs _(usually a timeout)_
85
+ */
86
+ errorCallback?: () => void;
87
+ };
88
+ export type RepeatOptions = {
89
+ /**
90
+ * Callback to run after the timer has finished (or is stopped)
91
+ * - `finished` is `true` if the timer was allowed to finish, and `false` if it was stopped
92
+ */
93
+ afterCallback?: AfterCallback;
94
+ } & OptionsWithCount & OptionsWithError;
95
+ export type TimerOptions = {} & RepeatOptions;
96
+ export type TimerState = {
97
+ active: boolean;
98
+ callback: AnyCallback;
99
+ destroyed: boolean;
100
+ count?: number;
101
+ elapsed?: number;
102
+ frame?: number;
103
+ index?: number;
104
+ isRepeated: boolean;
105
+ minimum: number;
106
+ paused: boolean;
107
+ trace?: string;
108
+ };
109
+ export type WorkType = "continue" | "pause" | "restart" | "start" | "stop";
110
+ /**
111
+ * A set of all active timers
112
+ */
113
+ export declare const activeTimers: Set<Timer>;
114
+ /**
115
+ * A set of types that allow work to begin
116
+ */
117
+ export declare const beginTypes: Set<WorkType>;
118
+ /**
119
+ * A set of types that allow work to end
120
+ */
121
+ export declare const endTypes: Set<WorkType>;
122
+ /**
123
+ * A set of types that allow work to end or restart
124
+ */
125
+ export declare const endOrRestartTypes: Set<WorkType>;
126
+ /**
127
+ * A set of timers that were paused due to the document being hidden
128
+ */
129
+ export declare const hiddenTimers: Set<Timer>;
130
+ /**
131
+ * Milliseconds in a frame, probably ;-)
132
+ */
133
+ export declare const milliseconds: number;
134
+
135
+ export {};
@@ -0,0 +1,114 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ declare abstract class BasicTimer<State> {
4
+ protected readonly $timer: string;
5
+ protected readonly state: State;
6
+ constructor(type: "repeat" | "wait" | "when", state: State);
7
+ /**
8
+ * Is the timer running?
9
+ */
10
+ abstract readonly active: boolean;
11
+ /**
12
+ * Is the timer destroyed?
13
+ */
14
+ abstract readonly destroyed: boolean;
15
+ /**
16
+ * Is the timer paused?
17
+ */
18
+ abstract readonly paused: boolean;
19
+ /**
20
+ * Gets the traced location of the timer
21
+ */
22
+ abstract readonly trace: string | undefined;
23
+ }
24
+ declare class Timer extends BasicTimer<TimerState> {
25
+ private readonly options;
26
+ get active(): boolean;
27
+ get destroyed(): boolean;
28
+ get paused(): boolean;
29
+ get trace(): string | undefined;
30
+ constructor(type: "repeat" | "wait", state: TimerState, options: TimerOptions);
31
+ /**
32
+ * Continues the timer _(if it was paused)_
33
+ */
34
+ continue(): Timer;
35
+ /**
36
+ * Destroys the timer _(after stopping it, if it was running)_
37
+ */
38
+ destroy(): void;
39
+ /**
40
+ * Pauses the timer _(if it was running)_
41
+ */
42
+ pause(): Timer;
43
+ /**
44
+ * Restarts the timer _(if it was running)_
45
+ */
46
+ restart(): Timer;
47
+ /**
48
+ * Starts the timer _(if it was stopped)_
49
+ */
50
+ start(): Timer;
51
+ /**
52
+ * Stops the timer _(if it was running)_
53
+ */
54
+ stop(): Timer;
55
+ }
56
+ /**
57
+ * Callback that runs after the timer has finished (or is stopped)
58
+ * - `finished` is `true` if the timer was allowed to finish, and `false` if it was stopped
59
+ */
60
+ export type AfterCallback = (finished: boolean) => void;
61
+ export type AnyCallback = (() => void) | IndexedCallback;
62
+ /**
63
+ * Callback that runs for each iteration of the timer
64
+ */
65
+ export type IndexedCallback = (index: number) => void;
66
+ export type BaseOptions = {
67
+ /**
68
+ * Interval between each callback
69
+ */
70
+ interval: number;
71
+ /**
72
+ * Maximum amount of time the timer may run for
73
+ */
74
+ timeout: number;
75
+ };
76
+ export type OptionsWithCount = {
77
+ /**
78
+ * How many times the timer should repeat
79
+ */
80
+ count: number;
81
+ } & BaseOptions;
82
+ export type OptionsWithError = {
83
+ /**
84
+ * Callback to run when an error occurs _(usually a timeout)_
85
+ */
86
+ errorCallback?: () => void;
87
+ };
88
+ export type RepeatOptions = {
89
+ /**
90
+ * Callback to run after the timer has finished (or is stopped)
91
+ * - `finished` is `true` if the timer was allowed to finish, and `false` if it was stopped
92
+ */
93
+ afterCallback?: AfterCallback;
94
+ } & OptionsWithCount & OptionsWithError;
95
+ export type TimerOptions = {} & RepeatOptions;
96
+ export type TimerState = {
97
+ active: boolean;
98
+ callback: AnyCallback;
99
+ destroyed: boolean;
100
+ count?: number;
101
+ elapsed?: number;
102
+ frame?: number;
103
+ index?: number;
104
+ isRepeated: boolean;
105
+ minimum: number;
106
+ paused: boolean;
107
+ trace?: string;
108
+ };
109
+ export type WorkType = "continue" | "pause" | "restart" | "start" | "stop";
110
+ export declare function getOptions(options: Partial<TimerOptions>, isRepeated: boolean): TimerOptions;
111
+ export declare function getValueOrDefault(value: unknown, defaultValue: number, minimum?: number): number;
112
+ export declare function work(type: WorkType, timer: Timer, state: TimerState, options: TimerOptions): Timer;
113
+
114
+ export {};
@@ -0,0 +1,3 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ export {};
package/types/index.d.cts CHANGED
@@ -1,70 +1,5 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
- /**
4
- * Callback that runs after the timer has finished (or is stopped)
5
- * - `finished` is `true` if the timer was allowed to finish, and `false` if it was stopped
6
- */
7
- export type AfterCallback = (finished: boolean) => void;
8
- export type AnyCallback = (() => void) | IndexedCallback;
9
- /**
10
- * Callback that runs for each iteration of the timer
11
- */
12
- export type IndexedCallback = (index: number) => void;
13
- export type BaseOptions = {
14
- /**
15
- * Interval between each callback
16
- */
17
- interval: number;
18
- /**
19
- * Maximum amount of time the timer may run for
20
- */
21
- timeout: number;
22
- };
23
- export type OptionsWithCount = {
24
- /**
25
- * How many times the timer should repeat
26
- */
27
- count: number;
28
- } & BaseOptions;
29
- export type OptionsWithError = {
30
- /**
31
- * Callback to run when an error occurs _(usually a timeout)_
32
- */
33
- errorCallback?: () => void;
34
- };
35
- export type RepeatOptions = {
36
- /**
37
- * Callback to run after the timer has finished (or is stopped)
38
- * - `finished` is `true` if the timer was allowed to finish, and `false` if it was stopped
39
- */
40
- afterCallback?: AfterCallback;
41
- } & OptionsWithCount & OptionsWithError;
42
- export type TimerOptions = {} & RepeatOptions;
43
- export type TimerState = {
44
- active: boolean;
45
- callback: AnyCallback;
46
- destroyed: boolean;
47
- count?: number;
48
- elapsed?: number;
49
- frame?: number;
50
- index?: number;
51
- isRepeated: boolean;
52
- minimum: number;
53
- paused: boolean;
54
- trace: TimerTrace;
55
- };
56
- declare class TimerTrace extends Error {
57
- constructor();
58
- }
59
- export type WaitOptions = {} & BaseOptions & OptionsWithError;
60
- export type WhenOptions = {} & OptionsWithCount;
61
- export type WhenState = {
62
- promise: Promise<void>;
63
- rejecter?: () => void;
64
- resolver?: () => void;
65
- started: boolean;
66
- timer: Timer$1;
67
- };
68
3
  declare abstract class BasicTimer<State> {
69
4
  protected readonly $timer: string;
70
5
  protected readonly state: State;
@@ -84,22 +19,22 @@ declare abstract class BasicTimer<State> {
84
19
  /**
85
20
  * Gets the traced location of the timer
86
21
  */
87
- abstract readonly trace: TimerTrace | undefined;
22
+ abstract readonly trace: string | undefined;
88
23
  }
89
24
  /**
90
25
  * A timer that can be started, stopped, and restarted as neeeded
91
26
  */
92
- declare class Timer$1 extends BasicTimer<TimerState> {
27
+ export declare class Timer extends BasicTimer<TimerState> {
93
28
  private readonly options;
94
29
  get active(): boolean;
95
30
  get destroyed(): boolean;
96
31
  get paused(): boolean;
97
- get trace(): TimerTrace | undefined;
32
+ get trace(): string | undefined;
98
33
  constructor(type: "repeat" | "wait", state: TimerState, options: TimerOptions);
99
34
  /**
100
35
  * Continues the timer _(if it was paused)_
101
36
  */
102
- continue(): Timer$1;
37
+ continue(): Timer;
103
38
  /**
104
39
  * Destroys the timer _(after stopping it, if it was running)_
105
40
  */
@@ -107,19 +42,19 @@ declare class Timer$1 extends BasicTimer<TimerState> {
107
42
  /**
108
43
  * Pauses the timer _(if it was running)_
109
44
  */
110
- pause(): Timer$1;
45
+ pause(): Timer;
111
46
  /**
112
47
  * Restarts the timer _(if it was running)_
113
48
  */
114
- restart(): Timer$1;
49
+ restart(): Timer;
115
50
  /**
116
51
  * Starts the timer _(if it was stopped)_
117
52
  */
118
- start(): Timer$1;
53
+ start(): Timer;
119
54
  /**
120
55
  * Stops the timer _(if it was running)_
121
56
  */
122
- stop(): Timer$1;
57
+ stop(): Timer;
123
58
  }
124
59
  /**
125
60
  * Creates a timer which:
@@ -130,26 +65,88 @@ declare class Timer$1 extends BasicTimer<TimerState> {
130
65
  * - `options.interval` defaults to `1000/60` _(1 frame)_
131
66
  * - `options.timeout` defaults to `Infinity`
132
67
  */
133
- export declare function repeat(callback: IndexedCallback, options?: Partial<RepeatOptions>): Timer$1;
68
+ export declare function repeat(callback: IndexedCallback, options?: Partial<RepeatOptions>): Timer;
134
69
  /**
135
70
  * Creates a timer which calls a callback after a certain amount of time
136
71
  */
137
- export declare function wait(callback: () => void): Timer$1;
72
+ export declare function wait(callback: () => void): Timer;
138
73
  /**
139
74
  * Creates a timer which calls a callback after a certain amount of time
140
75
  */
141
- export declare function wait(callback: () => void, time: number): Timer$1;
76
+ export declare function wait(callback: () => void, time: number): Timer;
142
77
  /**
143
78
  * Creates a timer which calls a callback after a certain amount of time
144
79
  * - `options.interval` defaults to `1000/60` _(1 frame)_
145
80
  * - `options.timeout` defaults to `30_000` _(30 seconds)_
146
81
  */
147
- export declare function wait(callback: () => void, options: Partial<WaitOptions>): Timer$1;
82
+ export declare function wait(callback: () => void, options: Partial<WaitOptions>): Timer;
83
+ /**
84
+ * Callback that runs after the timer has finished (or is stopped)
85
+ * - `finished` is `true` if the timer was allowed to finish, and `false` if it was stopped
86
+ */
87
+ export type AfterCallback = (finished: boolean) => void;
88
+ export type AnyCallback = (() => void) | IndexedCallback;
89
+ /**
90
+ * Callback that runs for each iteration of the timer
91
+ */
92
+ export type IndexedCallback = (index: number) => void;
93
+ export type BaseOptions = {
94
+ /**
95
+ * Interval between each callback
96
+ */
97
+ interval: number;
98
+ /**
99
+ * Maximum amount of time the timer may run for
100
+ */
101
+ timeout: number;
102
+ };
103
+ export type OptionsWithCount = {
104
+ /**
105
+ * How many times the timer should repeat
106
+ */
107
+ count: number;
108
+ } & BaseOptions;
109
+ export type OptionsWithError = {
110
+ /**
111
+ * Callback to run when an error occurs _(usually a timeout)_
112
+ */
113
+ errorCallback?: () => void;
114
+ };
115
+ export type RepeatOptions = {
116
+ /**
117
+ * Callback to run after the timer has finished (or is stopped)
118
+ * - `finished` is `true` if the timer was allowed to finish, and `false` if it was stopped
119
+ */
120
+ afterCallback?: AfterCallback;
121
+ } & OptionsWithCount & OptionsWithError;
122
+ export type TimerOptions = {} & RepeatOptions;
123
+ export type TimerState = {
124
+ active: boolean;
125
+ callback: AnyCallback;
126
+ destroyed: boolean;
127
+ count?: number;
128
+ elapsed?: number;
129
+ frame?: number;
130
+ index?: number;
131
+ isRepeated: boolean;
132
+ minimum: number;
133
+ paused: boolean;
134
+ trace?: string;
135
+ };
136
+ export type WaitOptions = {} & BaseOptions & OptionsWithError;
137
+ export type WhenOptions = {} & OptionsWithCount;
138
+ export type WhenState = {
139
+ promise: Promise<void>;
140
+ rejecter?: () => void;
141
+ resolver?: () => void;
142
+ started: boolean;
143
+ timer: Timer;
144
+ };
148
145
  export declare class When extends BasicTimer<WhenState> {
149
146
  get active(): boolean;
150
147
  get destroyed(): boolean;
151
148
  get paused(): boolean;
152
- get trace(): TimerTrace | undefined;
149
+ get trace(): string | undefined;
153
150
  constructor(state: WhenState);
154
151
  /**
155
152
  * Continues the timer _(if it was paused)_
@@ -180,15 +177,15 @@ export declare function when(condition: () => boolean, options?: Partial<WhenOpt
180
177
  /**
181
178
  * Is the value a repeating timer?
182
179
  */
183
- export declare function isRepeated(value: unknown): value is Timer$1;
180
+ export declare function isRepeated(value: unknown): value is Timer;
184
181
  /**
185
182
  * Is the value a timer?
186
183
  */
187
- export declare function isTimer(value: unknown): value is Timer$1;
184
+ export declare function isTimer(value: unknown): value is Timer;
188
185
  /**
189
186
  * Is the value a waiting timer?
190
187
  */
191
- export declare function isWaited(value: unknown): value is Timer$1;
188
+ export declare function isWaited(value: unknown): value is Timer;
192
189
  /**
193
190
  * Is the value a conditional timer?
194
191
  */
@@ -198,8 +195,4 @@ export declare function isWhen(value: unknown): value is When;
198
195
  */
199
196
  export declare function delay(time: number, timeout?: number): Promise<void>;
200
197
 
201
- export {
202
- Timer$1 as Timer,
203
- };
204
-
205
198
  export {};
package/types/is.d.cts ADDED
@@ -0,0 +1,160 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ declare abstract class BasicTimer<State> {
4
+ protected readonly $timer: string;
5
+ protected readonly state: State;
6
+ constructor(type: "repeat" | "wait" | "when", state: State);
7
+ /**
8
+ * Is the timer running?
9
+ */
10
+ abstract readonly active: boolean;
11
+ /**
12
+ * Is the timer destroyed?
13
+ */
14
+ abstract readonly destroyed: boolean;
15
+ /**
16
+ * Is the timer paused?
17
+ */
18
+ abstract readonly paused: boolean;
19
+ /**
20
+ * Gets the traced location of the timer
21
+ */
22
+ abstract readonly trace: string | undefined;
23
+ }
24
+ declare class Timer extends BasicTimer<TimerState> {
25
+ private readonly options;
26
+ get active(): boolean;
27
+ get destroyed(): boolean;
28
+ get paused(): boolean;
29
+ get trace(): string | undefined;
30
+ constructor(type: "repeat" | "wait", state: TimerState, options: TimerOptions);
31
+ /**
32
+ * Continues the timer _(if it was paused)_
33
+ */
34
+ continue(): Timer;
35
+ /**
36
+ * Destroys the timer _(after stopping it, if it was running)_
37
+ */
38
+ destroy(): void;
39
+ /**
40
+ * Pauses the timer _(if it was running)_
41
+ */
42
+ pause(): Timer;
43
+ /**
44
+ * Restarts the timer _(if it was running)_
45
+ */
46
+ restart(): Timer;
47
+ /**
48
+ * Starts the timer _(if it was stopped)_
49
+ */
50
+ start(): Timer;
51
+ /**
52
+ * Stops the timer _(if it was running)_
53
+ */
54
+ stop(): Timer;
55
+ }
56
+ /**
57
+ * Callback that runs after the timer has finished (or is stopped)
58
+ * - `finished` is `true` if the timer was allowed to finish, and `false` if it was stopped
59
+ */
60
+ export type AfterCallback = (finished: boolean) => void;
61
+ export type AnyCallback = (() => void) | IndexedCallback;
62
+ /**
63
+ * Callback that runs for each iteration of the timer
64
+ */
65
+ export type IndexedCallback = (index: number) => void;
66
+ export type BaseOptions = {
67
+ /**
68
+ * Interval between each callback
69
+ */
70
+ interval: number;
71
+ /**
72
+ * Maximum amount of time the timer may run for
73
+ */
74
+ timeout: number;
75
+ };
76
+ export type OptionsWithCount = {
77
+ /**
78
+ * How many times the timer should repeat
79
+ */
80
+ count: number;
81
+ } & BaseOptions;
82
+ export type OptionsWithError = {
83
+ /**
84
+ * Callback to run when an error occurs _(usually a timeout)_
85
+ */
86
+ errorCallback?: () => void;
87
+ };
88
+ export type RepeatOptions = {
89
+ /**
90
+ * Callback to run after the timer has finished (or is stopped)
91
+ * - `finished` is `true` if the timer was allowed to finish, and `false` if it was stopped
92
+ */
93
+ afterCallback?: AfterCallback;
94
+ } & OptionsWithCount & OptionsWithError;
95
+ export type TimerOptions = {} & RepeatOptions;
96
+ export type TimerState = {
97
+ active: boolean;
98
+ callback: AnyCallback;
99
+ destroyed: boolean;
100
+ count?: number;
101
+ elapsed?: number;
102
+ frame?: number;
103
+ index?: number;
104
+ isRepeated: boolean;
105
+ minimum: number;
106
+ paused: boolean;
107
+ trace?: string;
108
+ };
109
+ export type WhenState = {
110
+ promise: Promise<void>;
111
+ rejecter?: () => void;
112
+ resolver?: () => void;
113
+ started: boolean;
114
+ timer: Timer;
115
+ };
116
+ declare class When extends BasicTimer<WhenState> {
117
+ get active(): boolean;
118
+ get destroyed(): boolean;
119
+ get paused(): boolean;
120
+ get trace(): string | undefined;
121
+ constructor(state: WhenState);
122
+ /**
123
+ * Continues the timer _(if it was paused)_
124
+ */
125
+ continue(): When;
126
+ /**
127
+ * Destroys the timer _(and stops it,if it was running)_
128
+ */
129
+ destroy(): void;
130
+ /**
131
+ * Pauses the timer _(if it was running)_
132
+ */
133
+ pause(): When;
134
+ /**
135
+ * Stops the timer _(if it was running)_
136
+ */
137
+ stop(): When;
138
+ /**
139
+ * Starts the timer and returns a promise that resolves when the condition is met
140
+ */
141
+ then(resolve?: (() => void) | null, reject?: (() => void) | null): Promise<void>;
142
+ }
143
+ /**
144
+ * Is the value a repeating timer?
145
+ */
146
+ export declare function isRepeated(value: unknown): value is Timer;
147
+ /**
148
+ * Is the value a timer?
149
+ */
150
+ export declare function isTimer(value: unknown): value is Timer;
151
+ /**
152
+ * Is the value a waiting timer?
153
+ */
154
+ export declare function isWaited(value: unknown): value is Timer;
155
+ /**
156
+ * Is the value a conditional timer?
157
+ */
158
+ export declare function isWhen(value: unknown): value is When;
159
+
160
+ export {};