@beauraines/node-helpers 5.2.5 → 5.3.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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [5.3.0](https://github.com/beauraines/node-helpers/compare/v5.2.5...v5.3.0) (2024-12-21)
6
+
7
+
8
+ ### Features
9
+
10
+ * **helper:** async sleep function ([fc26a39](https://github.com/beauraines/node-helpers/commit/fc26a39fa54a353aba297390112646d01b450498))
11
+
5
12
  ### [5.2.5](https://github.com/beauraines/node-helpers/compare/v5.2.4...v5.2.5) (2024-12-07)
6
13
 
7
14
  ### [5.2.4](https://github.com/beauraines/node-helpers/compare/v5.2.3...v5.2.4) (2024-11-26)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beauraines/node-helpers",
3
- "version": "5.2.5",
3
+ "version": "5.3.0",
4
4
  "description": "Collection of node helpers",
5
5
  "main": "index.js",
6
6
  "repository": {
package/src/helpers.js CHANGED
@@ -218,6 +218,10 @@ const decompressFile = (filePath) => {
218
218
  return fs.createReadStream(filePath).pipe(gunzip());
219
219
  };
220
220
 
221
+ const sleep = async (milliseconds) => {
222
+ return new Promise(resolve => setTimeout(resolve, milliseconds))
223
+ }
224
+
221
225
 
222
226
  module.exports = {
223
227
  decompressFile,
@@ -227,6 +231,7 @@ module.exports = {
227
231
  groupAndSum,
228
232
  readFile,
229
233
  listFiles,
234
+ sleep,
230
235
  sparkline,
231
236
  streamToBuffer,
232
237
  stripNewLines,
@@ -45,5 +45,13 @@ describe('helpers',()=> {
45
45
  expect(convertedDate).toBe(expectedOutput);
46
46
  })
47
47
 
48
+ it('should sleep for 1 second', async () => {
49
+ let expectedEnd = new Date();
50
+ expectedEnd.setSeconds(expectedEnd.getSeconds() + 1); // Modify expectedEnd directly
51
+ await helper.sleep(1000);
52
+ const end = new Date();
53
+ expect(end.getTime()).toBeCloseTo(expectedEnd.getTime(), -2); // Allow slight deviation
54
+ })
55
+
48
56
  })
49
57