@naturalcycles/js-lib 14.103.0 → 14.104.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.
@@ -179,11 +179,10 @@ export class LocalTime {
179
179
  return v === undefined ? this.get('second') : this.set('second', v);
180
180
  }
181
181
  setComponents(c, mutate = false) {
182
- var _a;
183
182
  const d = mutate ? this.$date : new Date(this.$date);
184
183
  // Year, month and day set all-at-once, to avoid 30/31 (and 28/29) mishap
185
184
  if (c.day || c.month !== undefined || c.year !== undefined) {
186
- d.setFullYear((_a = c.year) !== null && _a !== void 0 ? _a : d.getFullYear(), c.month ? c.month - 1 : d.getMonth(), c.day || d.getDate());
185
+ d.setFullYear(c.year ?? d.getFullYear(), c.month ? c.month - 1 : d.getMonth(), c.day || d.getDate());
187
186
  }
188
187
  if (c.hour !== undefined) {
189
188
  d.setHours(c.hour);
@@ -19,7 +19,6 @@ export function _createPromiseDecorator(cfg, decoratorParams = {}) {
19
19
  const key = String(propertyKey);
20
20
  const methodSignature = _getTargetMethodSignature(target, key);
21
21
  pd.value = async function (...args) {
22
- var _a, _b;
23
22
  // console.log(`@${cfg.decoratorName} called inside function`)
24
23
  const started = Date.now();
25
24
  try {
@@ -47,9 +46,12 @@ export function _createPromiseDecorator(cfg, decoratorParams = {}) {
47
46
  started,
48
47
  };
49
48
  if (cfg.thenFn) {
50
- res = cfg.thenFn(Object.assign(Object.assign({}, resp), { res }));
49
+ res = cfg.thenFn({
50
+ ...resp,
51
+ res,
52
+ });
51
53
  }
52
- (_a = cfg.finallyFn) === null || _a === void 0 ? void 0 : _a.call(cfg, resp);
54
+ cfg.finallyFn?.(resp);
53
55
  return res;
54
56
  }
55
57
  catch (err) {
@@ -64,10 +66,13 @@ export function _createPromiseDecorator(cfg, decoratorParams = {}) {
64
66
  };
65
67
  let handled = false;
66
68
  if (cfg.catchFn) {
67
- cfg.catchFn(Object.assign(Object.assign({}, resp), { err }));
69
+ cfg.catchFn({
70
+ ...resp,
71
+ err,
72
+ });
68
73
  handled = true;
69
74
  }
70
- (_b = cfg.finallyFn) === null || _b === void 0 ? void 0 : _b.call(cfg, resp);
75
+ cfg.finallyFn?.(resp);
71
76
  if (!handled) {
72
77
  throw err; // rethrow
73
78
  }
@@ -105,5 +105,10 @@ export function _debounce(func, wait, opt = {}) {
105
105
  return debounced;
106
106
  }
107
107
  export function _throttle(func, wait, opt = {}) {
108
- return _debounce(func, wait, Object.assign(Object.assign({ leading: true, trailing: true }, opt), { maxWait: wait }));
108
+ return _debounce(func, wait, {
109
+ leading: true,
110
+ trailing: true,
111
+ ...opt,
112
+ maxWait: wait,
113
+ });
109
114
  }
@@ -18,7 +18,10 @@ import { AppError } from './app.error';
18
18
  export function _assert(condition, // will be evaluated as Boolean
19
19
  message, errorData) {
20
20
  if (!condition) {
21
- throw new AssertionError(message || 'see stacktrace', Object.assign({ userFriendly: true }, errorData));
21
+ throw new AssertionError(message || 'see stacktrace', {
22
+ userFriendly: true,
23
+ ...errorData,
24
+ });
22
25
  }
23
26
  }
24
27
  /**
@@ -36,7 +39,10 @@ export function _assertEquals(actual, expected, message, errorData) {
36
39
  ]
37
40
  .filter(Boolean)
38
41
  .join('\n');
39
- throw new AssertionError(msg, Object.assign({ userFriendly: true }, errorData));
42
+ throw new AssertionError(msg, {
43
+ userFriendly: true,
44
+ ...errorData,
45
+ });
40
46
  }
41
47
  }
42
48
  /**
@@ -54,7 +60,10 @@ export function _assertDeepEquals(actual, expected, message, errorData) {
54
60
  ]
55
61
  .filter(Boolean)
56
62
  .join('\n');
57
- throw new AssertionError(msg, Object.assign({ userFriendly: true }, errorData));
63
+ throw new AssertionError(msg, {
64
+ userFriendly: true,
65
+ ...errorData,
66
+ });
58
67
  }
59
68
  }
60
69
  export function _assertIsError(err, message) {
@@ -21,9 +21,8 @@ export function _anyToError(o, errorClass = Error, opt) {
21
21
  * Objects (not Errors) get converted to prettified JSON string (via `_stringifyAny`).
22
22
  */
23
23
  export function _anyToErrorObject(o, opt) {
24
- var _a;
25
24
  if (o instanceof Error) {
26
- return _errorToErrorObject(o, (_a = opt === null || opt === void 0 ? void 0 : opt.includeErrorStack) !== null && _a !== void 0 ? _a : true);
25
+ return _errorToErrorObject(o, opt?.includeErrorStack ?? true);
27
26
  }
28
27
  o = _jsonParseIfPossible(o);
29
28
  if (_isHttpErrorResponse(o)) {
@@ -36,7 +35,10 @@ export function _anyToErrorObject(o, opt) {
36
35
  // so, fair to return `data: {}` in the end
37
36
  // Also we're sure it includes no "error name", e.g no `Error: ...`,
38
37
  // so, fair to include `name: 'Error'`
39
- const message = _stringifyAny(o, Object.assign({ includeErrorData: true }, opt));
38
+ const message = _stringifyAny(o, {
39
+ includeErrorData: true,
40
+ ...opt,
41
+ });
40
42
  return {
41
43
  name: 'Error',
42
44
  message,
@@ -47,7 +49,7 @@ export function _errorToErrorObject(e, includeErrorStack = true) {
47
49
  const obj = {
48
50
  name: e.name,
49
51
  message: e.message,
50
- data: Object.assign({}, e.data), // empty by default
52
+ data: { ...e.data }, // empty by default
51
53
  };
52
54
  if (includeErrorStack) {
53
55
  obj.stack = e.stack;
@@ -81,14 +83,13 @@ export function _errorObjectToError(o, errorClass = Error) {
81
83
  return err;
82
84
  }
83
85
  export function _isHttpErrorResponse(o) {
84
- return _isHttpErrorObject(o === null || o === void 0 ? void 0 : o.error);
86
+ return _isHttpErrorObject(o?.error);
85
87
  }
86
88
  export function _isHttpErrorObject(o) {
87
- var _a;
88
89
  return (!!o &&
89
90
  typeof o.name === 'string' &&
90
91
  typeof o.message === 'string' &&
91
- typeof ((_a = o.data) === null || _a === void 0 ? void 0 : _a.httpStatusCode) === 'number');
92
+ typeof o.data?.httpStatusCode === 'number');
92
93
  }
93
94
  /**
94
95
  * Note: any instance of AppError is also automatically an ErrorObject
@@ -29,7 +29,7 @@ export function _tryCatch(fn, opt = {}) {
29
29
  try {
30
30
  return await onError(_anyToError(err)); // eslint-disable-line @typescript-eslint/return-await
31
31
  }
32
- catch (_a) { }
32
+ catch { }
33
33
  }
34
34
  // returns undefined, but doesn't rethrow
35
35
  }
@@ -6,7 +6,6 @@ import { _filterNullishValues } from '../object/object.util';
6
6
  * API similar to Object.assign(s1, s2)
7
7
  */
8
8
  export function mergeJsonSchemaObjects(s1, s2) {
9
- var _a, _b;
10
9
  // Merge `properties`
11
10
  Object.entries(s2.properties).forEach(([k, v]) => {
12
11
  ;
@@ -18,8 +17,8 @@ export function mergeJsonSchemaObjects(s1, s2) {
18
17
  s1.patternProperties[k] = v;
19
18
  });
20
19
  s1.propertyNames = s2.propertyNames || s1.propertyNames;
21
- s1.minProperties = (_a = s2.minProperties) !== null && _a !== void 0 ? _a : s1.minProperties;
22
- s1.maxProperties = (_b = s2.maxProperties) !== null && _b !== void 0 ? _b : s1.maxProperties;
20
+ s1.minProperties = s2.minProperties ?? s1.minProperties;
21
+ s1.maxProperties = s2.maxProperties ?? s1.maxProperties;
23
22
  // Merge `required`
24
23
  s1.required.push(...s2.required);
25
24
  s1.required = _uniq(s1.required).sort();
@@ -250,12 +250,11 @@ export class JsonSchemaStringBuilder extends JsonSchemaAnyBuilder {
250
250
  return this;
251
251
  }
252
252
  transformModify(t, add) {
253
- var _a;
254
253
  if (add) {
255
254
  this.schema.transform = _uniq([...(this.schema.transform || []), t]);
256
255
  }
257
256
  else {
258
- this.schema.transform = (_a = this.schema.transform) === null || _a === void 0 ? void 0 : _a.filter(s => s !== t);
257
+ this.schema.transform = this.schema.transform?.filter(s => s !== t);
259
258
  }
260
259
  return this;
261
260
  }
@@ -14,7 +14,7 @@ export function _average(values) {
14
14
  * Same as _average, but safely returns null if input array is empty or nullish.
15
15
  */
16
16
  export function _averageOrNull(values) {
17
- return (values === null || values === void 0 ? void 0 : values.length) ? values.reduce((a, b) => a + b) / values.length : null;
17
+ return values?.length ? values.reduce((a, b) => a + b) / values.length : null;
18
18
  }
19
19
  /**
20
20
  * valuesArray and weightsArray length is expected to be the same.
@@ -29,7 +29,7 @@ export function _omit(obj, props, mutate = false) {
29
29
  return props.reduce((r, prop) => {
30
30
  delete r[prop];
31
31
  return r;
32
- }, mutate ? obj : Object.assign({}, obj));
32
+ }, mutate ? obj : { ...obj });
33
33
  }
34
34
  /**
35
35
  * Returns object with filtered keys from `props` array.
@@ -76,7 +76,7 @@ export function _filterObject(obj, predicate, mutate = false) {
76
76
  if (!predicate(k, r[k], obj))
77
77
  delete r[k];
78
78
  return r;
79
- }, mutate ? obj : Object.assign({}, obj));
79
+ }, mutate ? obj : { ...obj });
80
80
  }
81
81
  /**
82
82
  * var users = {
@@ -137,8 +137,7 @@ export function _mapObject(obj, mapper) {
137
137
  }, {});
138
138
  }
139
139
  export function _findKeyByValue(obj, v) {
140
- var _a;
141
- return (_a = Object.entries(obj).find(([_, value]) => value === v)) === null || _a === void 0 ? void 0 : _a[0];
140
+ return Object.entries(obj).find(([_, value]) => value === v)?.[0];
142
141
  }
143
142
  export function _objectNullValuesToUndefined(obj, mutate = false) {
144
143
  return _mapValues(obj, (_k, v) => (v === null ? undefined : v), mutate);
@@ -6,7 +6,6 @@ Improvements:
6
6
  - Included Typescript typings (no need for @types/p-map)
7
7
  - Compatible with pProps (that had typings issues)
8
8
  */
9
- import { __asyncValues } from "tslib";
10
9
  import { END, ErrorMode, SKIP } from '..';
11
10
  import { AggregatedError } from './AggregatedError';
12
11
  /**
@@ -36,7 +35,6 @@ import { AggregatedError } from './AggregatedError';
36
35
  * })();
37
36
  */
38
37
  export async function pMap(iterable, mapper, opt = {}) {
39
- var e_1, _a;
40
38
  const ret = [];
41
39
  // const iterator = iterable[Symbol.iterator]()
42
40
  const items = [...iterable];
@@ -50,33 +48,23 @@ export async function pMap(iterable, mapper, opt = {}) {
50
48
  let currentIndex = 0;
51
49
  // Special cases that are able to preserve async stack traces
52
50
  if (concurrency === 1) {
53
- try {
54
- // Special case for concurrency == 1
55
- for (var items_1 = __asyncValues(items), items_1_1; items_1_1 = await items_1.next(), !items_1_1.done;) {
56
- const item = items_1_1.value;
57
- try {
58
- const r = await mapper(item, currentIndex++);
59
- if (r === END)
60
- break;
61
- if (r !== SKIP)
62
- ret.push(r);
63
- }
64
- catch (err) {
65
- if (errorMode === ErrorMode.THROW_IMMEDIATELY)
66
- throw err;
67
- if (errorMode === ErrorMode.THROW_AGGREGATED) {
68
- errors.push(err);
69
- }
70
- // otherwise, suppress completely
71
- }
72
- }
73
- }
74
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
75
- finally {
51
+ // Special case for concurrency == 1
52
+ for await (const item of items) {
76
53
  try {
77
- if (items_1_1 && !items_1_1.done && (_a = items_1.return)) await _a.call(items_1);
54
+ const r = await mapper(item, currentIndex++);
55
+ if (r === END)
56
+ break;
57
+ if (r !== SKIP)
58
+ ret.push(r);
59
+ }
60
+ catch (err) {
61
+ if (errorMode === ErrorMode.THROW_IMMEDIATELY)
62
+ throw err;
63
+ if (errorMode === ErrorMode.THROW_AGGREGATED) {
64
+ errors.push(err);
65
+ }
66
+ // otherwise, suppress completely
78
67
  }
79
- finally { if (e_1) throw e_1.error; }
80
68
  }
81
69
  if (errors.length) {
82
70
  throw new AggregatedError(errors, ret);
@@ -13,9 +13,14 @@ export class PQueue {
13
13
  this.inFlight = 0;
14
14
  this.queue = [];
15
15
  this.onIdleListeners = [];
16
- this.cfg = Object.assign({
16
+ this.cfg = {
17
17
  // concurrency: Number.MAX_SAFE_INTEGER,
18
- errorMode: ErrorMode.THROW_IMMEDIATELY, logger: console, debug: false, resolveOn: 'finish' }, cfg);
18
+ errorMode: ErrorMode.THROW_IMMEDIATELY,
19
+ logger: console,
20
+ debug: false,
21
+ resolveOn: 'finish',
22
+ ...cfg,
23
+ };
19
24
  if (!cfg.debug) {
20
25
  this.debug = () => { };
21
26
  }
@@ -72,7 +72,10 @@ export async function pRetry(fn, opt = {}) {
72
72
  });
73
73
  }
74
74
  ;
75
- err.data = Object.assign(Object.assign({}, err.data), opt.errorData);
75
+ err.data = {
76
+ ...err.data,
77
+ ...opt.errorData,
78
+ };
76
79
  reject(err);
77
80
  }
78
81
  else {
@@ -32,7 +32,10 @@ export async function pTimeout(promise, opt) {
32
32
  catch (err) {
33
33
  if (fakeError)
34
34
  err.stack = fakeError.stack; // keep original stack
35
- err.data = Object.assign(Object.assign({}, err.data), opt.errorData);
35
+ err.data = {
36
+ ...err.data,
37
+ ...opt.errorData,
38
+ };
36
39
  reject(err);
37
40
  }
38
41
  return;
@@ -10,7 +10,7 @@ export function _jsonParseIfPossible(obj, reviver) {
10
10
  try {
11
11
  return JSON.parse(obj, reviver);
12
12
  }
13
- catch (_a) { }
13
+ catch { }
14
14
  }
15
15
  return obj;
16
16
  }
@@ -8,7 +8,7 @@ export function _safeJsonStringify(obj, replacer, spaces, cycleReplacer) {
8
8
  // Try native first (as it's ~3 times faster)
9
9
  return JSON.stringify(obj, replacer, spaces);
10
10
  }
11
- catch (_a) {
11
+ catch {
12
12
  // Native failed - resort to the "safe" serializer
13
13
  return JSON.stringify(obj, serializer(replacer, cycleReplacer), spaces);
14
14
  }
@@ -85,7 +85,7 @@ export function _stringifyAny(obj, opt = {}) {
85
85
  const { stringifyFn = _safeJsonStringify } = opt;
86
86
  s = stringifyFn(obj, undefined, 2);
87
87
  }
88
- catch (_a) {
88
+ catch {
89
89
  s = String(obj); // fallback
90
90
  }
91
91
  }
@@ -138,15 +138,15 @@ is.array = (value, assertion) => {
138
138
  }
139
139
  return value.every(assertion);
140
140
  };
141
- is.buffer = (value) => { var _a, _b, _c; return (_c = (_b = (_a = value === null || value === void 0 ? void 0 : value.constructor) === null || _a === void 0 ? void 0 : _a.isBuffer) === null || _b === void 0 ? void 0 : _b.call(_a, value)) !== null && _c !== void 0 ? _c : false; };
141
+ is.buffer = (value) => value?.constructor?.isBuffer?.(value) ?? false;
142
142
  is.nullOrUndefined = (value) => is.null_(value) || is.undefined(value);
143
143
  is.object = (value) => !is.null_(value) && (typeof value === 'object' || is.function_(value));
144
- is.iterable = (value) => is.function_(value === null || value === void 0 ? void 0 : value[Symbol.iterator]);
145
- is.asyncIterable = (value) => is.function_(value === null || value === void 0 ? void 0 : value[Symbol.asyncIterator]);
144
+ is.iterable = (value) => is.function_(value?.[Symbol.iterator]);
145
+ is.asyncIterable = (value) => is.function_(value?.[Symbol.asyncIterator]);
146
146
  is.generator = (value) => is.iterable(value) && is.function_(value.next) && is.function_(value.throw);
147
147
  is.asyncGenerator = (value) => is.asyncIterable(value) && is.function_(value.next) && is.function_(value.throw);
148
148
  is.nativePromise = (value) => isObjectOfType('Promise')(value);
149
- const hasPromiseAPI = (value) => is.function_(value === null || value === void 0 ? void 0 : value.then) && is.function_(value === null || value === void 0 ? void 0 : value.catch);
149
+ const hasPromiseAPI = (value) => is.function_(value?.then) && is.function_(value?.catch);
150
150
  is.promise = (value) => is.nativePromise(value) || hasPromiseAPI(value);
151
151
  is.generatorFunction = isObjectOfType('GeneratorFunction');
152
152
  is.asyncGeneratorFunction = (value) => getObjectType(value) === 'AsyncGeneratorFunction';
@@ -184,7 +184,7 @@ is.urlString = (value) => {
184
184
  new URL(value); // eslint-disable-line no-new
185
185
  return true;
186
186
  }
187
- catch (_a) {
187
+ catch {
188
188
  return false;
189
189
  }
190
190
  };
@@ -235,14 +235,13 @@ is.domElement = (value) => {
235
235
  DOM_PROPERTIES_TO_CHECK.every(property => property in value));
236
236
  };
237
237
  is.observable = (value) => {
238
- var _a, _b, _c, _d;
239
238
  if (!value) {
240
239
  return false;
241
240
  }
242
- if (value === ((_b = (_a = value)[Symbol.observable]) === null || _b === void 0 ? void 0 : _b.call(_a))) {
241
+ if (value === value[Symbol.observable]?.()) {
243
242
  return true;
244
243
  }
245
- if (value === ((_d = (_c = value)['@@observable']) === null || _d === void 0 ? void 0 : _d.call(_c))) {
244
+ if (value === value['@@observable']?.()) {
246
245
  return true;
247
246
  }
248
247
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.103.0",
3
+ "version": "14.104.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",