@naturalcycles/js-lib 15.55.0 → 15.56.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.
@@ -1,6 +1,6 @@
1
1
  // Modified version of topbar:
2
2
  // http://buunguyen.github.io/topbar
3
- /* eslint-disable */
3
+ // oxlint-disable
4
4
  const browser = typeof window !== 'undefined';
5
5
  let canvas;
6
6
  let progressTimerId;
@@ -24,7 +24,7 @@ export const _AsyncMemo = (opt) => (target, key, descriptor) => {
24
24
  const { logger = console, cacheFactory, cacheKeyFn = jsonMemoSerializer } = opt;
25
25
  const keyStr = String(key);
26
26
  const methodSignature = _getTargetMethodSignature(target, keyStr);
27
- // eslint-disable-next-line @typescript-eslint/promise-function-async
27
+ // oxlint-disable-next-line @typescript-eslint/promise-function-async
28
28
  descriptor.value = function (...args) {
29
29
  const ctx = this;
30
30
  const cacheKey = cacheKeyFn(args);
@@ -17,7 +17,7 @@ export const _SwarmSafe = () => (target, key, descriptor) => {
17
17
  const methodSignature = _getTargetMethodSignature(target, keyStr);
18
18
  const instanceCache = new Map();
19
19
  console.log('SwarmSafe constructor called', { key, methodSignature });
20
- // eslint-disable-next-line @typescript-eslint/promise-function-async
20
+ // oxlint-disable-next-line @typescript-eslint/promise-function-async
21
21
  descriptor.value = function (...args) {
22
22
  console.log('SwarmSafe method called', { key, methodSignature, args });
23
23
  const ctx = this;
@@ -9,6 +9,7 @@ import { _clamp } from '../number/number.util.js';
9
9
  import { _filterFalsyValues, _filterNullishValues, _filterUndefinedValues, _mapKeys, _merge, _omit, _pick, } from '../object/object.util.js';
10
10
  import { pDelay } from '../promise/pDelay.js';
11
11
  import { pTimeout } from '../promise/pTimeout.js';
12
+ import { _toUrlOrNull } from '../string/index.js';
12
13
  import { _jsonParse, _jsonParseIfPossible } from '../string/json.util.js';
13
14
  import { _stringify } from '../string/stringify.js';
14
15
  import { HTTP_METHODS } from './http.model.js';
@@ -630,7 +631,7 @@ export class Fetcher {
630
631
  let { name } = cfg;
631
632
  if (!name && cfg.baseUrl) {
632
633
  // derive FetcherName from baseUrl
633
- const url = URL.parse(cfg.baseUrl);
634
+ const url = _toUrlOrNull(cfg.baseUrl);
634
635
  if (url) {
635
636
  name = url.hostname;
636
637
  }
@@ -1,4 +1,4 @@
1
- import type { AnyObject, KeyValueTuple, MutateOptions, ObjectMapper, ObjectPredicate, Reviver, StringMap, ValueOf } from '../types.js';
1
+ import type { AnyObject, KeyValueTuple, MutateOptions, ObjectMapper, ObjectPredicate, RequiredProp, Reviver, StringMap, ValueOf } from '../types.js';
2
2
  import { SKIP } from '../types.js';
3
3
  /**
4
4
  * Returns clone of `obj` with only `props` preserved.
@@ -228,4 +228,13 @@ export declare function _deepFreeze(o: any): void;
228
228
  * To make mutation extra clear - function returns void (unlike Object.assign).
229
229
  */
230
230
  export declare function _objectAssignExact<T extends AnyObject>(target: T, source: T): void;
231
+ /**
232
+ * type MyObj = { a?: string, b?: string }
233
+ *
234
+ * const collection: MyObj[] = [...]
235
+ *
236
+ * const collectionA = collection.filter(_hasProp('a'))
237
+ * --> collectionA is now RequiredProp<MyObj, 'a'>[], i.e. { a: string, b?: string }[]
238
+ */
239
+ export declare function _hasProp<T, Prop extends keyof T>(prop: Prop): (object: T) => object is RequiredProp<T, Prop>;
231
240
  export {};
@@ -446,3 +446,16 @@ export function _objectAssignExact(target, source) {
446
446
  }
447
447
  }
448
448
  }
449
+ /**
450
+ * type MyObj = { a?: string, b?: string }
451
+ *
452
+ * const collection: MyObj[] = [...]
453
+ *
454
+ * const collectionA = collection.filter(_hasProp('a'))
455
+ * --> collectionA is now RequiredProp<MyObj, 'a'>[], i.e. { a: string, b?: string }[]
456
+ */
457
+ export function _hasProp(prop) {
458
+ return function (object) {
459
+ return typeof object[prop] !== 'undefined';
460
+ };
461
+ }
@@ -1,4 +1,4 @@
1
- /* eslint-disable @typescript-eslint/promise-function-async */
1
+ /* oxlint-disable @typescript-eslint/promise-function-async */
2
2
  /**
3
3
  * Returns DeferredPromise - a Promise that has .resolve() and .reject() methods.
4
4
  */
@@ -8,7 +8,7 @@ import { pDefer } from './pDefer.js';
8
8
  export async function pDelay(ms = 0, value) {
9
9
  return await new Promise((resolve, reject) => setTimeout(value instanceof Error ? reject : resolve, ms, value));
10
10
  }
11
- /* eslint-disable @typescript-eslint/promise-function-async */
11
+ /* oxlint-disable @typescript-eslint/promise-function-async */
12
12
  /**
13
13
  * Promisified version of setTimeout.
14
14
  *
@@ -1,5 +1,5 @@
1
1
  // from: https://github.com/lodash/lodash/blob/master/.internal/unicodeWords.js
2
- /* eslint-disable */
2
+ // oxlint-disable
3
3
  /** Used to compose unicode character classes. */
4
4
  const rsAstralRange = '\\ud800-\\udfff';
5
5
  const rsComboMarksRange = '\\u0300-\\u036f';
package/dist/types.js CHANGED
@@ -58,5 +58,4 @@ export function _typeCast(_v) { }
58
58
  * Type-safe Object.assign that checks that part is indeed a Partial<T>
59
59
  */
60
60
  export const _objectAssign = Object.assign;
61
- /* eslint-enable */
62
61
  export * from './typeFest.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
3
  "type": "module",
4
- "version": "15.55.0",
4
+ "version": "15.56.0",
5
5
  "dependencies": {
6
6
  "tslib": "^2",
7
7
  "undici": "^7",
@@ -1,6 +1,6 @@
1
1
  // Modified version of topbar:
2
2
  // http://buunguyen.github.io/topbar
3
- /* eslint-disable */
3
+ // oxlint-disable
4
4
 
5
5
  export interface TopBarOptions {
6
6
  /**
@@ -69,7 +69,7 @@ export const _AsyncMemo =
69
69
  const keyStr = String(key)
70
70
  const methodSignature = _getTargetMethodSignature(target, keyStr)
71
71
 
72
- // eslint-disable-next-line @typescript-eslint/promise-function-async
72
+ // oxlint-disable-next-line @typescript-eslint/promise-function-async
73
73
  descriptor.value = function (this: typeof target, ...args: MaybeParameters<FN>): Promise<any> {
74
74
  const ctx = this
75
75
  const cacheKey = cacheKeyFn(args)
@@ -22,7 +22,7 @@ export const _SwarmSafe = (): MethodDecorator => (target, key, descriptor) => {
22
22
 
23
23
  console.log('SwarmSafe constructor called', { key, methodSignature })
24
24
 
25
- // eslint-disable-next-line @typescript-eslint/promise-function-async
25
+ // oxlint-disable-next-line @typescript-eslint/promise-function-async
26
26
  descriptor.value = function (this: typeof target, ...args: any[]): Promise<any> {
27
27
  console.log('SwarmSafe method called', { key, methodSignature, args })
28
28
  const ctx = this
@@ -28,6 +28,7 @@ import {
28
28
  } from '../object/object.util.js'
29
29
  import { pDelay } from '../promise/pDelay.js'
30
30
  import { pTimeout } from '../promise/pTimeout.js'
31
+ import { _toUrlOrNull } from '../string/index.js'
31
32
  import { _jsonParse, _jsonParseIfPossible } from '../string/json.util.js'
32
33
  import { _stringify } from '../string/stringify.js'
33
34
  import type {
@@ -770,7 +771,7 @@ export class Fetcher {
770
771
  let { name } = cfg
771
772
  if (!name && cfg.baseUrl) {
772
773
  // derive FetcherName from baseUrl
773
- const url = URL.parse(cfg.baseUrl)
774
+ const url = _toUrlOrNull(cfg.baseUrl)
774
775
  if (url) {
775
776
  name = url.hostname
776
777
  }
@@ -5,6 +5,7 @@ import type {
5
5
  MutateOptions,
6
6
  ObjectMapper,
7
7
  ObjectPredicate,
8
+ RequiredProp,
8
9
  Reviver,
9
10
  StringMap,
10
11
  ValueOf,
@@ -527,3 +528,17 @@ export function _objectAssignExact<T extends AnyObject>(target: T, source: T): v
527
528
  }
528
529
  }
529
530
  }
531
+
532
+ /**
533
+ * type MyObj = { a?: string, b?: string }
534
+ *
535
+ * const collection: MyObj[] = [...]
536
+ *
537
+ * const collectionA = collection.filter(_hasProp('a'))
538
+ * --> collectionA is now RequiredProp<MyObj, 'a'>[], i.e. { a: string, b?: string }[]
539
+ */
540
+ export function _hasProp<T, Prop extends keyof T>(prop: Prop) {
541
+ return function (object: T): object is RequiredProp<T, Prop> {
542
+ return typeof object[prop] !== 'undefined'
543
+ }
544
+ }
@@ -21,7 +21,7 @@ export interface DeferredPromise<T = void> extends Promise<T> {
21
21
  rejectAborted: (reason?: string) => void
22
22
  }
23
23
 
24
- /* eslint-disable @typescript-eslint/promise-function-async */
24
+ /* oxlint-disable @typescript-eslint/promise-function-async */
25
25
 
26
26
  /**
27
27
  * Returns DeferredPromise - a Promise that has .resolve() and .reject() methods.
@@ -14,7 +14,7 @@ export async function pDelay<T>(ms: NumberOfMilliseconds = 0, value?: T): Promis
14
14
  )
15
15
  }
16
16
 
17
- /* eslint-disable @typescript-eslint/promise-function-async */
17
+ /* oxlint-disable @typescript-eslint/promise-function-async */
18
18
 
19
19
  /**
20
20
  * Promisified version of setTimeout.
@@ -1,5 +1,5 @@
1
1
  // from: https://github.com/lodash/lodash/blob/master/.internal/unicodeWords.js
2
- /* eslint-disable */
2
+ // oxlint-disable
3
3
 
4
4
  /** Used to compose unicode character classes. */
5
5
  const rsAstralRange = '\\ud800-\\udfff'
package/src/types.ts CHANGED
@@ -478,7 +478,7 @@ export type Class<T = any> = new (...args: any[]) => T
478
478
  //=> error TS2339: Property 'push' does not exist on type 'readonly string[]'
479
479
  ```
480
480
  */
481
- /* eslint-disable @typescript-eslint/no-restricted-types */
481
+ /* oxlint-disable @typescript-eslint/no-restricted-types */
482
482
  export type ReadonlyDeep<T> = T extends Primitive | ((...args: any[]) => unknown)
483
483
  ? T
484
484
  : T extends ReadonlyMap<infer KeyType, infer ValueType>
@@ -509,6 +509,8 @@ type ReadonlyObjectDeep<ObjectType extends object> = {
509
509
  readonly [KeyType in keyof ObjectType]: ReadonlyDeep<ObjectType[KeyType]>
510
510
  }
511
511
 
512
+ // oxlint-enable
513
+
512
514
  /**
513
515
  Makes one property of T required instead of optional.
514
516
  @example
@@ -524,6 +526,4 @@ type ReadonlyObjectDeep<ObjectType extends object> = {
524
526
  */
525
527
  export type RequiredProp<T, K extends keyof T> = Required<Pick<T, K>> & T
526
528
 
527
- /* eslint-enable */
528
-
529
529
  export * from './typeFest.js'