@parasrp/delay 1.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.
Files changed (4) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +85 -8
  3. package/index.js +28 -7
  4. package/package.json +35 -16
package/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Paras R Poshiya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,19 +1,96 @@
1
1
  # @parasrp/delay
2
2
 
3
- A small and simple JavaScript utility to pause execution for a specified number of milliseconds.
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+ ![npm version](https://img.shields.io/npm/v/@parasrp/delay)
5
+ ![npm downloads](https://img.shields.io/npm/dw/@parasrp/delay)
6
+ ![install size](https://packagephobia.com/badge?p=@parasrp/delay)
7
+ ![bundle size](https://img.shields.io/bundlephobia/min/@parasrp/delay)
4
8
 
9
+ A lightweight, promise-based JavaScript utility to pause execution for a specified duration. Perfect for adding timeouts, staggering API calls, or building simple animations.
10
+
11
+ ---
5
12
  ## ✨ Features
6
13
 
7
- - Lightweight and fast
8
- - Promise-based
9
- - No dependencies
10
- - Works in any modern JavaScript environment
14
+ - đŸĒļ **Lightweight & Fast**: Zero overhead, minimal footprint.
15
+ - 🤝 **Promise-based**: Works seamlessly with `async/await`.
16
+ - đŸ“Ļ **Zero Dependencies**: Keeps your node_modules clean.
17
+ - 🌍 **Universal**: Works in Node.js, browsers, and modern JS environments.
18
+ - âąī¸ **Flexible Units**: Supports `milliseconds`, `seconds`, `minutes`, and `hours`.
11
19
 
12
20
  ---
13
-
14
21
  ## đŸ“Ļ Installation
15
22
 
16
- Install using npm:
17
-
23
+ Install the package via npm:
18
24
  ```bash
19
25
  npm install @parasrp/delay
26
+ ```
27
+
28
+ Install the package via yarn:
29
+ ```bash
30
+ yarn add @parasrp/delay
31
+ ```
32
+
33
+ ---
34
+ ## ✨ Features
35
+ You can use @parasrp/delay with both CommonJS and ES Modules.
36
+
37
+ ES6 Modules:
38
+ ```js
39
+ import delay from "@parasrp/delay";
40
+ ```
41
+
42
+ CommonJS:
43
+ ```js
44
+ const delay = require("@parasrp/delay");
45
+ ```
46
+
47
+ ---
48
+ ## 📖 API
49
+
50
+ ```js
51
+ /**
52
+ * Sleep (pause execution) for a given time with unit
53
+ * @param {number} value - The amount of time to wait
54
+ * @param {'milliseconds'|'seconds'|'minutes'|'hours'} [unit='milliseconds'] - The unit of time (default is milliseconds)
55
+ * @returns {Promise<void>} - A Promise that resolves after the specified delay
56
+ **/
57
+ await delay(value, unit?);
58
+ ```
59
+
60
+ ---
61
+ ## Examples
62
+
63
+ Using async/await:
64
+ ```js
65
+ async function demo() {
66
+ console.log("Waiting 2 seconds...");
67
+ await delay(2, "seconds"); // waits 2000 ms
68
+ console.log("Done!");
69
+
70
+ console.log("Waiting 1 minute...");
71
+ await delay(1, "minutes"); // waits 60000 ms
72
+ console.log("Finished!");
73
+ }
74
+
75
+ demo();
76
+ ```
77
+
78
+ Using .then():
79
+ ```js
80
+ console.log("Start waiting...");
81
+
82
+ delay(1000).then(() => {
83
+ console.log("Finished waiting 1000 milliseconds");
84
+ });
85
+
86
+ delay(0.5, "hours").then(() => {
87
+ console.log("Finished waiting 30 minutes");
88
+ });
89
+
90
+ ```
91
+
92
+ ---
93
+ ## 👤 Author
94
+ **Paras R Poshiya**
95
+ * [GitHub](https://github.com/parasposhiya)
96
+ * [GitLab](https://gitlab.com/parasposhiya)
package/index.js CHANGED
@@ -1,10 +1,31 @@
1
1
  /**
2
- * Sleep for given milliseconds
3
- * @param {number} ms
4
- * @returns {Promise<void>}
5
- */
2
+ * Sleep (pause execution) for a given time with unit
3
+ * @param {number} value - The amount of time to wait
4
+ * @param {'milliseconds'|'seconds'|'minutes'|'hours'} [unit='milliseconds'] - The unit of time (default is milliseconds)
5
+ * @returns {Promise<void>} - A Promise that resolves after the specified delay
6
+ **/
7
+ const delay = (value, unit = 'milliseconds') => {
8
+ let ms; // variable to hold the converted time in milliseconds
6
9
 
7
- const delay = (ms) =>
8
- new Promise((resolve) => setTimeout(resolve, ms));
10
+ // Convert the given value into milliseconds based on the unit
11
+ switch (unit) {
12
+ case 'seconds':
13
+ ms = value * 1000; // 1 second = 1000 ms
14
+ break;
15
+ case 'minutes':
16
+ ms = value * 1000 * 60; // 1 minute = 60,000 ms
17
+ break;
18
+ case 'hours':
19
+ ms = value * 1000 * 60 * 60; // 1 hour = 3,600,000 ms
20
+ break;
21
+ case 'milliseconds':
22
+ default:
23
+ ms = value; // already in milliseconds
24
+ }
9
25
 
10
- export default delay
26
+ // Return a Promise that resolves after the calculated milliseconds
27
+ return new Promise((resolve) => setTimeout(resolve, ms));
28
+ };
29
+
30
+ // Export the function so it can be imported in other files
31
+ export default delay;
package/package.json CHANGED
@@ -1,16 +1,35 @@
1
- {
2
- "name": "@parasrp/delay",
3
- "version": "1.0.1",
4
- "description": "sleep function",
5
- "author": "Paras R Poshiya",
6
- "keywords": [
7
- "sleep",
8
- "delay"
9
- ],
10
- "license": "MIT",
11
- "main": "index.js",
12
- "type": "module",
13
- "exports": {
14
- ".": "./index.js"
15
- }
16
- }
1
+ {
2
+ "name": "@parasrp/delay",
3
+ "version": "2.0.0",
4
+ "description": "A simple sleep/delay function with support for milliseconds, seconds, minutes, and hours.",
5
+ "author": "Paras R Poshiya",
6
+ "keywords": [
7
+ "sleep",
8
+ "delay",
9
+ "wait",
10
+ "timeout",
11
+ "pause"
12
+ ],
13
+ "license": "MIT",
14
+ "main": "index.js",
15
+ "type": "module",
16
+ "exports": {
17
+ ".": "./index.js"
18
+ },
19
+ "scripts": {
20
+ "test": "node --test",
21
+ "build": "echo 'No build step yet' && exit 0"
22
+ },
23
+ "files": [
24
+ "index.js",
25
+ "README.md"
26
+ ],
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://gitlab.com/parasrp-npm/delay.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://gitlab.com/parasrp-npm/delay/issues"
33
+ },
34
+ "homepage": "https://gitlab.com/parasrp-npm/delay#readme"
35
+ }