-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
88 lines (72 loc) · 1.43 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import Emittery from 'emittery';
export type TimerDirection = 'down' | 'up';
export type TimerState = [running: boolean, date: number, offset: number];
export interface TimerOptions {
/**
* Indicates if the timer must increment or decrement time.
* @default 'up'
*/
direction?: TimerDirection;
/**
* The initial state value for resuming execution.
* @default [false, 0, 0]
*/
state?: TimerState;
/**
* Returns the current epoch.
*/
now?(): number;
}
interface EventData {
state: TimerState;
}
export class Timer extends Emittery<EventData> {
/**
* The current direction.
*/
readonly direction: TimerDirection;
/**
* The current state.
*/
readonly state: TimerState;
/**
* Returns the current epoch.
*/
now: () => number;
/**
* Indicates if the timer is running.
*/
get running(): boolean;
/**
* The current time.
*/
get time(): number;
/**
* Creates a new timer.
* @param options the timer options
*/
constructor(options?: TimerOptions);
/**
* Updates the current state.
* @param state the new state
*/
update(state: TimerState): void;
/**
* Starts the timer.
* @param resume indicates if it must resume from the last state change
*/
start(resume?: boolean): void;
/**
* Stops the timer.
*/
stop(): void;
/**
* Resets the timer.
*/
reset(): void;
/**
* Updates the current time.
* @param time the new time, in milliseconds
*/
seek(time: number): void;
}