@oscarpalmer/timer 0.35.0 → 0.36.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/get.cjs +7 -1
- package/dist/get.js +7 -2
- package/dist/repeat.cjs +2 -2
- package/dist/repeat.js +2 -2
- package/dist/timer.full.js +10 -8
- package/dist/when.cjs +1 -1
- package/dist/when.js +3 -3
- package/package.json +1 -1
- package/src/get.ts +10 -5
- package/src/models.ts +34 -26
- package/src/repeat.ts +2 -2
- package/src/when.ts +2 -3
- package/types/get.d.cts +1 -0
- package/types/get.d.ts +1 -0
- package/types/index.d.cts +10 -2
- package/types/is.d.cts +1 -1
- package/types/models.d.cts +10 -2
- package/types/models.d.ts +10 -2
- package/types/repeat.d.cts +9 -1
- package/types/when.d.cts +1 -1
package/dist/get.cjs
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown_runtime.cjs");
|
|
2
|
+
const require_constants = require("./constants.cjs");
|
|
2
3
|
const __oscarpalmer_atoms_function = require_rolldown_runtime.__toESM(require("@oscarpalmer/atoms/function"));
|
|
3
4
|
function getCallback(value) {
|
|
4
5
|
return typeof value === "function" ? value : __oscarpalmer_atoms_function.noop;
|
|
5
6
|
}
|
|
7
|
+
function getValidTimeout(value) {
|
|
8
|
+
return typeof value === "number" && value > 0 ? value : require_constants.defaultTimeout;
|
|
9
|
+
}
|
|
6
10
|
function getValidNumber(value, defaultValue) {
|
|
7
|
-
|
|
11
|
+
const actualDefault = defaultValue ?? 0;
|
|
12
|
+
return typeof value === "number" && value > actualDefault ? value : actualDefault;
|
|
8
13
|
}
|
|
9
14
|
exports.getCallback = getCallback;
|
|
10
15
|
exports.getValidNumber = getValidNumber;
|
|
16
|
+
exports.getValidTimeout = getValidTimeout;
|
package/dist/get.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import { defaultTimeout } from "./constants.js";
|
|
1
2
|
import { noop } from "@oscarpalmer/atoms/function";
|
|
2
3
|
function getCallback(value) {
|
|
3
4
|
return typeof value === "function" ? value : noop;
|
|
4
5
|
}
|
|
6
|
+
function getValidTimeout(value) {
|
|
7
|
+
return typeof value === "number" && value > 0 ? value : defaultTimeout;
|
|
8
|
+
}
|
|
5
9
|
function getValidNumber(value, defaultValue) {
|
|
6
|
-
|
|
10
|
+
const actualDefault = defaultValue ?? 0;
|
|
11
|
+
return typeof value === "number" && value > actualDefault ? value : actualDefault;
|
|
7
12
|
}
|
|
8
|
-
export { getCallback, getValidNumber };
|
|
13
|
+
export { getCallback, getValidNumber, getValidTimeout };
|
package/dist/repeat.cjs
CHANGED
|
@@ -9,10 +9,10 @@ function repeat(callback, options) {
|
|
|
9
9
|
trace: new require_models.TimerTrace().stack
|
|
10
10
|
}, {
|
|
11
11
|
onAfter: require_get.getCallback(options?.onAfter),
|
|
12
|
-
onError:
|
|
12
|
+
onError: require_get.getCallback(options?.onTimeout),
|
|
13
13
|
count: require_get.getValidNumber(options?.count),
|
|
14
14
|
interval: require_get.getValidNumber(options?.interval, require_constants.milliseconds),
|
|
15
|
-
timeout:
|
|
15
|
+
timeout: require_get.getValidNumber(options?.timeout)
|
|
16
16
|
}, true);
|
|
17
17
|
}
|
|
18
18
|
exports.repeat = repeat;
|
package/dist/repeat.js
CHANGED
|
@@ -9,10 +9,10 @@ function repeat(callback, options) {
|
|
|
9
9
|
trace: new TimerTrace().stack
|
|
10
10
|
}, {
|
|
11
11
|
onAfter: getCallback(options?.onAfter),
|
|
12
|
-
onError:
|
|
12
|
+
onError: getCallback(options?.onTimeout),
|
|
13
13
|
count: getValidNumber(options?.count),
|
|
14
14
|
interval: getValidNumber(options?.interval, milliseconds),
|
|
15
|
-
timeout:
|
|
15
|
+
timeout: getValidNumber(options?.timeout)
|
|
16
16
|
}, true);
|
|
17
17
|
}
|
|
18
18
|
export { repeat };
|
package/dist/timer.full.js
CHANGED
|
@@ -100,12 +100,14 @@ calculate().then((value) => {
|
|
|
100
100
|
function getCallback(value) {
|
|
101
101
|
return typeof value === 'function' ? value : noop;
|
|
102
102
|
}
|
|
103
|
+
function getValidTimeout(value) {
|
|
104
|
+
return typeof value === 'number' && value > 0 ? value : defaultTimeout;
|
|
105
|
+
}
|
|
103
106
|
function getValidNumber(value, defaultValue) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
: (defaultValue ?? 0);
|
|
107
|
+
const actualDefault = defaultValue ?? 0;
|
|
108
|
+
return typeof value === 'number' && value > actualDefault
|
|
109
|
+
? value
|
|
110
|
+
: actualDefault;
|
|
109
111
|
}
|
|
110
112
|
|
|
111
113
|
/**
|
|
@@ -370,10 +372,10 @@ function repeat(callback, options) {
|
|
|
370
372
|
trace: new TimerTrace().stack,
|
|
371
373
|
}, {
|
|
372
374
|
onAfter: getCallback(options?.onAfter),
|
|
373
|
-
onError:
|
|
375
|
+
onError: getCallback(options?.onTimeout),
|
|
374
376
|
count: getValidNumber(options?.count),
|
|
375
377
|
interval: getValidNumber(options?.interval, milliseconds),
|
|
376
|
-
timeout:
|
|
378
|
+
timeout: getValidNumber(options?.timeout),
|
|
377
379
|
}, true);
|
|
378
380
|
}
|
|
379
381
|
|
|
@@ -466,7 +468,7 @@ class When {
|
|
|
466
468
|
},
|
|
467
469
|
count: getValidNumber(options?.count),
|
|
468
470
|
interval: getValidNumber(options?.interval, milliseconds),
|
|
469
|
-
timeout:
|
|
471
|
+
timeout: getValidTimeout(options?.timeout),
|
|
470
472
|
}, false);
|
|
471
473
|
}
|
|
472
474
|
/**
|
package/dist/when.cjs
CHANGED
|
@@ -57,7 +57,7 @@ var When = class {
|
|
|
57
57
|
},
|
|
58
58
|
count: require_get.getValidNumber(options?.count),
|
|
59
59
|
interval: require_get.getValidNumber(options?.interval, require_constants.milliseconds),
|
|
60
|
-
timeout: require_get.
|
|
60
|
+
timeout: require_get.getValidTimeout(options?.timeout)
|
|
61
61
|
}, false);
|
|
62
62
|
}
|
|
63
63
|
continue() {
|
package/dist/when.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TYPE_WHEN,
|
|
2
|
-
import { getValidNumber } from "./get.js";
|
|
1
|
+
import { TYPE_WHEN, destroyedMessage, milliseconds, startedMessage } from "./constants.js";
|
|
2
|
+
import { getValidNumber, getValidTimeout } from "./get.js";
|
|
3
3
|
import "./global.js";
|
|
4
4
|
import { TimerTrace } from "./models.js";
|
|
5
5
|
import { Timer } from "./timer.js";
|
|
@@ -56,7 +56,7 @@ var When = class {
|
|
|
56
56
|
},
|
|
57
57
|
count: getValidNumber(options?.count),
|
|
58
58
|
interval: getValidNumber(options?.interval, milliseconds),
|
|
59
|
-
timeout:
|
|
59
|
+
timeout: getValidTimeout(options?.timeout)
|
|
60
60
|
}, false);
|
|
61
61
|
}
|
|
62
62
|
continue() {
|
package/package.json
CHANGED
package/src/get.ts
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import {noop} from '@oscarpalmer/atoms/function';
|
|
2
2
|
import type {GenericCallback} from '@oscarpalmer/atoms/models';
|
|
3
|
+
import {defaultTimeout} from './constants';
|
|
3
4
|
|
|
4
5
|
export function getCallback(value: unknown): GenericCallback {
|
|
5
6
|
return typeof value === 'function' ? (value as GenericCallback) : noop;
|
|
6
7
|
}
|
|
7
8
|
|
|
9
|
+
export function getValidTimeout(value: unknown): number {
|
|
10
|
+
return typeof value === 'number' && value > 0 ? value : defaultTimeout;
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
export function getValidNumber(value: unknown, defaultValue?: number): number {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
:
|
|
14
|
+
const actualDefault = defaultValue ?? 0;
|
|
15
|
+
|
|
16
|
+
return typeof value === 'number' && value > actualDefault
|
|
17
|
+
? value
|
|
18
|
+
: actualDefault;
|
|
14
19
|
}
|
package/src/models.ts
CHANGED
|
@@ -4,19 +4,27 @@ import type {Timer} from './timer';
|
|
|
4
4
|
* Options for a repeating timer
|
|
5
5
|
*/
|
|
6
6
|
export type RepeatOptions = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Callback to be called when the timer has stopped, either manually or by completing its work
|
|
9
|
+
*/
|
|
10
|
+
onAfter: (finished: boolean) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Callback to be called after the timer has timed out
|
|
13
|
+
*/
|
|
14
|
+
onTimeout: () => void;
|
|
15
|
+
/**
|
|
16
|
+
* How many times the timer should repeat
|
|
17
|
+
*/
|
|
18
|
+
count: number;
|
|
19
|
+
/**
|
|
20
|
+
* The interval between each repeat
|
|
21
|
+
*/
|
|
22
|
+
interval: number;
|
|
23
|
+
/**
|
|
24
|
+
* The timeout for the timer _(any value above `0` will enable the timeout)_
|
|
25
|
+
*/
|
|
26
|
+
timeout: number;
|
|
27
|
+
};
|
|
20
28
|
|
|
21
29
|
export type TimerOptions = {
|
|
22
30
|
onAfter: ((finished: boolean) => void) | undefined;
|
|
@@ -52,19 +60,19 @@ export type TimerType = 'repeat' | 'wait' | 'when';
|
|
|
52
60
|
* Options for a conditional timer
|
|
53
61
|
*/
|
|
54
62
|
export type WhenOptions = {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
};
|
|
63
|
+
/**
|
|
64
|
+
* How many times the timer should check the condition
|
|
65
|
+
*/
|
|
66
|
+
count: number;
|
|
67
|
+
/**
|
|
68
|
+
* Then interval between each condtional check
|
|
69
|
+
*/
|
|
70
|
+
interval: number;
|
|
71
|
+
/**
|
|
72
|
+
* The timeout for the timer _(any value above `0` will enable the timeout)_
|
|
73
|
+
*/
|
|
74
|
+
timeout: number;
|
|
75
|
+
};
|
|
68
76
|
|
|
69
77
|
export type WhenState = {
|
|
70
78
|
promise: Promise<void>;
|
package/src/repeat.ts
CHANGED
|
@@ -19,10 +19,10 @@ export function repeat(
|
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
21
|
onAfter: getCallback(options?.onAfter),
|
|
22
|
-
onError:
|
|
22
|
+
onError: getCallback(options?.onTimeout),
|
|
23
23
|
count: getValidNumber(options?.count),
|
|
24
24
|
interval: getValidNumber(options?.interval, milliseconds),
|
|
25
|
-
timeout:
|
|
25
|
+
timeout: getValidNumber(options?.timeout),
|
|
26
26
|
},
|
|
27
27
|
true,
|
|
28
28
|
);
|
package/src/when.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import {noop} from '@oscarpalmer/atoms/function';
|
|
2
2
|
import {
|
|
3
|
-
defaultTimeout,
|
|
4
3
|
destroyedMessage,
|
|
5
4
|
milliseconds,
|
|
6
5
|
startedMessage,
|
|
7
6
|
TYPE_WHEN,
|
|
8
7
|
} from './constants';
|
|
9
|
-
import {getValidNumber} from './get';
|
|
8
|
+
import {getValidNumber, getValidTimeout} from './get';
|
|
10
9
|
import './global';
|
|
11
10
|
import {TimerTrace, type WhenOptions, type WhenState} from './models';
|
|
12
11
|
import {Timer} from './timer';
|
|
@@ -95,7 +94,7 @@ class When {
|
|
|
95
94
|
},
|
|
96
95
|
count: getValidNumber(options?.count),
|
|
97
96
|
interval: getValidNumber(options?.interval, milliseconds),
|
|
98
|
-
timeout:
|
|
97
|
+
timeout: getValidTimeout(options?.timeout),
|
|
99
98
|
},
|
|
100
99
|
false,
|
|
101
100
|
);
|
package/types/get.d.cts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export type GenericCallback = (...args: any[]) => any;
|
|
7
7
|
export declare function getCallback(value: unknown): GenericCallback;
|
|
8
|
+
export declare function getValidTimeout(value: unknown): number;
|
|
8
9
|
export declare function getValidNumber(value: unknown, defaultValue?: number): number;
|
|
9
10
|
|
|
10
11
|
export {};
|
package/types/get.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { GenericCallback } from '@oscarpalmer/atoms/models';
|
|
2
2
|
export declare function getCallback(value: unknown): GenericCallback;
|
|
3
|
+
export declare function getValidTimeout(value: unknown): number;
|
|
3
4
|
export declare function getValidNumber(value: unknown, defaultValue?: number): number;
|
package/types/index.d.cts
CHANGED
|
@@ -54,7 +54,11 @@ export type RepeatOptions = {
|
|
|
54
54
|
/**
|
|
55
55
|
* Callback to be called when the timer has stopped, either manually or by completing its work
|
|
56
56
|
*/
|
|
57
|
-
onAfter: (
|
|
57
|
+
onAfter: (finished: boolean) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Callback to be called after the timer has timed out
|
|
60
|
+
*/
|
|
61
|
+
onTimeout: () => void;
|
|
58
62
|
/**
|
|
59
63
|
* How many times the timer should repeat
|
|
60
64
|
*/
|
|
@@ -63,6 +67,10 @@ export type RepeatOptions = {
|
|
|
63
67
|
* The interval between each repeat
|
|
64
68
|
*/
|
|
65
69
|
interval: number;
|
|
70
|
+
/**
|
|
71
|
+
* The timeout for the timer _(any value above `0` will enable the timeout)_
|
|
72
|
+
*/
|
|
73
|
+
timeout: number;
|
|
66
74
|
};
|
|
67
75
|
export type TimerOptions = {
|
|
68
76
|
onAfter: ((finished: boolean) => void) | undefined;
|
|
@@ -96,7 +104,7 @@ export type WhenOptions = {
|
|
|
96
104
|
*/
|
|
97
105
|
interval: number;
|
|
98
106
|
/**
|
|
99
|
-
* The timeout for the timer
|
|
107
|
+
* The timeout for the timer _(any value above `0` will enable the timeout)_
|
|
100
108
|
*/
|
|
101
109
|
timeout: number;
|
|
102
110
|
};
|
package/types/is.d.cts
CHANGED
package/types/models.d.cts
CHANGED
|
@@ -54,7 +54,11 @@ export type RepeatOptions = {
|
|
|
54
54
|
/**
|
|
55
55
|
* Callback to be called when the timer has stopped, either manually or by completing its work
|
|
56
56
|
*/
|
|
57
|
-
onAfter: (
|
|
57
|
+
onAfter: (finished: boolean) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Callback to be called after the timer has timed out
|
|
60
|
+
*/
|
|
61
|
+
onTimeout: () => void;
|
|
58
62
|
/**
|
|
59
63
|
* How many times the timer should repeat
|
|
60
64
|
*/
|
|
@@ -63,6 +67,10 @@ export type RepeatOptions = {
|
|
|
63
67
|
* The interval between each repeat
|
|
64
68
|
*/
|
|
65
69
|
interval: number;
|
|
70
|
+
/**
|
|
71
|
+
* The timeout for the timer _(any value above `0` will enable the timeout)_
|
|
72
|
+
*/
|
|
73
|
+
timeout: number;
|
|
66
74
|
};
|
|
67
75
|
export type TimerOptions = {
|
|
68
76
|
onAfter: ((finished: boolean) => void) | undefined;
|
|
@@ -99,7 +107,7 @@ export type WhenOptions = {
|
|
|
99
107
|
*/
|
|
100
108
|
interval: number;
|
|
101
109
|
/**
|
|
102
|
-
* The timeout for the timer
|
|
110
|
+
* The timeout for the timer _(any value above `0` will enable the timeout)_
|
|
103
111
|
*/
|
|
104
112
|
timeout: number;
|
|
105
113
|
};
|
package/types/models.d.ts
CHANGED
|
@@ -6,7 +6,11 @@ export type RepeatOptions = {
|
|
|
6
6
|
/**
|
|
7
7
|
* Callback to be called when the timer has stopped, either manually or by completing its work
|
|
8
8
|
*/
|
|
9
|
-
onAfter: (
|
|
9
|
+
onAfter: (finished: boolean) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Callback to be called after the timer has timed out
|
|
12
|
+
*/
|
|
13
|
+
onTimeout: () => void;
|
|
10
14
|
/**
|
|
11
15
|
* How many times the timer should repeat
|
|
12
16
|
*/
|
|
@@ -15,6 +19,10 @@ export type RepeatOptions = {
|
|
|
15
19
|
* The interval between each repeat
|
|
16
20
|
*/
|
|
17
21
|
interval: number;
|
|
22
|
+
/**
|
|
23
|
+
* The timeout for the timer _(any value above `0` will enable the timeout)_
|
|
24
|
+
*/
|
|
25
|
+
timeout: number;
|
|
18
26
|
};
|
|
19
27
|
export type TimerOptions = {
|
|
20
28
|
onAfter: ((finished: boolean) => void) | undefined;
|
|
@@ -51,7 +59,7 @@ export type WhenOptions = {
|
|
|
51
59
|
*/
|
|
52
60
|
interval: number;
|
|
53
61
|
/**
|
|
54
|
-
* The timeout for the timer
|
|
62
|
+
* The timeout for the timer _(any value above `0` will enable the timeout)_
|
|
55
63
|
*/
|
|
56
64
|
timeout: number;
|
|
57
65
|
};
|
package/types/repeat.d.cts
CHANGED
|
@@ -54,7 +54,11 @@ export type RepeatOptions = {
|
|
|
54
54
|
/**
|
|
55
55
|
* Callback to be called when the timer has stopped, either manually or by completing its work
|
|
56
56
|
*/
|
|
57
|
-
onAfter: (
|
|
57
|
+
onAfter: (finished: boolean) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Callback to be called after the timer has timed out
|
|
60
|
+
*/
|
|
61
|
+
onTimeout: () => void;
|
|
58
62
|
/**
|
|
59
63
|
* How many times the timer should repeat
|
|
60
64
|
*/
|
|
@@ -63,6 +67,10 @@ export type RepeatOptions = {
|
|
|
63
67
|
* The interval between each repeat
|
|
64
68
|
*/
|
|
65
69
|
interval: number;
|
|
70
|
+
/**
|
|
71
|
+
* The timeout for the timer _(any value above `0` will enable the timeout)_
|
|
72
|
+
*/
|
|
73
|
+
timeout: number;
|
|
66
74
|
};
|
|
67
75
|
export type TimerOptions = {
|
|
68
76
|
onAfter: ((finished: boolean) => void) | undefined;
|