66 - simple delay
77 - Bronstein
88 - Fischer
9- - game config store comes with most common game types
9+ - clock config store comes with most common game types
1010- supports mid-game player penalty/bonus
1111- TDD -> good test coverage
1212- full Typescript support
1313- vanilla JavaScript
1414- 0 dependencies
1515- ** esm** and ** commonjs** imports supported
16+ - small footprint, less than 2 kb uglified and gzipped
1617
1718## Installation
1819
@@ -33,94 +34,94 @@ npm install chess-clock
3334### ESM
3435
3536``` ts
36- import { Timer } from ' chess-clock'
37+ import { Clock } from ' chess-clock'
3738```
3839
3940### CommonJS
4041
4142``` ts
42- const { Timer } = require (' chess-clock/cjs' )
43+ const { Clock } = require (' chess-clock/cjs' )
4344```
4445
4546## Basic example
4647
4748``` ts
48- import { Timer } from ' chess-clock'
49+ import { Clock } from ' chess-clock'
4950
50- const fischer = Timer .getConfig (' Fischer Rapid 5|5' )!
51+ const fischer = Clock .getConfig (' Fischer Rapid 5|5' )!
5152const updateInterval = 1000
5253const callback = console .info
5354
54- const timer = new Timer ({
55+ const clock = new Clock ({
5556 ... fischer ,
5657 updateInterval ,
5758 callback ,
5859})
5960
60- timer .push (0 )
61- setTimeout (() => timer .push (1 ), 2100 )
62- setTimeout (() => timer .push (0 ), 4200 )
63- setTimeout (() => timer .push (1 ), 8400 )
61+ clock .push (0 )
62+ setTimeout (() => clock .push (1 ), 2100 )
63+ setTimeout (() => clock .push (0 ), 4200 )
64+ setTimeout (() => clock .push (1 ), 8400 )
6465```
6566
66- ## Instantiating Timer
67+ ## Instantiating Clock
6768
6869``` ts
69- const timer = new Timer ({
70- // game config (can be retrieved from the Config store or inlined)
71- name: string
72- stages : Stage []
70+ const clock = new Clock ({
71+ // clock config (can be retrieved from the Config store or inlined)
72+ name? : string
73+ stages ? : Stage []
7374 // optional: default is 100ms
7475 updateInterval ?: number
75- // optional: called with game state on each "button" push and on each interval update
76- callback ?: (state : State ) => void
76+ // optional: called with clock state on each "button" push and on each interval update
77+ callback ? (state : State ): void
7778})
7879` ` `
7980
8081## Instance methods
8182
82- ### Get game 's state
83+ ### Get clock 's state
8384
8485` ` ` ts
85- timer .state
86+ clock .state
8687` ` `
8788
8889### Add time to a player
8990
9091` ` ` ts
91- timer .addTime (player : 0 | 1 , time : number )
92+ clock .addTime (player : 0 | 1 , time : number )
9293` ` `
9394
9495### End player's turn
9596
9697` ` ` ts
97- timer .push (player : 0 | 1 )
98+ clock .push (player : 0 | 1 )
9899` ` `
99100
100- ### Pause game
101+ ### Pause clock
101102
102103` ` ` ts
103- timer .pause ()
104+ clock .pause ()
104105` ` `
105106
106- ### Resume game
107+ ### Resume clock
107108
108109` ` ` ts
109- timer .resume ()
110+ clock .resume ()
110111` ` `
111112
112- ### Reset game with old or new game config
113+ ### Reset clock with old or new config
113114
114115` ` ` ts
115- reset ()
116- reset ({ name: string ; stages : Stage [] })
116+ clock . reset ()
117+ clock . reset ({ name: string ; stages: Stage [] })
117118` ` `
118119
119120## Static methods
120121
121- ### Game configurations
122+ ### Clock configurations
122123
123- Game config store holds arrays of Stage objects.
124+ Clock config store holds arrays of Stage objects.
124125
125126` ` ` ts
126127Stage {
@@ -138,31 +139,31 @@ Stage {
138139### Add/replace a config in configs store
139140
140141` ` ` ts
141- Timer .setConfig (name : string , stages : Stage [])
142+ Clock .setConfig (name : string , stages : Stage [])
142143` ` `
143144
144145### Delete a config by name in configs store
145146
146147` ` ` ts
147- Timer .deleteConfig (name : string )
148+ Clock .deleteConfig (name : string )
148149` ` `
149150
150151### Get a config by name from configs store
151152
152153` ` ` ts
153- Timer .setConfig (name : string )
154+ Clock .setConfig (name : string )
154155` ` `
155156
156157### List config names from configs store.
157158
158159` ` ` ts
159- Timer .listConfigNames ()
160+ Clock .listConfigNames ()
160161` ` `
161162
162163### List config entries from configs store
163164
164165` ` ` ts
165- Timer .listConfigEntries ()
166+ Clock .listConfigEntries ()
166167` ` `
167168
168169## Timing methods ([wikipedia](https://en.wikipedia.org/wiki/Time_control#Chess))
0 commit comments