@naturalcycles/js-lib 14.226.0 → 14.228.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.
@@ -94,15 +94,7 @@ export declare class LocalDate {
94
94
  */
95
95
  diff(d: LocalDateInput, unit: LocalDateUnit): number;
96
96
  plus(num: number, unit: LocalDateUnit, mutate?: boolean): LocalDate;
97
- /**
98
- * @deprecated use `minus` instead
99
- */
100
- subtract(num: number, unit: LocalDateUnit, mutate?: boolean): LocalDate;
101
97
  minus(num: number, unit: LocalDateUnit, mutate?: boolean): LocalDate;
102
- /**
103
- * @deprecated use `plus` instead
104
- */
105
- add(num: number, unit: LocalDateUnit, mutate?: boolean): LocalDate;
106
98
  startOf(unit: LocalDateUnitStrict): LocalDate;
107
99
  endOf(unit: LocalDateUnitStrict): LocalDate;
108
100
  static getYearLength(year: number): number;
@@ -342,21 +342,9 @@ class LocalDate {
342
342
  }
343
343
  return new LocalDate($year, $month, $day);
344
344
  }
345
- /**
346
- * @deprecated use `minus` instead
347
- */
348
- subtract(num, unit, mutate = false) {
349
- return this.plus(-num, unit, mutate);
350
- }
351
345
  minus(num, unit, mutate = false) {
352
346
  return this.plus(-num, unit, mutate);
353
347
  }
