@naturalcycles/js-lib 14.195.0 → 14.196.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.
@@ -562,7 +562,7 @@ class Fetcher {
562
562
  },
563
563
  init: (0, object_util_1._merge)({
564
564
  ...this.cfg.init,
565
- headers: { ...this.cfg.init.headers },
565
+ headers: { ...this.cfg.init.headers }, // this avoids mutation
566
566
  method: opt.method || this.cfg.init.method,
567
567
  credentials: opt.credentials || this.cfg.init.credentials,
568
568
  redirect: opt.redirect || this.cfg.init.redirect || 'follow',
@@ -1,4 +1,4 @@
1
- import { AbortableMapper, AbortablePredicate, END, Predicate } from '../types';
1
+ import { AbortableMapper, AbortablePredicate, END } from '../types';
2
2
  /**
3
3
  * Iterable2 is a wrapper around Iterable that implements "Iterator Helpers proposal":
4
4
  * https://github.com/tc39/proposal-iterator-helpers
@@ -15,7 +15,9 @@ export declare class Iterable2<T> implements Iterable<T> {
15
15
  [Symbol.iterator](): Iterator<T>;
16
16
  toArray(): T[];
17
17
  forEach(cb: (v: T, i: number) => any | typeof END): void;
18
- find(cb: Predicate<T>): T | undefined;
18
+ some(cb: AbortablePredicate<T>): boolean;
19
+ every(cb: AbortablePredicate<T>): boolean;
20
+ find(cb: AbortablePredicate<T>): T | undefined;
19
21
  filter(cb: AbortablePredicate<T>): Iterable2<T>;
20
22
  map<OUT>(mapper: AbortableMapper<T, OUT>): Iterable2<OUT>;
21
23
  }
@@ -33,10 +33,26 @@ class Iterable2 {
33
33
  return;
34
34
  }
35
35
  }
36
+ some(cb) {
37
+ // eslint-disable-next-line unicorn/prefer-array-some
38
+ return !!this.find(cb);
39
+ }
40
+ every(cb) {
41
+ let i = 0;
42
+ for (const v of this.it) {
43
+ const r = cb(v, i++);
44
+ if (r === types_1.END || !r)
45
+ return false;
46
+ }
47
+ return true;
48
+ }
36
49
  find(cb) {
37
50
  let i = 0;
38
51
  for (const v of this.it) {
39
- if (cb(v, i++))
52
+ const r = cb(v, i++);
53
+ if (r === types_1.END)
54
+ return;
55
+ if (r)
40
56
  return v;
41
57
  }
42
58
  }
@@ -43,7 +43,7 @@ function commonLoggerMinLevel(logger, minLevel, mutate = false) {
43
43
  return exports.commonLoggerNoop;
44
44
  }
45
45
  return {
46
- log: index_1._noop,
46
+ log: index_1._noop, // otherwise it is "log everything" logger (same logger as input)
47
47
  warn: level <= exports.commonLogLevelNumber['warn'] ? logger.warn.bind(logger) : index_1._noop,
48
48
  error: logger.error.bind(logger), // otherwise it's "log nothing" logger (same as noopLogger)
49
49
  };
@@ -30,10 +30,26 @@ export class Iterable2 {
30
30
  return;
31
31
  }
32
32
  }
33
+ some(cb) {
34
+ // eslint-disable-next-line unicorn/prefer-array-some
35
+ return !!this.find(cb);
36
+ }
37
+ every(cb) {
38
+ let i = 0;
39
+ for (const v of this.it) {
40
+ const r = cb(v, i++);
41
+ if (r === END || !r)
42
+ return false;
43
+ }
44
+ return true;
45
+ }
33
46
  find(cb) {
34
47
  let i = 0;
35
48
  for (const v of this.it) {
36
- if (cb(v, i++))
49
+ const r = cb(v, i++);
50
+ if (r === END)
51
+ return;
52
+ if (r)
37
53
  return v;
38
54
  }
39
55
  }
@@ -40,7 +40,7 @@ export function commonLoggerMinLevel(logger, minLevel, mutate = false) {
40
40
  return commonLoggerNoop;
41
41
  }
42
42
  return {
43
- log: _noop,
43
+ log: _noop, // otherwise it is "log everything" logger (same logger as input)
44
44
  warn: level <= commonLogLevelNumber['warn'] ? logger.warn.bind(logger) : _noop,
45
45
  error: logger.error.bind(logger), // otherwise it's "log nothing" logger (same as noopLogger)
46
46
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.195.0",
3
+ "version": "14.196.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -1,4 +1,4 @@
1
- import { AbortableMapper, AbortablePredicate, END, Predicate, SKIP } from '../types'
1
+ import { AbortableMapper, AbortablePredicate, END, SKIP } from '../types'
2
2
 
3
3
  /**
4
4
  * Iterable2 is a wrapper around Iterable that implements "Iterator Helpers proposal":
@@ -34,10 +34,26 @@ export class Iterable2<T> implements Iterable<T> {
34
34
  }
35
35
  }
36
36
 
37
- find(cb: Predicate<T>): T | undefined {
37
+ some(cb: AbortablePredicate<T>): boolean {
38
+ // eslint-disable-next-line unicorn/prefer-array-some
39
+ return !!this.find(cb)
40
+ }
41
+
42
+ every(cb: AbortablePredicate<T>): boolean {
43
+ let i = 0
44
+ for (const v of this.it) {
45
+ const r = cb(v, i++)
46
+ if (r === END || !r) return false
47
+ }
48
+ return true
49
+ }
50
+
51
+ find(cb: AbortablePredicate<T>): T | undefined {
38
52
  let i = 0
39
53
  for (const v of this.it) {
40
- if (cb(v, i++)) return v
54
+ const r = cb(v, i++)
55
+ if (r === END) return
56
+ if (r) return v
41
57
  }
42
58
  }
43
59
 
@@ -77,8 +77,8 @@ export function _leven(first: string, second: string): number {
77
77
  ? result + 1
78
78
  : temporary2
79
79
  : temporary2 > temporary
80
- ? temporary + 1
81
- : temporary2
80
+ ? temporary + 1
81
+ : temporary2
82
82
  }
83
83
  }
84
84
 
package/src/typeFest.ts CHANGED
@@ -30,8 +30,8 @@ export type IsEqual<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G ex
30
30
  type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true
31
31
  ? never
32
32
  : KeyType extends ExcludeType
33
- ? never
34
- : KeyType
33
+ ? never
34
+ : KeyType
35
35
 
36
36
  /**
37
37
  Create a type from an object type without certain keys.
@@ -94,12 +94,12 @@ export type Except<ObjectType, KeysType extends keyof ObjectType> = {
94
94
  export type ReadonlyDeep<T> = T extends Primitive | ((...args: any[]) => unknown)
95
95
  ? T
96
96
  : T extends ReadonlyMap<infer KeyType, infer ValueType>
97
- ? ReadonlyMapDeep<KeyType, ValueType>
98
- : T extends ReadonlySet<infer ItemType>
99
- ? ReadonlySetDeep<ItemType>
100
- : T extends object
101
- ? ReadonlyObjectDeep<T>
102
- : unknown
97
+ ? ReadonlyMapDeep<KeyType, ValueType>
98
+ : T extends ReadonlySet<infer ItemType>
99
+ ? ReadonlySetDeep<ItemType>
100
+ : T extends object
101
+ ? ReadonlyObjectDeep<T>
102
+ : unknown
103
103
 
104
104
  /**
105
105
  Same as `ReadonlyDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `ReadonlyDeep`.
@@ -171,8 +171,8 @@ export type Merge<Destination, Source> = {
171
171
  [Key in keyof OmitIndexSignature<Destination & Source>]: Key extends keyof Source
172
172
  ? Source[Key]
173
173
  : Key extends keyof Destination
174
- ? Destination[Key]
175
- : never
174
+ ? Destination[Key]
175
+ : never
176
176
  } & PickIndexSignature<Destination & Source>
177
177
 
178
178
  /**