waiit 0.0.1 → 2.0.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 +33 -83
- package/app.js +1 -1
- package/cli.js +2 -0
- package/index.d.ts +4 -6
- package/package.json +8 -37
package/README.md
CHANGED
|
@@ -3,24 +3,15 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/waiit)
|
|
4
4
|
[](https://github.com/Raju/waiit/blob/main/LICENSE)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Promise-based delay utility. Tiny, typed, zero dependencies.
|
|
7
7
|
|
|
8
|
-
## Features
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
- ⚡ **Simple API** - Easy to use with async/await
|
|
12
|
-
- 📦 **TypeScript Support** - Includes type definitions
|
|
13
|
-
- 🔧 **Flexible** - Pass any millisecond value or omit for immediate resolution
|
|
14
|
-
- 🌐 **Universal** - Works in Node.js and browsers
|
|
9
|
+
## Features
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
🪶 Lightweight (1 line) · ⚡ Simple async/await API · 📦 TypeScript ready · 🔧 Flexible · 🌐 Universal (Node.js & Browser) · 💻 CLI support
|
|
17
12
|
|
|
18
|
-
| Platform | Supported |
|
|
19
|
-
|----------|-----------|
|
|
20
|
-
| Node.js | ✅ |
|
|
21
|
-
| Browser | ✅ |
|
|
22
13
|
|
|
23
|
-
##
|
|
14
|
+
## Install
|
|
24
15
|
|
|
25
16
|
```bash
|
|
26
17
|
npm install waiit
|
|
@@ -28,108 +19,67 @@ npm install waiit
|
|
|
28
19
|
|
|
29
20
|
## API
|
|
30
21
|
|
|
31
|
-
```
|
|
22
|
+
```ts
|
|
32
23
|
wait(ms?: number): Promise<void>
|
|
33
24
|
```
|
|
34
25
|
|
|
35
26
|
| Parameter | Type | Default | Description |
|
|
36
27
|
|-----------|----------|---------|--------------------------------------|
|
|
37
|
-
| `ms` | `number` | `0` |
|
|
28
|
+
| `ms` | `number` | `0` | Delay in milliseconds |
|
|
38
29
|
|
|
39
30
|
**Returns:** A `Promise` that resolves after the specified time.
|
|
40
31
|
|
|
41
|
-
## Examples
|
|
42
|
-
|
|
43
|
-
```js
|
|
44
|
-
wait() // Returns a promise that resolves immediately
|
|
45
|
-
wait(1000) // Returns a promise that resolves after 1 second
|
|
46
|
-
wait(5000) // Returns a promise that resolves after 5 seconds
|
|
47
|
-
```
|
|
48
32
|
|
|
49
33
|
## Usage
|
|
50
34
|
|
|
51
|
-
### CommonJS
|
|
52
|
-
|
|
53
35
|
```js
|
|
36
|
+
// CommonJS
|
|
54
37
|
const wait = require('waiit');
|
|
55
38
|
|
|
56
|
-
|
|
57
|
-
console.log('Start');
|
|
58
|
-
|
|
59
|
-
await wait(5000);
|
|
60
|
-
console.log('Waited 5 seconds');
|
|
61
|
-
|
|
62
|
-
await wait();
|
|
63
|
-
console.log('Finish');
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
doSomething();
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### ES Modules
|
|
70
|
-
|
|
71
|
-
```js
|
|
39
|
+
// ES Modules
|
|
72
40
|
import wait from 'waiit';
|
|
73
41
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
await wait(2000);
|
|
77
|
-
console.log('Done after 2 seconds!');
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
example();
|
|
42
|
+
// Browser (CDN)
|
|
43
|
+
import wait from 'https://unpkg.com/waiit/app.js';
|
|
81
44
|
```
|
|
82
45
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
<script type="module">
|
|
87
|
-
// Using unpkg
|
|
88
|
-
import wait from 'https://unpkg.com/waiit/app.js';
|
|
89
|
-
|
|
90
|
-
await wait(1000);
|
|
91
|
-
console.log('Waited 1 second!');
|
|
92
|
-
</script>
|
|
46
|
+
```js
|
|
47
|
+
await wait(2000); // Wait 2 seconds
|
|
48
|
+
await wait(); // Resolve immediately
|
|
93
49
|
```
|
|
94
50
|
|
|
95
|
-
###
|
|
96
|
-
|
|
97
|
-
#### Retry with delay
|
|
98
|
-
|
|
51
|
+
### Retry with delay
|
|
99
52
|
```js
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
async function fetchWithRetry(url, retries = 3, delay = 1000) {
|
|
53
|
+
async function fetchWithRetry(url, retries = 3) {
|
|
103
54
|
for (let i = 0; i < retries; i++) {
|
|
104
55
|
try {
|
|
105
56
|
return await fetch(url);
|
|
106
|
-
} catch (
|
|
107
|
-
if (i < retries - 1)
|
|
108
|
-
await wait(delay);
|
|
109
|
-
}
|
|
57
|
+
} catch (e) {
|
|
58
|
+
if (i < retries - 1) await wait(1000);
|
|
110
59
|
}
|
|
111
60
|
}
|
|
112
|
-
throw new Error('
|
|
61
|
+
throw new Error('Failed');
|
|
113
62
|
}
|
|
114
63
|
```
|
|
115
64
|
|
|
116
|
-
|
|
117
|
-
|
|
65
|
+
### Sequential execution
|
|
118
66
|
```js
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
for (const step of steps) {
|
|
123
|
-
console.log(step.message);
|
|
124
|
-
await wait(step.delay);
|
|
125
|
-
}
|
|
67
|
+
for (const step of steps) {
|
|
68
|
+
console.log(step.message);
|
|
69
|
+
await wait(step.delay);
|
|
126
70
|
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## CLI
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Via npx
|
|
77
|
+
npx waiit 2000 # Wait 2 seconds
|
|
127
78
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
]);
|
|
79
|
+
# Or install globally
|
|
80
|
+
npm i -g waiit
|
|
81
|
+
waiit 3000 # Wait 3 seconds
|
|
82
|
+
waiit # Exit immediately
|
|
133
83
|
```
|
|
134
84
|
|
|
135
85
|
## License
|
package/app.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports=t=>new Promise(r=>setTimeout(r,t))
|
|
1
|
+
module.exports=t=>new Promise(r=>setTimeout(r,t))
|
package/cli.js
ADDED
package/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @param ms
|
|
4
|
-
* @returns
|
|
5
|
-
* @example
|
|
6
|
-
* await wait(2000); // Wait for 2 seconds
|
|
7
|
-
* await wait(); // Resolve immediately
|
|
2
|
+
* Promise-based delay utility. Tiny, typed, zero dependencies.
|
|
3
|
+
* @param ms Delay in ms (default: 0)
|
|
4
|
+
* @returns Promise that resolves after the specified delay
|
|
5
|
+
* @example wait(2000); // Wait for 2 seconds
|
|
8
6
|
*/
|
|
9
7
|
declare function wait(ms?: number): Promise<void>;
|
|
10
8
|
export = wait;
|
package/package.json
CHANGED
|
@@ -1,49 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "waiit",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Promise-based delay utility. Tiny, typed, zero dependencies.",
|
|
5
5
|
"main": "app.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
|
+
"bin": "cli.js",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
9
11
|
"require": "./app.js",
|
|
10
12
|
"import": "./app.js"
|
|
11
13
|
}
|
|
12
14
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
"test:cjs": "node test.js",
|
|
16
|
-
"test:esm": "node test.mjs"
|
|
17
|
-
},
|
|
18
|
-
"repository": {
|
|
19
|
-
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/Raju/waiit.git"
|
|
21
|
-
},
|
|
22
|
-
"keywords": [
|
|
23
|
-
"wait",
|
|
24
|
-
"delay",
|
|
25
|
-
"sleep",
|
|
26
|
-
"timeout",
|
|
27
|
-
"promise",
|
|
28
|
-
"async",
|
|
29
|
-
"await",
|
|
30
|
-
"setTimeout",
|
|
31
|
-
"timer",
|
|
32
|
-
"pause",
|
|
33
|
-
"browser",
|
|
34
|
-
"node"
|
|
35
|
-
],
|
|
15
|
+
"repository": "Raju/waiit",
|
|
16
|
+
"keywords": ["wait","delay","sleep","timeout","promise","async","await","setTimeout","timer","pause","browser","node","cli"],
|
|
36
17
|
"author": "Raju Dhami",
|
|
37
18
|
"license": "MIT",
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
"homepage": "https://github.com/Raju/waiit#readme",
|
|
42
|
-
"engines": {
|
|
43
|
-
"node": ">=10.0.0"
|
|
44
|
-
},
|
|
45
|
-
"files": [
|
|
46
|
-
"app.js",
|
|
47
|
-
"index.d.ts"
|
|
48
|
-
]
|
|
49
|
-
}
|
|
19
|
+
"files": ["app.js", "index.d.ts", "cli.js"]
|
|
20
|
+
}
|