waiit 2.0.0 → 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 CHANGED
@@ -8,13 +8,26 @@ Promise-based delay utility. Tiny, typed, zero dependencies.
8
8
 
9
9
  ## Features
10
10
 
11
- 🪶 Lightweight (1 line) · ⚡ Simple async/await API · 📦 TypeScript ready · 🔧 Flexible · 🌐 Universal (Node.js & Browser) · 💻 CLI support
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,65 +36,97 @@ 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
- ```js
36
- // CommonJS
37
- const wait = require('waiit');
48
+ ### ES Modules
38
49
 
39
- // ES Modules
50
+ ```js
40
51
  import wait from 'waiit';
41
52
 
42
- // Browser (CDN)
43
- import wait from 'https://unpkg.com/waiit/app.js';
53
+ await wait(2000); // Pause for 2 seconds
54
+ await wait(500); // Pause for 500ms
55
+ await wait(); // Continue immediately (0ms)
44
56
  ```
45
57
 
58
+ ### CommonJS
59
+
46
60
  ```js
47
- await wait(2000); // Wait 2 seconds
48
- await wait(); // Resolve immediately
61
+ const wait = require('waiit');
62
+
63
+ await wait(2000);
49
64
  ```
50
65
 
51
- ### Retry with delay
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
+
89
+ **Retry with delay:**
52
90
  ```js
91
+ import wait from 'waiit';
92
+
53
93
  async function fetchWithRetry(url, retries = 3) {
54
94
  for (let i = 0; i < retries; i++) {
55
95
  try {
56
96
  return await fetch(url);
57
97
  } catch (e) {
58
- if (i < retries - 1) await wait(1000);
98
+ if (i < retries - 1) {
99
+ console.log(`Retry ${i + 1}...`);
100
+ await wait(1000);
101
+ }
59
102
  }
60
103
  }
61
- throw new Error('Failed');
104
+ throw new Error('Max retries reached');
62
105
  }
63
106
  ```
64
107
 
65
- ### Sequential execution
108
+ **Sequential execution:**
66
109
  ```js
67
- for (const step of steps) {
68
- console.log(step.message);
69
- await wait(step.delay);
70
- }
110
+ console.log('Starting...');
111
+ await wait(1000);
112
+ console.log('After 1 second');
113
+ await wait(2000);
114
+ console.log('After 3 seconds total');
71
115
  ```
72
116
 
117
+
73
118
  ## CLI
74
119
 
75
120
  ```bash
76
- # Via npx
77
- npx waiit 2000 # Wait 2 seconds
121
+ # Via npx (no install needed)
122
+ npx waiit 2000 && echo "Done!"
78
123
 
79
124
  # Or install globally
80
125
  npm i -g waiit
81
- waiit 3000 # Wait 3 seconds
82
- waiit # Exit immediately
126
+ waiit 3000 && echo "3 seconds passed"
83
127
  ```
84
128
 
129
+
85
130
  ## License
86
131
 
87
- [MIT](LICENSE) © Raju Dhami
132
+ [MIT](LICENSE) © [Raju Dhami](https://github.com/Raju)
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
- module.exports=t=>new Promise(r=>setTimeout(r,t))
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": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "Promise-based delay utility. Tiny, typed, zero dependencies.",
5
- "main": "app.js",
6
- "types": "index.d.ts",
7
- "bin": "cli.js",
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": "./index.d.ts",
11
- "require": "./app.js",
12
- "import": "./app.js"
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": ["wait","delay","sleep","timeout","promise","async","await","setTimeout","timer","pause","browser","node","cli"],
17
- "author": "Raju Dhami",
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": ["app.js", "index.d.ts", "cli.js"]
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
  }
File without changes
File without changes