waiit 2.0.1 → 3.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 +55 -33
- package/app.cjs +1 -0
- package/app.global.js +1 -0
- package/app.js +1 -1
- package/package.json +41 -10
- /package/{cli.js → app.cli.js} +0 -0
- /package/{index.d.ts → app.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -8,13 +8,26 @@ Promise-based delay utility. Tiny, typed, zero dependencies.
|
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
|
-
🪶 Lightweight
|
|
11
|
+
🪶 Lightweight · ⚡ Simple async/await API · 📦 TypeScript ready · 🌐 Universal (Node.js & Browser) · 💻 CLI support
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
## Install
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
+
# npm
|
|
17
18
|
npm install waiit
|
|
19
|
+
|
|
20
|
+
# yarn
|
|
21
|
+
yarn add waiit
|
|
22
|
+
|
|
23
|
+
# pnpm
|
|
24
|
+
pnpm add waiit
|
|
25
|
+
|
|
26
|
+
# bun
|
|
27
|
+
bun add waiit
|
|
28
|
+
|
|
29
|
+
# deno
|
|
30
|
+
deno add npm:waiit
|
|
18
31
|
```
|
|
19
32
|
|
|
20
33
|
## API
|
|
@@ -23,37 +36,60 @@ npm install waiit
|
|
|
23
36
|
wait(ms?: number): Promise<void>
|
|
24
37
|
```
|
|
25
38
|
|
|
26
|
-
| Parameter | Type | Default | Description
|
|
27
|
-
|
|
28
|
-
| `ms` | `number` | `0` | Delay in milliseconds
|
|
39
|
+
| Parameter | Type | Default | Description |
|
|
40
|
+
|-----------|----------|---------|----------------------|
|
|
41
|
+
| `ms` | `number` | `0` | Delay in milliseconds |
|
|
29
42
|
|
|
30
43
|
**Returns:** A `Promise` that resolves after the specified time.
|
|
31
44
|
|
|
32
45
|
|
|
33
46
|
## Usage
|
|
34
47
|
|
|
35
|
-
###
|
|
48
|
+
### ES Modules
|
|
36
49
|
|
|
37
50
|
```js
|
|
38
|
-
// CommonJS
|
|
39
|
-
const wait = require('waiit');
|
|
40
|
-
|
|
41
|
-
// ES Modules
|
|
42
51
|
import wait from 'waiit';
|
|
43
52
|
|
|
44
|
-
// Browser (CDN)
|
|
45
|
-
import wait from 'https://unpkg.com/waiit/app.js';
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
**Basic examples:**
|
|
49
|
-
```js
|
|
50
53
|
await wait(2000); // Pause for 2 seconds
|
|
51
54
|
await wait(500); // Pause for 500ms
|
|
52
55
|
await wait(); // Continue immediately (0ms)
|
|
53
56
|
```
|
|
54
57
|
|
|
58
|
+
### CommonJS
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
const wait = require('waiit');
|
|
62
|
+
|
|
63
|
+
await wait(2000);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Browser (CDN)
|
|
67
|
+
|
|
68
|
+
**ES Modules:**
|
|
69
|
+
```html
|
|
70
|
+
<script type="module">
|
|
71
|
+
import wait from 'https://unpkg.com/waiit/app.js';
|
|
72
|
+
|
|
73
|
+
await wait(1000);
|
|
74
|
+
console.log('Done!');
|
|
75
|
+
</script>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Classic Script (JSFiddle, CodePen, etc.):**
|
|
79
|
+
```html
|
|
80
|
+
<script src="https://unpkg.com/waiit/app.umd.js"></script>
|
|
81
|
+
<script>
|
|
82
|
+
wait(1000).then(() => console.log('Done!'));
|
|
83
|
+
</script>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
## Examples
|
|
88
|
+
|
|
55
89
|
**Retry with delay:**
|
|
56
90
|
```js
|
|
91
|
+
import wait from 'waiit';
|
|
92
|
+
|
|
57
93
|
async function fetchWithRetry(url, retries = 3) {
|
|
58
94
|
for (let i = 0; i < retries; i++) {
|
|
59
95
|
try {
|
|
@@ -61,7 +97,7 @@ async function fetchWithRetry(url, retries = 3) {
|
|
|
61
97
|
} catch (e) {
|
|
62
98
|
if (i < retries - 1) {
|
|
63
99
|
console.log(`Retry ${i + 1}...`);
|
|
64
|
-
await wait(1000);
|
|
100
|
+
await wait(1000);
|
|
65
101
|
}
|
|
66
102
|
}
|
|
67
103
|
}
|
|
@@ -78,32 +114,18 @@ await wait(2000);
|
|
|
78
114
|
console.log('After 3 seconds total');
|
|
79
115
|
```
|
|
80
116
|
|
|
81
|
-
|
|
117
|
+
|
|
118
|
+
## CLI
|
|
82
119
|
|
|
83
120
|
```bash
|
|
84
121
|
# Via npx (no install needed)
|
|
85
|
-
npx waiit 2000
|
|
86
|
-
echo "Done!"
|
|
122
|
+
npx waiit 2000 && echo "Done!"
|
|
87
123
|
|
|
88
124
|
# Or install globally
|
|
89
125
|
npm i -g waiit
|
|
90
126
|
waiit 3000 && echo "3 seconds passed"
|
|
91
|
-
|
|
92
|
-
# Use in shell scripts
|
|
93
|
-
echo "Starting..."
|
|
94
|
-
waiit 1000
|
|
95
|
-
echo "Finished"
|
|
96
127
|
```
|
|
97
128
|
|
|
98
|
-
**Shell script example:**
|
|
99
|
-
```bash
|
|
100
|
-
#!/bin/bash
|
|
101
|
-
echo "Build starting..."
|
|
102
|
-
npm run build
|
|
103
|
-
waiit 2000 # Give time for build artifacts to settle
|
|
104
|
-
echo "Deploying..."
|
|
105
|
-
npm run deploy
|
|
106
|
-
```
|
|
107
129
|
|
|
108
130
|
## License
|
|
109
131
|
|
package/app.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports=t=>new Promise(r=>setTimeout(r,t))
|
package/app.global.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
((g,f)=>{typeof exports==="object"&&typeof module!=="undefined"?module.exports=f():typeof define==="function"&&define.amd?define(f):(g=g||self,g.wait=f())})(this,()=>t=>new Promise(r=>setTimeout(r,t)))
|
package/app.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export default t=>new Promise(r=>setTimeout(r,t))
|
package/package.json
CHANGED
|
@@ -1,20 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "waiit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Promise-based delay utility. Tiny, typed, zero dependencies.",
|
|
5
|
-
"main": "app.
|
|
6
|
-
"
|
|
7
|
-
"
|
|
5
|
+
"main": "app.cjs",
|
|
6
|
+
"module": "app.js",
|
|
7
|
+
"browser": "app.global.js",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"types": "app.d.ts",
|
|
10
|
+
"bin": "app.cli.js",
|
|
8
11
|
"exports": {
|
|
9
12
|
".": {
|
|
10
|
-
"types": "./
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
+
"types": "./app.d.ts",
|
|
14
|
+
"import": "./app.js",
|
|
15
|
+
"require": "./app.cjs"
|
|
13
16
|
}
|
|
14
17
|
},
|
|
18
|
+
"sideEffects": false,
|
|
15
19
|
"repository": "Raju/waiit",
|
|
16
|
-
"keywords": [
|
|
17
|
-
|
|
20
|
+
"keywords": [
|
|
21
|
+
"wait",
|
|
22
|
+
"delay",
|
|
23
|
+
"sleep",
|
|
24
|
+
"timeout",
|
|
25
|
+
"promise",
|
|
26
|
+
"async",
|
|
27
|
+
"await",
|
|
28
|
+
"setTimeout",
|
|
29
|
+
"timer",
|
|
30
|
+
"pause",
|
|
31
|
+
"browser",
|
|
32
|
+
"node",
|
|
33
|
+
"cli"
|
|
34
|
+
],
|
|
35
|
+
"author": "Raju Dhami <raju@rajudhami.com>",
|
|
36
|
+
"contributors": [
|
|
37
|
+
"Raju Dhami <raju@rajudhami.com>"
|
|
38
|
+
],
|
|
18
39
|
"license": "MIT",
|
|
19
|
-
"files": [
|
|
40
|
+
"files": [
|
|
41
|
+
"app.js",
|
|
42
|
+
"app.cjs",
|
|
43
|
+
"app.global.js",
|
|
44
|
+
"app.d.ts",
|
|
45
|
+
"app.cli.js"
|
|
46
|
+
],
|
|
47
|
+
"packageManager": "bun@1.3.6",
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=14"
|
|
50
|
+
}
|
|
20
51
|
}
|
/package/{cli.js → app.cli.js}
RENAMED
|
File without changes
|
/package/{index.d.ts → app.d.ts}
RENAMED
|
File without changes
|