@dereekb/util 11.1.5 → 11.1.6
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/fetch/package.json +1 -1
- package/index.cjs.js +13 -5
- package/index.esm.js +13 -5
- package/package.json +1 -1
- package/src/lib/date/expires.d.ts +14 -5
- package/test/CHANGELOG.md +4 -0
- package/test/package.json +1 -1
package/fetch/package.json
CHANGED
package/index.cjs.js
CHANGED
|
@@ -13049,6 +13049,7 @@ function expirationDetails(input) {
|
|
|
13049
13049
|
expires,
|
|
13050
13050
|
now: inputNow,
|
|
13051
13051
|
expiresFromDate,
|
|
13052
|
+
defaultExpiresFromDateToNow,
|
|
13052
13053
|
expiresIn
|
|
13053
13054
|
} = input;
|
|
13054
13055
|
const parsedExpiresFromDate = expiresFromDate != null ? dateFromDateOrTimeNumber(expiresFromDate) : null;
|
|
@@ -13057,10 +13058,16 @@ function expirationDetails(input) {
|
|
|
13057
13058
|
const now = (_ref = nowOverride != null ? nowOverride : inputNow) != null ? _ref : new Date();
|
|
13058
13059
|
return now;
|
|
13059
13060
|
}
|
|
13060
|
-
function hasExpired(nowOverride) {
|
|
13061
|
+
function hasExpired(nowOverride, defaultIfNoExpirationDate = false) {
|
|
13061
13062
|
const now = getNow(nowOverride);
|
|
13062
13063
|
const expirationDate = getExpirationDateForNow(now);
|
|
13063
|
-
|
|
13064
|
+
let result;
|
|
13065
|
+
if (expirationDate == null) {
|
|
13066
|
+
result = defaultIfNoExpirationDate;
|
|
13067
|
+
} else {
|
|
13068
|
+
result = expirationDate <= now;
|
|
13069
|
+
}
|
|
13070
|
+
return result;
|
|
13064
13071
|
}
|
|
13065
13072
|
function getExpirationDate(nowOverride) {
|
|
13066
13073
|
const now = getNow(nowOverride);
|
|
@@ -13073,7 +13080,7 @@ function expirationDetails(input) {
|
|
|
13073
13080
|
} else if (expiresAt != null) {
|
|
13074
13081
|
expirationDate = expiresAt;
|
|
13075
13082
|
} else if (expiresIn != null) {
|
|
13076
|
-
const date = parsedExpiresFromDate != null ? parsedExpiresFromDate : now;
|
|
13083
|
+
const date = parsedExpiresFromDate != null ? parsedExpiresFromDate : defaultExpiresFromDateToNow !== false ? now : null;
|
|
13077
13084
|
expirationDate = addMilliseconds(date, expiresIn);
|
|
13078
13085
|
}
|
|
13079
13086
|
return expirationDate;
|
|
@@ -13106,9 +13113,10 @@ function calculateExpirationDate(input) {
|
|
|
13106
13113
|
*/
|
|
13107
13114
|
function isThrottled(throttleTime, lastRunAt, now) {
|
|
13108
13115
|
return !expirationDetails({
|
|
13109
|
-
|
|
13116
|
+
defaultExpiresFromDateToNow: false,
|
|
13117
|
+
expiresFromDate: lastRunAt != null ? lastRunAt : null,
|
|
13110
13118
|
expiresIn: throttleTime
|
|
13111
|
-
}).hasExpired(now);
|
|
13119
|
+
}).hasExpired(now, true);
|
|
13112
13120
|
}
|
|
13113
13121
|
/**
|
|
13114
13122
|
* Returns true if any of the input ExpirationDetails have not expired.
|
package/index.esm.js
CHANGED
|
@@ -14807,6 +14807,7 @@ function expirationDetails(input) {
|
|
|
14807
14807
|
expires,
|
|
14808
14808
|
now: inputNow,
|
|
14809
14809
|
expiresFromDate,
|
|
14810
|
+
defaultExpiresFromDateToNow,
|
|
14810
14811
|
expiresIn
|
|
14811
14812
|
} = input;
|
|
14812
14813
|
const parsedExpiresFromDate = expiresFromDate != null ? dateFromDateOrTimeNumber(expiresFromDate) : null;
|
|
@@ -14815,10 +14816,16 @@ function expirationDetails(input) {
|
|
|
14815
14816
|
const now = (_ref = nowOverride != null ? nowOverride : inputNow) != null ? _ref : new Date();
|
|
14816
14817
|
return now;
|
|
14817
14818
|
}
|
|
14818
|
-
function hasExpired(nowOverride) {
|
|
14819
|
+
function hasExpired(nowOverride, defaultIfNoExpirationDate = false) {
|
|
14819
14820
|
const now = getNow(nowOverride);
|
|
14820
14821
|
const expirationDate = getExpirationDateForNow(now);
|
|
14821
|
-
|
|
14822
|
+
let result;
|
|
14823
|
+
if (expirationDate == null) {
|
|
14824
|
+
result = defaultIfNoExpirationDate;
|
|
14825
|
+
} else {
|
|
14826
|
+
result = expirationDate <= now;
|
|
14827
|
+
}
|
|
14828
|
+
return result;
|
|
14822
14829
|
}
|
|
14823
14830
|
function getExpirationDate(nowOverride) {
|
|
14824
14831
|
const now = getNow(nowOverride);
|
|
@@ -14831,7 +14838,7 @@ function expirationDetails(input) {
|
|
|
14831
14838
|
} else if (expiresAt != null) {
|
|
14832
14839
|
expirationDate = expiresAt;
|
|
14833
14840
|
} else if (expiresIn != null) {
|
|
14834
|
-
const date = parsedExpiresFromDate != null ? parsedExpiresFromDate : now;
|
|
14841
|
+
const date = parsedExpiresFromDate != null ? parsedExpiresFromDate : defaultExpiresFromDateToNow !== false ? now : null;
|
|
14835
14842
|
expirationDate = addMilliseconds(date, expiresIn);
|
|
14836
14843
|
}
|
|
14837
14844
|
return expirationDate;
|
|
@@ -14866,9 +14873,10 @@ function calculateExpirationDate(input) {
|
|
|
14866
14873
|
*/
|
|
14867
14874
|
function isThrottled(throttleTime, lastRunAt, now) {
|
|
14868
14875
|
return !expirationDetails({
|
|
14869
|
-
|
|
14876
|
+
defaultExpiresFromDateToNow: false,
|
|
14877
|
+
expiresFromDate: lastRunAt != null ? lastRunAt : null,
|
|
14870
14878
|
expiresIn: throttleTime
|
|
14871
|
-
}).hasExpired(now);
|
|
14879
|
+
}).hasExpired(now, true);
|
|
14872
14880
|
}
|
|
14873
14881
|
|
|
14874
14882
|
/**
|
package/package.json
CHANGED
|
@@ -25,15 +25,23 @@ export interface ExpirationDetailsInput<T extends Expires = Expires> extends Exp
|
|
|
25
25
|
*/
|
|
26
26
|
expires?: Maybe<T>;
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* Default current now time to use.
|
|
29
|
+
*
|
|
30
|
+
* If not set, functions will use the current time when they are called.
|
|
29
31
|
*/
|
|
30
32
|
now?: Maybe<Date>;
|
|
31
33
|
/**
|
|
32
34
|
* The base date or time number to calculate expirations from.
|
|
33
35
|
*
|
|
34
|
-
* If not
|
|
36
|
+
* If not defined, the expiresFromDate is considered to have never been run/set.
|
|
35
37
|
*/
|
|
36
38
|
expiresFromDate?: Maybe<DateOrUnixDateTimeNumber>;
|
|
39
|
+
/**
|
|
40
|
+
* If true, the "expiresFromDate" will default to the calculated now time when calculating the expiration.
|
|
41
|
+
*
|
|
42
|
+
* Defaults to true.
|
|
43
|
+
*/
|
|
44
|
+
defaultExpiresFromDateToNow?: Maybe<boolean>;
|
|
37
45
|
/**
|
|
38
46
|
* Time after "now" that expiration will occur.
|
|
39
47
|
*/
|
|
@@ -47,15 +55,16 @@ export interface ExpirationDetails<T extends Expires = Expires> {
|
|
|
47
55
|
/**
|
|
48
56
|
* Returns true if the expiration time has passed.
|
|
49
57
|
*
|
|
50
|
-
* @param nowOverride
|
|
58
|
+
* @param nowOverride Optional override for the current time. Defaults to the current time.
|
|
59
|
+
* @param defaultIfNoExpirationDate If true, returns true if no expiration date is defined. Defaults to false.
|
|
51
60
|
*/
|
|
52
|
-
hasExpired(nowOverride?: Maybe<Date
|
|
61
|
+
hasExpired(nowOverride?: Maybe<Date>, defaultIfNoExpirationDate?: boolean): boolean;
|
|
53
62
|
/**
|
|
54
63
|
* Returns the expiration date.
|
|
55
64
|
*
|
|
56
65
|
* Returns null if no expiration is defined.
|
|
57
66
|
*
|
|
58
|
-
* @param nowOverride
|
|
67
|
+
* @param nowOverride Optional override for the current time. Defaults to the current time.
|
|
59
68
|
*/
|
|
60
69
|
getExpirationDate(nowOverride?: Maybe<Date>): Maybe<Date>;
|
|
61
70
|
}
|
package/test/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [11.1.6](https://github.com/dereekb/dbx-components/compare/v11.1.5-dev...v11.1.6) (2025-03-20)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
5
9
|
## [11.1.5](https://github.com/dereekb/dbx-components/compare/v11.1.4-dev...v11.1.5) (2025-03-20)
|
|
6
10
|
|
|
7
11
|
|