354
- /**
355
- * @deprecated use `plus` instead
356
- */
357
- add(num, unit, mutate = false) {
358
- return this.plus(num, unit, mutate);
359
- }
360
348
  startOf(unit) {
361
349
  if (unit === 'day')
362
350
  return this;
@@ -70,15 +70,7 @@ export declare class LocalTime {
70
70
  second(v: number): LocalTime;
71
71
  setComponents(c: Partial<LocalTimeComponents>, mutate?: boolean): LocalTime;
72
72
  plus(num: number, unit: LocalTimeUnit, mutate?: boolean): LocalTime;
73
- /**
74
- * @deprecated use `minus` instead
75
- */
76
- subtract(num: number, unit: LocalTimeUnit, mutate?: boolean): LocalTime;
77
73
  minus(num: number, unit: LocalTimeUnit, mutate?: boolean): LocalTime;
78
- /**
79
- * @deprecated use `plus` instead
80
- */
81
- add(num: number, unit: LocalTimeUnit, mutate?: boolean): LocalTime;
82
74
  absDiff(other: LocalTimeInput, unit: LocalTimeUnit): number;
83
75
  diff(other: LocalTimeInput, unit: LocalTimeUnit): number;
84
76
  startOf(unit: LocalTimeUnit, mutate?: boolean): LocalTime;
@@ -211,21 +211,9 @@ class LocalTime {
211
211
  }
212
212
  return this.set(unit, this.get(unit) + num, mutate);
213
213
  }
214
- /**
215
- * @deprecated use `minus` instead
216
- */
217
- subtract(num, unit, mutate = false) {
218
- return this.plus(num * -1, unit, mutate);
219
- }
220
214
  minus(num, unit, mutate = false) {
221
215
  return this.plus(num * -1, unit, mutate);
222
216
  }
223
- /**
224
- * @deprecated use `plus` instead
225
- */
226
- add(num, unit, mutate = false) {
227
- return this.plus(num, unit, mutate);
228
- }
229
217
  absDiff(other, unit) {
230
218
  return Math.abs(this.diff(other, unit));
231
219
  }
@@ -8,6 +8,8 @@ const decorator_util_1 = require("./decorator.util");
8
8
  function _Timeout(opt) {
9
9
  return (target, key, descriptor) => {
10
10
  (0, assert_1._assert)(typeof descriptor.value === 'function', '@_Timeout can be applied only to methods');
11
+ if (!opt.timeout)
12
+ return descriptor;
11
13
  const originalFn = descriptor.value;
12
14
  const keyStr = String(key);
13
15
  descriptor.value = async function (...args) {
@@ -25,7 +25,6 @@ async function pRetry(fn, opt = {}) {
25
25
  const fname = name || fn.name || 'pRetry function';
26
26
  let delay = initialDelay;
27
27
  let attempt = 0;
28
- /* eslint-disable no-constant-condition */
29
28
  while (true) {
30
29
  const started = Date.now();
31
30
  try {
@@ -4,6 +4,8 @@ import type { AnyAsyncFunction, NumberOfMilliseconds } from '../types';
4
4
  export interface PTimeoutOptions {
5
5
  /**
6
6
  * Timeout in milliseconds.
7
+ *
8
+ * If 0 is passed - the function would be executed right away, with no timeout.
7
9
  */
8
10
  timeout: NumberOfMilliseconds;
9
11
  /**
@@ -11,6 +11,9 @@ const error_util_1 = require("../error/error.util");
11
11
  */
12
12
  function pTimeoutFn(fn, opt) {
13
13
  opt.name ||= fn.name;
14
+ if (!opt.timeout) {
15
+ return fn;
16
+ }
14
17
  return async function pTimeoutInternalFn(...args) {
15
18
  return await pTimeout(() => fn.apply(this, args), opt);
16
19
  };
@@ -23,6 +26,10 @@ exports.pTimeoutFn = pTimeoutFn;
23
26
  * If the Function rejects - passes this rejection further.
24
27
  */
25
28
  async function pTimeout(fn, opt) {
29
+ if (!opt.timeout) {
30
+ // short-circuit to direct execution if 0 timeout is passed
31
+ return await fn();
32
+ }
26
33
  const { timeout, name = fn.name || 'pTimeout function', onTimeout } = opt;
27
34
  const fakeError = opt.fakeError || new Error('TimeoutError');
28
35
  // eslint-disable-next-line no-async-promise-executor
@@ -65,7 +65,3 @@ export interface StringifyOptions {
65
65
  * Returns 'undefined' if undefined is passed (default util.inspect behavior).
66
66
  */
67
67
  export declare function _stringify(obj: any, opt?: StringifyOptions): string;
68
- /**
69
- * @deprecated renamed to _stringify
70
- */
71
- export declare const _stringifyAny: typeof _stringify;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._stringifyAny = exports._stringify = exports.setGlobalStringifyFunction = void 0;
3
+ exports._stringify = exports.setGlobalStringifyFunction = void 0;
4
4
  const error_util_1 = require("../error/error.util");
5
5
  const json_util_1 = require("./json.util");
6
6
  const safeJsonStringify_1 = require("./safeJsonStringify");
@@ -136,7 +136,3 @@ function _stringify(obj, opt = {}) {
136
136
  return s;
137
137
  }
138
138
  exports._stringify = _stringify;
139
- /**
140
- * @deprecated renamed to _stringify
141
- */
142
- exports._stringifyAny = _stringify;
@@ -339,21 +339,9 @@ export class LocalDate {
339
339
  }
340
340
  return new LocalDate($year, $month, $day);
341
341
  }
342
- /**
343
- * @deprecated use `minus` instead
344
- */
345
- subtract(num, unit, mutate = false) {
346
- return this.plus(-num, unit, mutate);
347
- }
348
342
  minus(num, unit, mutate = false) {
349
343
  return this.plus(-num, unit, mutate);
350
344
  }
351
- /**
352
- * @deprecated use `plus` instead
353
- */
354
- add(num, unit, mutate = false) {
355
- return this.plus(num, unit, mutate);
356
- }
357
345
  startOf(unit) {
358
346
  if (unit === 'day')
359
347
  return this;
@@ -209,21 +209,9 @@ export class LocalTime {
209
209
  }
210
210
  return this.set(unit, this.get(unit) + num, mutate);
211
211
  }
212
- /**
213
- * @deprecated use `minus` instead
214
- */
215
- subtract(num, unit, mutate = false) {
216
- return this.plus(num * -1, unit, mutate);
217
- }
218
212
  minus(num, unit, mutate = false) {
219
213
  return this.plus(num * -1, unit, mutate);
220
214
  }
221
- /**
222
- * @deprecated use `plus` instead
223
- */
224
- add(num, unit, mutate = false) {
225
- return this.plus(num, unit, mutate);
226
- }
227
215
  absDiff(other, unit) {
228
216
  return Math.abs(this.diff(other, unit));
229
217
  }
@@ -5,6 +5,8 @@ import { _getMethodSignature } from './decorator.util';
5
5
  export function _Timeout(opt) {
6
6
  return (target, key, descriptor) => {
7
7
  _assert(typeof descriptor.value === 'function', '@_Timeout can be applied only to methods');
8
+ if (!opt.timeout)
9
+ return descriptor;
8
10
  const originalFn = descriptor.value;
9
11
  const keyStr = String(key);
10
12
  descriptor.value = async function (...args) {
@@ -21,7 +21,6 @@ export async function pRetry(fn, opt = {}) {
21
21
  const fname = name || fn.name || 'pRetry function';
22
22
  let delay = initialDelay;
23
23
  let attempt = 0;
24
- /* eslint-disable no-constant-condition */
25
24
  while (true) {
26
25
  const started = Date.now();
27
26
  try {
@@ -8,6 +8,9 @@ import { _errorDataAppend, TimeoutError } from '../error/error.util';
8
8
  */
9
9
  export function pTimeoutFn(fn, opt) {
10
10
  opt.name || (opt.name = fn.name);
11
+ if (!opt.timeout) {
12
+ return fn;
13
+ }
11
14
  return async function pTimeoutInternalFn(...args) {
12
15
  return await pTimeout(() => fn.apply(this, args), opt);
13
16
  };
@@ -19,6 +22,10 @@ export function pTimeoutFn(fn, opt) {
19
22
  * If the Function rejects - passes this rejection further.
20
23
  */
21
24
  export async function pTimeout(fn, opt) {
25
+ if (!opt.timeout) {
26
+ // short-circuit to direct execution if 0 timeout is passed
27
+ return await fn();
28
+ }
22
29
  const { timeout, name = fn.name || 'pTimeout function', onTimeout } = opt;
23
30
  const fakeError = opt.fakeError || new Error('TimeoutError');
24
31
  // eslint-disable-next-line no-async-promise-executor
@@ -131,7 +131,3 @@ export function _stringify(obj, opt = {}) {
131
131
  }
132
132
  return s;
133
133
  }
134
- /**
135
- * @deprecated renamed to _stringify
136
- */
137
- export const _stringifyAny = _stringify;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.226.0",
3
+ "version": "14.228.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -415,24 +415,10 @@ export class LocalDate {
415
415
  return new LocalDate($year, $month, $day)
416
416
  }
417
417
 
418
- /**
419
- * @deprecated use `minus` instead
420
- */
421
- subtract(num: number, unit: LocalDateUnit, mutate = false): LocalDate {
422
- return this.plus(-num, unit, mutate)
423
- }
424
-
425
418
  minus(num: number, unit: LocalDateUnit, mutate = false): LocalDate {
426
419
  return this.plus(-num, unit, mutate)
427
420
  }
428
421
 
429
- /**
430
- * @deprecated use `plus` instead
431
- */
432
- add(num: number, unit: LocalDateUnit, mutate = false): LocalDate {
433
- return this.plus(num, unit, mutate)
434
- }
435
-
436
422
  startOf(unit: LocalDateUnitStrict): LocalDate {
437
423
  if (unit === 'day') return this
438
424
  if (unit === 'month') return LocalDate.create(this.$year, this.$month, 1)
@@ -281,24 +281,10 @@ export class LocalTime {
281
281
  return this.set(unit, this.get(unit) + num, mutate)
282
282
  }
283
283
 
284
- /**
285
- * @deprecated use `minus` instead
286
- */
287
- subtract(num: number, unit: LocalTimeUnit, mutate = false): LocalTime {
288
- return this.plus(num * -1, unit, mutate)
289
- }
290
-
291
284
  minus(num: number, unit: LocalTimeUnit, mutate = false): LocalTime {
292
285
  return this.plus(num * -1, unit, mutate)
293
286
  }
294
287
 
295
- /**
296
- * @deprecated use `plus` instead
297
- */
298
- add(num: number, unit: LocalTimeUnit, mutate = false): LocalTime {
299
- return this.plus(num, unit, mutate)
300
- }
301
-
302
288
  absDiff(other: LocalTimeInput, unit: LocalTimeUnit): number {
303
289
  return Math.abs(this.diff(other, unit))
304
290
  }
@@ -8,6 +8,8 @@ export function _Timeout(opt: PTimeoutOptions): MethodDecorator {
8
8
  return (target, key, descriptor) => {
9
9
  _assert(typeof descriptor.value === 'function', '@_Timeout can be applied only to methods')
10
10
 
11
+ if (!opt.timeout) return descriptor
12
+
11
13
  const originalFn = descriptor.value
12
14
  const keyStr = String(key)
13
15
 
@@ -128,7 +128,6 @@ export async function pRetry<T>(
128
128
  let delay = initialDelay
129
129
  let attempt = 0
130
130
 
131
- /* eslint-disable no-constant-condition */
132
131
  while (true) {
133
132
  const started = Date.now()
134
133
 
@@ -5,6 +5,8 @@ import type { AnyAsyncFunction, NumberOfMilliseconds } from '../types'
5
5
  export interface PTimeoutOptions {
6
6
  /**
7
7
  * Timeout in milliseconds.
8
+ *
9
+ * If 0 is passed - the function would be executed right away, with no timeout.
8
10
  */
9
11
  timeout: NumberOfMilliseconds
10
12
 
@@ -46,6 +48,10 @@ export interface PTimeoutOptions {
46
48
  export function pTimeoutFn<T extends AnyAsyncFunction>(fn: T, opt: PTimeoutOptions): T {
47
49
  opt.name ||= fn.name
48
50
 
51
+ if (!opt.timeout) {
52
+ return fn
53
+ }
54
+
49
55
  return async function pTimeoutInternalFn(this: any, ...args: any[]) {
50
56
  return await pTimeout(() => fn.apply(this, args), opt)
51
57
  } as T
@@ -58,6 +64,11 @@ export function pTimeoutFn<T extends AnyAsyncFunction>(fn: T, opt: PTimeoutOptio
58
64
  * If the Function rejects - passes this rejection further.
59
65
  */
60
66
  export async function pTimeout<T>(fn: AnyAsyncFunction<T>, opt: PTimeoutOptions): Promise<T> {
67
+ if (!opt.timeout) {
68
+ // short-circuit to direct execution if 0 timeout is passed
69
+ return await fn()
70
+ }
71
+
61
72
  const { timeout, name = fn.name || 'pTimeout function', onTimeout } = opt
62
73
  const fakeError = opt.fakeError || new Error('TimeoutError')
63
74
 
@@ -184,8 +184,3 @@ export function _stringify(obj: any, opt: StringifyOptions = {}): string {
184
184
 
185
185
  return s
186
186
  }
187
-
188
- /**
189
- * @deprecated renamed to _stringify
190
- */
191
- export const _stringifyAny = _stringify