@oscarpalmer/timer 0.6.0 → 0.7.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 +40 -2
- package/dist/timer.js +1 -2
- package/package.json +11 -11
- package/src/index.ts +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,45 @@
|
|
|
1
1
|
# Timer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://badge.fury.io/js/@oscarpalmer%2Ftimer)
|
|
4
|
+
|
|
5
|
+
A better solution for timeout- and interval-based timers.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Timer is available on _npm_ as [`@oscarpalmer/timer`](https://www.npmjs.com/package/@oscarpalmer/timer).
|
|
10
|
+
|
|
11
|
+
## Getting started
|
|
12
|
+
|
|
13
|
+
This is fairily lightweight package, so hopefully you'll be up and running in seconds :blush:
|
|
14
|
+
|
|
15
|
+
### Examples
|
|
16
|
+
|
|
17
|
+
The timers can be called with nice helper methods, which also auto-start the timers:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import {repeat, wait} from '@oscarpalmer/timer';
|
|
21
|
+
|
|
22
|
+
let waited = wait(callback, time);
|
|
23
|
+
let repeated = repeat(callback, time, count);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or they can be created using class syntax, but without being auto-started:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import {Repeated, Waited} from '@oscarpalmer/timer';
|
|
30
|
+
|
|
31
|
+
waited = new Waited(callback, time);
|
|
32
|
+
repeated = new Repeated(callback, time, count);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Both the nice helper methods and the class syntax create similar objects – `Waited` and `Repeated` – which share methods:
|
|
36
|
+
|
|
37
|
+
|Method|Description|
|
|
38
|
+
|-----:|:----------|
|
|
39
|
+
|`start()`|Starts the timer: necessary when creating a timer using the class syntax _(e.g. `new Waited...`)_, but helpful when the timer needs to be started at other times, as well|
|
|
40
|
+
|`stop()`|Stops the timer|
|
|
41
|
+
|`restart()`|Restarts the timer|
|
|
4
42
|
|
|
5
43
|
## License
|
|
6
44
|
|
|
7
|
-
[MIT licensed](LICENSE), natch :
|
|
45
|
+
[MIT licensed](LICENSE), natch :wink:
|
package/dist/timer.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
3
|
var __publicField = (obj, key, value) => {
|
|
@@ -7,7 +6,7 @@ var __publicField = (obj, key, value) => {
|
|
|
7
6
|
};
|
|
8
7
|
|
|
9
8
|
// src/index.ts
|
|
10
|
-
var milliseconds = 1e3 / 60;
|
|
9
|
+
var milliseconds = Math.round(1e3 / 60);
|
|
11
10
|
var Timed = class {
|
|
12
11
|
constructor(type, callback, time, count) {
|
|
13
12
|
__publicField(this, "callback");
|
package/package.json
CHANGED
|
@@ -3,17 +3,17 @@
|
|
|
3
3
|
"name": "Oscar Palmér",
|
|
4
4
|
"url": "https://oscarpalmer.se"
|
|
5
5
|
},
|
|
6
|
-
"description": "A better
|
|
6
|
+
"description": "A better solution for timeout- and interval-based timers.",
|
|
7
7
|
"devDependencies": {
|
|
8
8
|
"@tsconfig/recommended": "^1.0.0",
|
|
9
|
-
"@types/node": "^18.
|
|
10
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
11
|
-
"@typescript-eslint/parser": "^5.
|
|
12
|
-
"esbuild": "^0.
|
|
13
|
-
"eslint": "^8.
|
|
14
|
-
"eslint-config-xo": "^0.
|
|
15
|
-
"eslint-config-xo-typescript": "^0.
|
|
16
|
-
"typescript": "^4.
|
|
9
|
+
"@types/node": "^18.7.0",
|
|
10
|
+
"@typescript-eslint/eslint-plugin": "^5.35.0",
|
|
11
|
+
"@typescript-eslint/parser": "^5.35.0",
|
|
12
|
+
"esbuild": "^0.15.0",
|
|
13
|
+
"eslint": "^8.22.0",
|
|
14
|
+
"eslint-config-xo": "^0.42.0",
|
|
15
|
+
"eslint-config-xo-typescript": "^0.53.0",
|
|
16
|
+
"typescript": "^4.8.0"
|
|
17
17
|
},
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"type": "module",
|
|
44
44
|
"types": "src/index.d.ts",
|
|
45
45
|
"unpkg": "dist/timer.js",
|
|
46
|
-
"version": "0.
|
|
47
|
-
}
|
|
46
|
+
"version": "0.7.0"
|
|
47
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ type RepeatedCallback = (index: number) => void;
|
|
|
2
2
|
type TimerType = 'repeated' | 'waited';
|
|
3
3
|
type WaitedCallback = () => void;
|
|
4
4
|
|
|
5
|
-
const milliseconds = 1000 / 60;
|
|
5
|
+
const milliseconds = Math.round(1000 / 60);
|
|
6
6
|
|
|
7
7
|
abstract class Timed<Callback> {
|
|
8
8
|
private readonly callback: Callback;
|