@sha1n/about-time 0.0.13 → 0.2.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/dist/lib/delay.js +3 -4
- package/dist/lib/eventually.js +2 -2
- package/dist/lib/retry.js +5 -6
- package/dist/lib/stopwatch.js +1 -2
- package/dist/lib/timeout.js +2 -3
- package/dist/lib/toMilliseconds.js +1 -2
- package/dist/lib/types.js +1 -2
- package/dist/types/lib/types.d.ts +2 -2
- package/package.json +20 -10
package/dist/lib/delay.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.sleep = sleep;
|
|
4
|
+
exports.delay = delay;
|
|
5
|
+
exports.delayed = delayed;
|
|
4
6
|
const toMilliseconds_1 = require("./toMilliseconds");
|
|
5
7
|
/**
|
|
6
8
|
* Zzzz...
|
|
@@ -17,7 +19,6 @@ function sleep(time, options) {
|
|
|
17
19
|
}
|
|
18
20
|
});
|
|
19
21
|
}
|
|
20
|
-
exports.sleep = sleep;
|
|
21
22
|
/**
|
|
22
23
|
* Delays the execution of the specified action and returns its value.
|
|
23
24
|
*
|
|
@@ -30,7 +31,6 @@ async function delay(action, options) {
|
|
|
30
31
|
const result = await action();
|
|
31
32
|
return result;
|
|
32
33
|
}
|
|
33
|
-
exports.delay = delay;
|
|
34
34
|
/**
|
|
35
35
|
* Returns a new function that executes the specified action with delay.
|
|
36
36
|
*
|
|
@@ -43,4 +43,3 @@ function delayed(action, options) {
|
|
|
43
43
|
return delay(action, options);
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
-
exports.delayed = delayed;
|
package/dist/lib/eventually.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.eventually =
|
|
3
|
+
exports.eventually = void 0;
|
|
4
|
+
exports.until = until;
|
|
4
5
|
const toMilliseconds_1 = require("./toMilliseconds");
|
|
5
6
|
const types_1 = require("./types");
|
|
6
7
|
/**
|
|
@@ -36,7 +37,6 @@ async function until(condition, options) {
|
|
|
36
37
|
}
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
|
-
exports.until = until;
|
|
40
40
|
/**
|
|
41
41
|
* Alias to `until`
|
|
42
42
|
*/
|
package/dist/lib/retry.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.retryAround = retryAround;
|
|
4
|
+
exports.retriable = retriable;
|
|
5
|
+
exports.fixedRetryPolicy = fixedRetryPolicy;
|
|
6
|
+
exports.simpleRetryPolicy = simpleRetryPolicy;
|
|
7
|
+
exports.exponentialBackoffRetryPolicy = exponentialBackoffRetryPolicy;
|
|
4
8
|
const toMilliseconds_1 = require("./toMilliseconds");
|
|
5
9
|
const delay_1 = require("./delay");
|
|
6
10
|
const types_1 = require("./types");
|
|
@@ -53,15 +57,12 @@ class FixedRetryPolicy {
|
|
|
53
57
|
function simpleRetryPolicy(count, interval, opts) {
|
|
54
58
|
return Object.freeze(new SimpleRetryPolicy(count, interval, opts === null || opts === void 0 ? void 0 : opts.units));
|
|
55
59
|
}
|
|
56
|
-
exports.simpleRetryPolicy = simpleRetryPolicy;
|
|
57
60
|
function fixedRetryPolicy(intervals, opts) {
|
|
58
61
|
return Object.freeze(new FixedRetryPolicy(intervals, opts === null || opts === void 0 ? void 0 : opts.units));
|
|
59
62
|
}
|
|
60
|
-
exports.fixedRetryPolicy = fixedRetryPolicy;
|
|
61
63
|
function exponentialBackoffRetryPolicy(count, opts) {
|
|
62
64
|
return Object.freeze(new ExponentialBackoffRetryPolicy(count, opts === null || opts === void 0 ? void 0 : opts.exponential, opts === null || opts === void 0 ? void 0 : opts.limit, opts === null || opts === void 0 ? void 0 : opts.units));
|
|
63
65
|
}
|
|
64
|
-
exports.exponentialBackoffRetryPolicy = exponentialBackoffRetryPolicy;
|
|
65
66
|
async function retryAround(action, policy, predicate = () => true) {
|
|
66
67
|
let next;
|
|
67
68
|
const intervals = policy.intervals()[Symbol.iterator]();
|
|
@@ -79,10 +80,8 @@ async function retryAround(action, policy, predicate = () => true) {
|
|
|
79
80
|
} while (!next.done);
|
|
80
81
|
throw new Error('Unexpected error. This is most likely a bug.');
|
|
81
82
|
}
|
|
82
|
-
exports.retryAround = retryAround;
|
|
83
83
|
function retriable(action, policy, predicate = () => true) {
|
|
84
84
|
return () => {
|
|
85
85
|
return retryAround(action, policy, predicate);
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
|
-
exports.retriable = retriable;
|
package/dist/lib/stopwatch.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stopwatch =
|
|
3
|
+
exports.stopwatch = stopwatch;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
5
|
/**
|
|
6
6
|
* Return a function that returns the elapsed time relative to this call.
|
|
@@ -12,4 +12,3 @@ function stopwatch() {
|
|
|
12
12
|
return (Date.now() - startTime) / (units || types_1.TimeUnit.Milliseconds);
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
|
-
exports.stopwatch = stopwatch;
|
package/dist/lib/timeout.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.timeBounded = timeBounded;
|
|
4
|
+
exports.timeoutAround = timeoutAround;
|
|
4
5
|
const toMilliseconds_1 = require("./toMilliseconds");
|
|
5
6
|
const types_1 = require("./types");
|
|
6
7
|
/**
|
|
@@ -36,10 +37,8 @@ async function timeoutAround(action, options) {
|
|
|
36
37
|
});
|
|
37
38
|
return race;
|
|
38
39
|
}
|
|
39
|
-
exports.timeoutAround = timeoutAround;
|
|
40
40
|
function timeBounded(action, options) {
|
|
41
41
|
return () => {
|
|
42
42
|
return timeoutAround(action, options);
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
exports.timeBounded = timeBounded;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toMilliseconds =
|
|
3
|
+
exports.toMilliseconds = toMilliseconds;
|
|
4
4
|
/**
|
|
5
5
|
* Converts time value in other units to milliseconds.
|
|
6
6
|
*
|
|
@@ -11,4 +11,3 @@ exports.toMilliseconds = void 0;
|
|
|
11
11
|
function toMilliseconds(time, units) {
|
|
12
12
|
return time * (units ? units : 1);
|
|
13
13
|
}
|
|
14
|
-
exports.toMilliseconds = toMilliseconds;
|
package/dist/lib/types.js
CHANGED
|
@@ -13,8 +13,7 @@ var TimeUnit;
|
|
|
13
13
|
TimeUnit[TimeUnit["Hour"] = 3600000] = "Hour";
|
|
14
14
|
TimeUnit[TimeUnit["Days"] = 86400000] = "Days";
|
|
15
15
|
TimeUnit[TimeUnit["Day"] = 86400000] = "Day";
|
|
16
|
-
})(TimeUnit || (TimeUnit = {}));
|
|
17
|
-
exports.TimeUnit = TimeUnit;
|
|
16
|
+
})(TimeUnit || (exports.TimeUnit = TimeUnit = {}));
|
|
18
17
|
class TimeoutError extends Error {
|
|
19
18
|
constructor(message) {
|
|
20
19
|
super(message || 'Timeout');
|
|
@@ -13,7 +13,7 @@ declare enum TimeUnit {
|
|
|
13
13
|
declare class TimeoutError extends Error {
|
|
14
14
|
constructor(message?: string);
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
type TimerOptions = {
|
|
17
17
|
/**
|
|
18
18
|
* The time to set
|
|
19
19
|
*/
|
|
@@ -27,7 +27,7 @@ declare type TimerOptions = {
|
|
|
27
27
|
*/
|
|
28
28
|
readonly unref?: boolean;
|
|
29
29
|
};
|
|
30
|
-
|
|
30
|
+
type PollOptions = {
|
|
31
31
|
/**
|
|
32
32
|
* The poll interval to set
|
|
33
33
|
*/
|
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sha1n/about-time",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "commonjs",
|
|
4
5
|
"description": "A set of essential time related utilities",
|
|
5
6
|
"repository": "https://github.com/sha1n/about-time",
|
|
6
7
|
"author": "Shai Nagar",
|
|
7
8
|
"license": "MIT",
|
|
8
|
-
"types": "./dist/types",
|
|
9
9
|
"main": "./dist",
|
|
10
|
-
"
|
|
10
|
+
"types": "./dist/types/index.d.ts",
|
|
11
|
+
"exports": [
|
|
12
|
+
"./dist/index.js",
|
|
13
|
+
"./dist/types/index.d.ts"
|
|
14
|
+
],
|
|
11
15
|
"keywords": [
|
|
12
16
|
"time",
|
|
13
17
|
"wait",
|
|
@@ -32,11 +36,11 @@
|
|
|
32
36
|
"@types/chance": "^1.1.3",
|
|
33
37
|
"@types/is-ci": "^3.0.0",
|
|
34
38
|
"@types/jest": "^27.4.0",
|
|
35
|
-
"@types/node": "^
|
|
36
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
37
|
-
"@typescript-eslint/parser": "^
|
|
39
|
+
"@types/node": "^22.0.0",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
41
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
38
42
|
"chance": "^1.1.8",
|
|
39
|
-
"eslint": "^8.
|
|
43
|
+
"eslint": "^8.57.0",
|
|
40
44
|
"eslint-config-prettier": "^8.5.0",
|
|
41
45
|
"eslint-plugin-import": "^2.26.0",
|
|
42
46
|
"eslint-plugin-jest": "^26.1.4",
|
|
@@ -53,8 +57,14 @@
|
|
|
53
57
|
"jest-summary-reporter": "^0.0.2",
|
|
54
58
|
"prettier": "^2.6.2",
|
|
55
59
|
"ts-jest": "^27.1.4",
|
|
56
|
-
"ts-node": "^10.
|
|
57
|
-
"typescript": "^
|
|
60
|
+
"ts-node": "^10.9.2",
|
|
61
|
+
"typescript": "^5.5.0"
|
|
62
|
+
},
|
|
63
|
+
"packageManager": "yarn@3.2.0",
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"@typescript-eslint/typescript-estree": "^8.0.0"
|
|
58
66
|
},
|
|
59
|
-
"
|
|
67
|
+
"engines": {
|
|
68
|
+
"node": ">=24"
|
|
69
|
+
}
|
|
60
70
|
}
|