eternal-timer 1.0.2 → 1.1.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 +106 -1
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -1,2 +1,107 @@
|
|
|
1
1
|
# eternal-timer
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
A simple and persistent timer library for Node.js. Timers are saved to a file and maintain their state even after process restart.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Create Timers**: Create timers for a specified duration
|
|
8
|
+
- **Remove Timers**: Delete timers by ID
|
|
9
|
+
- **Monitor Timers**: Handle expired timers with callback functions
|
|
10
|
+
- **List Timers**: Retrieve all active timers
|
|
11
|
+
- **Persistence**: Save timer data to a file that persists across process restarts
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install eternal-timer
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Basic Example
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { createTimer, checkTimers, removeTimer, showTimers } from 'eternal-timer';
|
|
25
|
+
|
|
26
|
+
// Create a timer (5 seconds)
|
|
27
|
+
const timerId = await createTimer(5000);
|
|
28
|
+
console.log('Timer created:', timerId);
|
|
29
|
+
|
|
30
|
+
// Monitor timers (executes when timer expires)
|
|
31
|
+
await checkTimers((timer) => {
|
|
32
|
+
console.log('Timer expired:', timer.id);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Display all timers
|
|
36
|
+
const timers = await showTimers();
|
|
37
|
+
console.log('Active timers:', timers);
|
|
38
|
+
|
|
39
|
+
// Remove a timer
|
|
40
|
+
await removeTimer(timerId);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## API
|
|
44
|
+
|
|
45
|
+
### `createTimer(length: number): Promise<string | null>`
|
|
46
|
+
|
|
47
|
+
Creates a new timer.
|
|
48
|
+
|
|
49
|
+
**Parameters:**
|
|
50
|
+
- `length` (number): Timer duration in milliseconds
|
|
51
|
+
|
|
52
|
+
**Returns:** Timer ID (UUID), or `null` on error
|
|
53
|
+
|
|
54
|
+
### `removeTimer(id: string): Promise<boolean>`
|
|
55
|
+
|
|
56
|
+
Removes a timer by ID.
|
|
57
|
+
|
|
58
|
+
**Parameters:**
|
|
59
|
+
- `id` (string): ID of the timer to remove
|
|
60
|
+
|
|
61
|
+
**Returns:** `true` on success, `false` on failure
|
|
62
|
+
|
|
63
|
+
### `checkTimers(callback: (timer: Timer) => void, interval?: number): Promise<void>`
|
|
64
|
+
|
|
65
|
+
Monitors expired timers and executes the callback function.
|
|
66
|
+
|
|
67
|
+
**Parameters:**
|
|
68
|
+
- `callback`: Function to execute when expired timers are found
|
|
69
|
+
- `interval` (number, optional): Check interval in milliseconds (default: 50ms)
|
|
70
|
+
|
|
71
|
+
### `showTimers(): Promise<Timer[]>`
|
|
72
|
+
|
|
73
|
+
Retrieves all active timers.
|
|
74
|
+
|
|
75
|
+
**Returns:** Array of `Timer` objects
|
|
76
|
+
|
|
77
|
+
## Type Definition
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
type Timer = {
|
|
81
|
+
id: string; // Unique timer identifier (UUID)
|
|
82
|
+
start: string; // Timer start timestamp
|
|
83
|
+
stop: string; // Timer end timestamp
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Scripts
|
|
88
|
+
|
|
89
|
+
- `npm run dev`: Run in development mode with nodemon
|
|
90
|
+
- `npm run build`: Compile TypeScript
|
|
91
|
+
- `npm start`: Run compiled JavaScript
|
|
92
|
+
|
|
93
|
+
## Storage
|
|
94
|
+
|
|
95
|
+
Timer data is stored in the `.timers` file in the project root. Each line follows this format:
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
{id} {start_timestamp} {stop_timestamp}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
ISC
|
|
104
|
+
|
|
105
|
+
## Repository
|
|
106
|
+
|
|
107
|
+
https://github.com/SUKEsann2000/eternal-timer
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eternal-timer",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "timer for node.js package",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -30,5 +30,9 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"uuid": "^13.0.0"
|
|
32
32
|
},
|
|
33
|
-
"files": [ "dist" ]
|
|
33
|
+
"files": [ "dist" ],
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"registry": "https://registry.npmjs.org/",
|
|
36
|
+
"access": "public"
|
|
37
|
+
}
|
|
34
38
|
}
|