@naturalcycles/js-lib 14.246.2 → 14.247.1

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.
@@ -55,6 +55,11 @@ export declare class LocalDate {
55
55
  * Checks if this localDate is same or younger (>=) than "today" by X units.
56
56
  */
57
57
  isSameOrYoungerThan(n: number, unit: LocalDateUnit, today?: LocalDateInput): boolean;
58
+ isToday(): boolean;
59
+ isAfterToday(): boolean;
60
+ isSameOrAfterToday(): boolean;
61
+ isBeforeToday(): boolean;
62
+ isSameOrBeforeToday(): boolean;
58
63
  getAgeInYears(today?: LocalDateInput): number;
59
64
  getAgeInMonths(today?: LocalDateInput): number;
60
65
  getAgeInDays(today?: LocalDateInput): number;
@@ -113,6 +113,21 @@ class LocalDate {
113
113
  isSameOrYoungerThan(n, unit, today) {
114
114
  return this.isSameOrAfter(exports.localDate.fromInput(today || new Date()).plus(-n, unit));
115
115
  }
116
+ isToday() {
117
+ return this.isSame(exports.localDate.today());
118
+ }
119
+ isAfterToday() {
120
+ return this.isAfter(exports.localDate.today());
121
+ }
122
+ isSameOrAfterToday() {
123
+ return this.isSameOrAfter(exports.localDate.today());
124
+ }
125
+ isBeforeToday() {
126
+ return this.isBefore(exports.localDate.today());
127
+ }
128
+ isSameOrBeforeToday() {
129
+ return this.isSameOrBefore(exports.localDate.today());
130
+ }
116
131
  getAgeInYears(today) {
117
132
  return this.getAgeIn('year', today);
118
133
  }
@@ -172,6 +172,8 @@ export declare class LocalTime {
172
172
  getAgeInMinutes(now?: LocalTimeInput): number;
173
173
  getAgeInSeconds(now?: LocalTimeInput): number;
174
174
  getAgeIn(unit: LocalTimeUnit, now?: LocalTimeInput): number;
175
+ isAfterNow(): boolean;
176
+ isBeforeNow(): boolean;
175
177
  /**
176
178
  * Returns 1 if this > d
177
179
  * returns 0 if they are equal
@@ -479,6 +479,12 @@ class LocalTime {
479
479
  getAgeIn(unit, now) {
480
480
  return exports.localTime.fromInput(now ?? new Date()).diff(this, unit);
481
481
  }
482
+ isAfterNow() {
483
+ return this.$date.valueOf() > Date.now();
484
+ }
485
+ isBeforeNow() {
486
+ return this.$date.valueOf() < Date.now();
487
+ }
482
488
  /**
483
489
  * Returns 1 if this > d
484
490
  * returns 0 if they are equal
@@ -15,7 +15,7 @@ function pRetryFn(fn, opt = {}) {
15
15
  async function pRetry(fn, opt = {}) {
16
16
  const { maxAttempts = 4, delay: initialDelay = 1000, delayMultiplier = 2, predicate, logger = console, name, timeout, } = opt;
17
17
  const fakeError = timeout ? new Error('TimeoutError') : undefined;
18
- let { logFirstAttempt = false, logRetries = true, logFailures = false, logSuccess = false } = opt;
18
+ let { logFirstAttempt = false, logRetries = true, logFailures = true, logSuccess = false } = opt;
19
19
  if (opt.logAll) {
20
20
  logSuccess = logFirstAttempt = logRetries = logFailures = true;
21
21
  }
@@ -51,7 +51,7 @@ async function pRetry(fn, opt = {}) {
51
51
  }
52
52
  catch (err) {
53
53
  if (logFailures) {
54
- logger.warn(`${fname} attempt #${attempt} error in ${(0, __1._since)(started)}:`, err);
54
+ logger.error(`${fname} attempt #${attempt} error in ${(0, __1._since)(started)}:`, err);
55
55
  }
56
56
  if (attempt >= maxAttempts || (predicate && !predicate(err, attempt, maxAttempts))) {
57
57
  // Give up
@@ -110,6 +110,21 @@ export class LocalDate {
110
110
  isSameOrYoungerThan(n, unit, today) {
111
111
  return this.isSameOrAfter(localDate.fromInput(today || new Date()).plus(-n, unit));
112
112
  }
113
+ isToday() {
114
+ return this.isSame(localDate.today());
115
+ }
116
+ isAfterToday() {
117
+ return this.isAfter(localDate.today());
118
+ }
119
+ isSameOrAfterToday() {
120
+ return this.isSameOrAfter(localDate.today());
121
+ }
122
+ isBeforeToday() {
123
+ return this.isBefore(localDate.today());
124
+ }
125
+ isSameOrBeforeToday() {
126
+ return this.isSameOrBefore(localDate.today());
127
+ }
113
128
  getAgeInYears(today) {
114
129
  return this.getAgeIn('year', today);
115
130
  }
@@ -476,6 +476,12 @@ export class LocalTime {
476
476
  getAgeIn(unit, now) {
477
477
  return localTime.fromInput(now ?? new Date()).diff(this, unit);
478
478
  }
479
+ isAfterNow() {
480
+ return this.$date.valueOf() > Date.now();
481
+ }
482
+ isBeforeNow() {
483
+ return this.$date.valueOf() < Date.now();
484
+ }
479
485
  /**
480
486
  * Returns 1 if this > d
481
487
  * returns 0 if they are equal
@@ -11,7 +11,7 @@ export function pRetryFn(fn, opt = {}) {
11
11
  export async function pRetry(fn, opt = {}) {
12
12
  const { maxAttempts = 4, delay: initialDelay = 1000, delayMultiplier = 2, predicate, logger = console, name, timeout, } = opt;
13
13
  const fakeError = timeout ? new Error('TimeoutError') : undefined;
14
- let { logFirstAttempt = false, logRetries = true, logFailures = false, logSuccess = false } = opt;
14
+ let { logFirstAttempt = false, logRetries = true, logFailures = true, logSuccess = false } = opt;
15
15
  if (opt.logAll) {
16
16
  logSuccess = logFirstAttempt = logRetries = logFailures = true;
17
17
  }
@@ -47,7 +47,7 @@ export async function pRetry(fn, opt = {}) {
47
47
  }
48
48
  catch (err) {
49
49
  if (logFailures) {
50
- logger.warn(`${fname} attempt #${attempt} error in ${_since(started)}:`, err);
50
+ logger.error(`${fname} attempt #${attempt} error in ${_since(started)}:`, err);
51
51
  }
52
52
  if (attempt >= maxAttempts || (predicate && !predicate(err, attempt, maxAttempts))) {
53
53
  // Give up
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.246.2",
3
+ "version": "14.247.1",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
- "build-prod": "build-prod-esm-cjs",
6
+ "build": "dev-lib build-esm-cjs",
7
+ "test": "dev-lib test",
8
+ "lint": "dev-lib lint",
9
+ "bt": "dev-lib bt",
10
+ "lbt": "dev-lib lbt",
7
11
  "test-tz1": "TZ=Europe/Stockholm yarn test local",
8
12
  "test-tz2": "TZ=JST-9 yarn test local",
9
13
  "test-ny": "TZ=GMT-0500 yarn test localTime",
@@ -17,11 +21,11 @@
17
21
  },
18
22
  "devDependencies": {
19
23
  "@naturalcycles/bench-lib": "^3.0.0",
20
- "@naturalcycles/dev-lib": "^14.0.0",
24
+ "@naturalcycles/dev-lib": "^15.0.3",
21
25
  "@naturalcycles/nodejs-lib": "^13.0.1",
22
26
  "@naturalcycles/time-lib": "^3.5.1",
23
27
  "@types/crypto-js": "^4.1.1",
24
- "@types/node": "^20.1.0",
28
+ "@types/node": "^22.0.0",
25
29
  "@types/semver": "^7.5.8",
26
30
  "crypto-js": "^4.1.1",
27
31
  "jest": "^29.0.0",
@@ -141,6 +141,22 @@ export class LocalDate {
141
141
  return this.isSameOrAfter(localDate.fromInput(today || new Date()).plus(-n, unit))
142
142
  }
143
143
 
144
+ isToday(): boolean {
145
+ return this.isSame(localDate.today())
146
+ }
147
+ isAfterToday(): boolean {
148
+ return this.isAfter(localDate.today())
149
+ }
150
+ isSameOrAfterToday(): boolean {
151
+ return this.isSameOrAfter(localDate.today())
152
+ }
153
+ isBeforeToday(): boolean {
154
+ return this.isBefore(localDate.today())
155
+ }
156
+ isSameOrBeforeToday(): boolean {
157
+ return this.isSameOrBefore(localDate.today())
158
+ }
159
+
144
160
  getAgeInYears(today?: LocalDateInput): number {
145
161
  return this.getAgeIn('year', today)
146
162
  }
@@ -538,6 +538,13 @@ export class LocalTime {
538
538
  return localTime.fromInput(now ?? new Date()).diff(this, unit)
539
539
  }
540
540
 
541
+ isAfterNow(): boolean {
542
+ return this.$date.valueOf() > Date.now()
543
+ }
544
+ isBeforeNow(): boolean {
545
+ return this.$date.valueOf() < Date.now()
546
+ }
547
+
541
548
  /**
542
549
  * Returns 1 if this > d
543
550
  * returns 0 if they are equal
@@ -114,7 +114,7 @@ export async function pRetry<T>(
114
114
  } = opt
115
115
 
116
116
  const fakeError = timeout ? new Error('TimeoutError') : undefined
117
- let { logFirstAttempt = false, logRetries = true, logFailures = false, logSuccess = false } = opt
117
+ let { logFirstAttempt = false, logRetries = true, logFailures = true, logSuccess = false } = opt
118
118
 
119
119
  if (opt.logAll) {
120
120
  logSuccess = logFirstAttempt = logRetries = logFailures = true
@@ -157,7 +157,7 @@ export async function pRetry<T>(
157
157
  return result
158
158
  } catch (err) {
159
159
  if (logFailures) {
160
- logger.warn(`${fname} attempt #${attempt} error in ${_since(started)}:`, err)
160
+ logger.error(`${fname} attempt #${attempt} error in ${_since(started)}:`, err)
161
161
  }
162
162
 
163
163
  if (attempt >= maxAttempts || (predicate && !predicate(err as Error, attempt, maxAttempts))) {