@oscarpalmer/timer 0.24.0 → 0.26.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/dist/constants.cjs +18 -0
- package/dist/constants.js +11 -12
- package/dist/{functions.mjs → functions.cjs} +35 -34
- package/dist/functions.js +25 -29
- package/dist/global.cjs +9 -0
- package/dist/global.js +1 -13
- package/dist/index.cjs +47 -0
- package/dist/index.js +30 -324
- package/dist/{is.mjs → is.cjs} +7 -8
- package/dist/is.js +4 -5
- package/dist/models.cjs +9 -0
- package/dist/{models.mjs → models.js} +0 -1
- package/dist/timer.cjs +111 -0
- package/dist/timer.js +64 -145
- package/dist/when.cjs +122 -0
- package/dist/when.js +86 -234
- package/package.json +19 -20
- package/src/constants.ts +2 -2
- package/src/functions.ts +3 -3
- package/src/global.ts +2 -1
- package/src/index.ts +4 -3
- package/src/is.ts +2 -2
- package/src/models.ts +1 -1
- package/src/timer.ts +3 -3
- package/src/when.ts +2 -2
- package/types/constants.d.cts +138 -0
- package/types/constants.d.ts +2 -2
- package/types/functions.d.cts +117 -0
- package/types/functions.d.ts +2 -2
- package/types/global.d.cts +3 -0
- package/types/global.d.ts +1 -1
- package/types/index.d.cts +78 -82
- package/types/index.d.ts +1 -1
- package/types/is.d.cts +163 -0
- package/types/is.d.ts +2 -2
- package/types/models.d.cts +123 -0
- package/types/models.d.ts +1 -1
- package/types/timer.d.cts +142 -0
- package/types/timer.d.ts +1 -1
- package/types/when.d.cts +153 -0
- package/types/when.d.ts +3 -3
- package/dist/constants.mjs +0 -19
- package/dist/global.mjs +0 -9
- package/dist/index.mjs +0 -46
- package/dist/timer.mjs +0 -89
- package/dist/when.mjs +0 -91
|
@@ -0,0 +1,117 @@
|
|
|
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: TimerTrace | 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(): TimerTrace | 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: TimerTrace;
|
|
108
|
+
};
|
|
109
|
+
declare class TimerTrace extends Error {
|
|
110
|
+
constructor();
|
|
111
|
+
}
|
|
112
|
+
export type WorkType = "continue" | "pause" | "restart" | "start" | "stop";
|
|
113
|
+
export declare function getOptions(options: Partial<TimerOptions>, isRepeated: boolean): TimerOptions;
|
|
114
|
+
export declare function getValueOrDefault(value: unknown, defaultValue: number, minimum?: number): number;
|
|
115
|
+
export declare function work(type: WorkType, timer: Timer, state: TimerState, options: TimerOptions): Timer;
|
|
116
|
+
|
|
117
|
+
export {};
|
package/types/functions.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TimerOptions, TimerState, WorkType } from '
|
|
2
|
-
import type { Timer } from '
|
|
1
|
+
import type { TimerOptions, TimerState, WorkType } from '~/models';
|
|
2
|
+
import type { Timer } from '~/timer';
|
|
3
3
|
export declare function getOptions(options: Partial<TimerOptions>, isRepeated: boolean): TimerOptions;
|
|
4
4
|
export declare function getValueOrDefault(value: unknown, defaultValue: number, minimum?: number): number;
|
|
5
5
|
export declare function work(type: WorkType, timer: Timer, state: TimerState, options: TimerOptions): Timer;
|
package/types/global.d.ts
CHANGED
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;
|
|
@@ -89,7 +24,7 @@ declare abstract class BasicTimer<State> {
|
|
|
89
24
|
/**
|
|
90
25
|
* A timer that can be started, stopped, and restarted as neeeded
|
|
91
26
|
*/
|
|
92
|
-
declare class Timer
|
|
27
|
+
export declare class Timer extends BasicTimer<TimerState> {
|
|
93
28
|
private readonly options;
|
|
94
29
|
get active(): boolean;
|
|
95
30
|
get destroyed(): boolean;
|
|
@@ -99,7 +34,7 @@ declare class Timer$1 extends BasicTimer<TimerState> {
|
|
|
99
34
|
/**
|
|
100
35
|
* Continues the timer _(if it was paused)_
|
|
101
36
|
*/
|
|
102
|
-
continue(): Timer
|
|
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
|
|
45
|
+
pause(): Timer;
|
|
111
46
|
/**
|
|
112
47
|
* Restarts the timer _(if it was running)_
|
|
113
48
|
*/
|
|
114
|
-
restart(): Timer
|
|
49
|
+
restart(): Timer;
|
|
115
50
|
/**
|
|
116
51
|
* Starts the timer _(if it was stopped)_
|
|
117
52
|
*/
|
|
118
|
-
start(): Timer
|
|
53
|
+
start(): Timer;
|
|
119
54
|
/**
|
|
120
55
|
* Stops the timer _(if it was running)_
|
|
121
56
|
*/
|
|
122
|
-
stop(): Timer
|
|
57
|
+
stop(): Timer;
|
|
123
58
|
}
|
|
124
59
|
/**
|
|
125
60
|
* Creates a timer which:
|
|
@@ -130,21 +65,86 @@ 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
|
|
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
|
|
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
|
|
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
|
|
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: TimerTrace;
|
|
135
|
+
};
|
|
136
|
+
declare class TimerTrace extends Error {
|
|
137
|
+
constructor();
|
|
138
|
+
}
|
|
139
|
+
export type WaitOptions = {} & BaseOptions & OptionsWithError;
|
|
140
|
+
export type WhenOptions = {} & OptionsWithCount;
|
|
141
|
+
export type WhenState = {
|
|
142
|
+
promise: Promise<void>;
|
|
143
|
+
rejecter?: () => void;
|
|
144
|
+
resolver?: () => void;
|
|
145
|
+
started: boolean;
|
|
146
|
+
timer: Timer;
|
|
147
|
+
};
|
|
148
148
|
export declare class When extends BasicTimer<WhenState> {
|
|
149
149
|
get active(): boolean;
|
|
150
150
|
get destroyed(): boolean;
|
|
@@ -180,15 +180,15 @@ export declare function when(condition: () => boolean, options?: Partial<WhenOpt
|
|
|
180
180
|
/**
|
|
181
181
|
* Is the value a repeating timer?
|
|
182
182
|
*/
|
|
183
|
-
export declare function isRepeated(value: unknown): value is Timer
|
|
183
|
+
export declare function isRepeated(value: unknown): value is Timer;
|
|
184
184
|
/**
|
|
185
185
|
* Is the value a timer?
|
|
186
186
|
*/
|
|
187
|
-
export declare function isTimer(value: unknown): value is Timer
|
|
187
|
+
export declare function isTimer(value: unknown): value is Timer;
|
|
188
188
|
/**
|
|
189
189
|
* Is the value a waiting timer?
|
|
190
190
|
*/
|
|
191
|
-
export declare function isWaited(value: unknown): value is Timer
|
|
191
|
+
export declare function isWaited(value: unknown): value is Timer;
|
|
192
192
|
/**
|
|
193
193
|
* Is the value a conditional timer?
|
|
194
194
|
*/
|
|
@@ -198,8 +198,4 @@ export declare function isWhen(value: unknown): value is When;
|
|
|
198
198
|
*/
|
|
199
199
|
export declare function delay(time: number, timeout?: number): Promise<void>;
|
|
200
200
|
|
|
201
|
-
export {
|
|
202
|
-
Timer$1 as Timer,
|
|
203
|
-
};
|
|
204
|
-
|
|
205
201
|
export {};
|
package/types/index.d.ts
CHANGED
package/types/is.d.cts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
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: TimerTrace | 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(): TimerTrace | 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: TimerTrace;
|
|
108
|
+
};
|
|
109
|
+
declare class TimerTrace extends Error {
|
|
110
|
+
constructor();
|
|
111
|
+
}
|
|
112
|
+
export type WhenState = {
|
|
113
|
+
promise: Promise<void>;
|
|
114
|
+
rejecter?: () => void;
|
|
115
|
+
resolver?: () => void;
|
|
116
|
+
started: boolean;
|
|
117
|
+
timer: Timer;
|
|
118
|
+
};
|
|
119
|
+
declare class When extends BasicTimer<WhenState> {
|
|
120
|
+
get active(): boolean;
|
|
121
|
+
get destroyed(): boolean;
|
|
122
|
+
get paused(): boolean;
|
|
123
|
+
get trace(): TimerTrace | undefined;
|
|
124
|
+
constructor(state: WhenState);
|
|
125
|
+
/**
|
|
126
|
+
* Continues the timer _(if it was paused)_
|
|
127
|
+
*/
|
|
128
|
+
continue(): When;
|
|
129
|
+
/**
|
|
130
|
+
* Destroys the timer _(and stops it,if it was running)_
|
|
131
|
+
*/
|
|
132
|
+
destroy(): void;
|
|
133
|
+
/**
|
|
134
|
+
* Pauses the timer _(if it was running)_
|
|
135
|
+
*/
|
|
136
|
+
pause(): When;
|
|
137
|
+
/**
|
|
138
|
+
* Stops the timer _(if it was running)_
|
|
139
|
+
*/
|
|
140
|
+
stop(): When;
|
|
141
|
+
/**
|
|
142
|
+
* Starts the timer and returns a promise that resolves when the condition is met
|
|
143
|
+
*/
|
|
144
|
+
then(resolve?: (() => void) | null, reject?: (() => void) | null): Promise<void>;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Is the value a repeating timer?
|
|
148
|
+
*/
|
|
149
|
+
export declare function isRepeated(value: unknown): value is Timer;
|
|
150
|
+
/**
|
|
151
|
+
* Is the value a timer?
|
|
152
|
+
*/
|
|
153
|
+
export declare function isTimer(value: unknown): value is Timer;
|
|
154
|
+
/**
|
|
155
|
+
* Is the value a waiting timer?
|
|
156
|
+
*/
|
|
157
|
+
export declare function isWaited(value: unknown): value is Timer;
|
|
158
|
+
/**
|
|
159
|
+
* Is the value a conditional timer?
|
|
160
|
+
*/
|
|
161
|
+
export declare function isWhen(value: unknown): value is When;
|
|
162
|
+
|
|
163
|
+
export {};
|
package/types/is.d.ts
CHANGED
|
@@ -0,0 +1,123 @@
|
|
|
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: TimerTrace | 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(): TimerTrace | 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: TimerTrace;
|
|
108
|
+
};
|
|
109
|
+
export declare class TimerTrace extends Error {
|
|
110
|
+
constructor();
|
|
111
|
+
}
|
|
112
|
+
export type WaitOptions = {} & BaseOptions & OptionsWithError;
|
|
113
|
+
export type WhenOptions = {} & OptionsWithCount;
|
|
114
|
+
export type WhenState = {
|
|
115
|
+
promise: Promise<void>;
|
|
116
|
+
rejecter?: () => void;
|
|
117
|
+
resolver?: () => void;
|
|
118
|
+
started: boolean;
|
|
119
|
+
timer: Timer;
|
|
120
|
+
};
|
|
121
|
+
export type WorkType = "continue" | "pause" | "restart" | "start" | "stop";
|
|
122
|
+
|
|
123
|
+
export {};
|
package/types/models.d.ts
CHANGED