@tutao/tutanota-utils 3.94.0 → 3.94.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.
@@ -1,71 +1,72 @@
1
- import { neverNull } from "./Utils.js"
1
+ import { neverNull } from "./Utils.js";
2
2
  /**
3
3
  * A wrapper for an object that shall be lazy loaded asynchronously. If loading the object is triggered in parallel (getAsync()) the object is actually only loaded once but returned to all calls of getAsync().
4
4
  * If the object was loaded once it is not loaded again.
5
5
  */
6
6
  export class LazyLoaded {
7
- /**
8
- * @param loadFunction The function that actually loads the object as soon as getAsync() is called the first time.
9
- * @param defaultValue The value that shall be returned by getSync() or getLoaded() as long as the object is not loaded yet.
10
- */
11
- constructor(loadFunction, defaultValue) {
12
- this._isLoaded = false
13
- this._loadFunction = loadFunction
14
- this._loadingPromise = null
15
- this._loadedObject = defaultValue !== null && defaultValue !== void 0 ? defaultValue : null
16
- }
17
- load() {
18
- this.getAsync()
19
- return this
20
- }
21
- isLoaded() {
22
- return this._isLoaded
23
- }
24
- /**
25
- * Loads the object if it is not loaded yet. May be called in parallel and takes care that the load function is only called once.
26
- */
27
- getAsync() {
28
- if (this.isLoaded()) {
29
- return Promise.resolve(neverNull(this._loadedObject))
30
- } else {
31
- if (!this._loadingPromise) {
32
- this._loadingPromise = this._loadFunction().then(result => {
33
- this._loadedObject = result
34
- this._isLoaded = true
35
- return result
36
- })
37
- }
38
- return this._loadingPromise
39
- }
40
- }
41
- /**
42
- * Returns null if the object is not loaded yet.
43
- */
44
- getSync() {
45
- return this._loadedObject
46
- }
47
- /**
48
- * Only call this function if you know that the object is already loaded.
49
- */
50
- getLoaded() {
51
- return neverNull(this._loadedObject)
52
- }
53
- /**
54
- * Removes the currently loaded object, so it will be loaded again with the next getAsync() call. Does not set any default value.
55
- */
56
- reset() {
57
- this._isLoaded = false
58
- this._loadingPromise = null
59
- this._loadedObject = null
60
- }
61
- /**
62
- * Loads the object again and replaces the current one
63
- */
64
- reload() {
65
- return this._loadFunction().then(result => {
66
- this._isLoaded = true
67
- this._loadedObject = result
68
- return result
69
- })
70
- }
7
+ /**
8
+ * @param loadFunction The function that actually loads the object as soon as getAsync() is called the first time.
9
+ * @param defaultValue The value that shall be returned by getSync() or getLoaded() as long as the object is not loaded yet.
10
+ */
11
+ constructor(loadFunction, defaultValue) {
12
+ this._isLoaded = false;
13
+ this._loadFunction = loadFunction;
14
+ this._loadingPromise = null;
15
+ this._loadedObject = defaultValue !== null && defaultValue !== void 0 ? defaultValue : null;
16
+ }
17
+ load() {
18
+ this.getAsync();
19
+ return this;
20
+ }
21
+ isLoaded() {
22
+ return this._isLoaded;
23
+ }
24
+ /**
25
+ * Loads the object if it is not loaded yet. May be called in parallel and takes care that the load function is only called once.
26
+ */
27
+ getAsync() {
28
+ if (this.isLoaded()) {
29
+ return Promise.resolve(neverNull(this._loadedObject));
30
+ }
31
+ else {
32
+ if (!this._loadingPromise) {
33
+ this._loadingPromise = this._loadFunction().then(result => {
34
+ this._loadedObject = result;
35
+ this._isLoaded = true;
36
+ return result;
37
+ });
38
+ }
39
+ return this._loadingPromise;
40
+ }
41
+ }
42
+ /**
43
+ * Returns null if the object is not loaded yet.
44
+ */
45
+ getSync() {
46
+ return this._loadedObject;
47
+ }
48
+ /**
49
+ * Only call this function if you know that the object is already loaded.
50
+ */
51
+ getLoaded() {
52
+ return neverNull(this._loadedObject);
53
+ }
54
+ /**
55
+ * Removes the currently loaded object, so it will be loaded again with the next getAsync() call. Does not set any default value.
56
+ */
57
+ reset() {
58
+ this._isLoaded = false;
59
+ this._loadingPromise = null;
60
+ this._loadedObject = null;
61
+ }
62
+ /**
63
+ * Loads the object again and replaces the current one
64
+ */
65
+ reload() {
66
+ return this._loadFunction().then(result => {
67
+ this._isLoaded = true;
68
+ this._loadedObject = result;
69
+ return result;
70
+ });
71
+ }
71
72
  }
@@ -2,8 +2,8 @@
2
2
  * Merges multiple maps into a single map with lists of values.
3
3
  * @param maps
4
4
  */
5
- export declare function mergeMaps<T>(maps: Map<string, T>[]): Map<string, T[]>
6
- export declare function getFromMap<K, V>(map: Map<K, V>, key: K, byDefault: () => V): V
5
+ export declare function mergeMaps<T>(maps: Map<string, T>[]): Map<string, T[]>;
6
+ export declare function getFromMap<K, V>(map: Map<K, V>, key: K, byDefault: () => V): V;
7
7
  /** Creates a new map with key and value added to {@param map}. It is like set() but for immutable map. */
8
- export declare function addMapEntry<K, V>(map: ReadonlyMap<K, V>, key: K, value: V): Map<K, V>
9
- export declare function deleteMapEntry<K, V>(map: ReadonlyMap<K, V>, key: K): Map<K, V>
8
+ export declare function addMapEntry<K, V>(map: ReadonlyMap<K, V>, key: K, value: V): Map<K, V>;
9
+ export declare function deleteMapEntry<K, V>(map: ReadonlyMap<K, V>, key: K): Map<K, V>;
package/dist/MapUtils.js CHANGED
@@ -1,37 +1,38 @@
1
- import { neverNull } from "./Utils.js"
1
+ import { neverNull } from "./Utils.js";
2
2
  /**
3
3
  * Merges multiple maps into a single map with lists of values.
4
4
  * @param maps
5
5
  */
6
6
  export function mergeMaps(maps) {
7
- return maps.reduce((mergedMap, map) => {
8
- // merge same key of multiple attributes
9
- map.forEach((value, key) => {
10
- if (mergedMap.has(key)) {
11
- neverNull(mergedMap.get(key)).push(value)
12
- } else {
13
- mergedMap.set(key, [value])
14
- }
15
- })
16
- return mergedMap
17
- }, new Map())
7
+ return maps.reduce((mergedMap, map) => {
8
+ // merge same key of multiple attributes
9
+ map.forEach((value, key) => {
10
+ if (mergedMap.has(key)) {
11
+ neverNull(mergedMap.get(key)).push(value);
12
+ }
13
+ else {
14
+ mergedMap.set(key, [value]);
15
+ }
16
+ });
17
+ return mergedMap;
18
+ }, new Map());
18
19
  }
19
20
  export function getFromMap(map, key, byDefault) {
20
- let value = map.get(key)
21
- if (!value) {
22
- value = byDefault()
23
- map.set(key, value)
24
- }
25
- return value
21
+ let value = map.get(key);
22
+ if (!value) {
23
+ value = byDefault();
24
+ map.set(key, value);
25
+ }
26
+ return value;
26
27
  }
27
28
  /** Creates a new map with key and value added to {@param map}. It is like set() but for immutable map. */
28
29
  export function addMapEntry(map, key, value) {
29
- const newMap = new Map(map)
30
- newMap.set(key, value)
31
- return newMap
30
+ const newMap = new Map(map);
31
+ newMap.set(key, value);
32
+ return newMap;
32
33
  }
33
34
  export function deleteMapEntry(map, key) {
34
- const newMap = new Map(map)
35
- newMap.delete(key)
36
- return newMap
35
+ const newMap = new Map(map);
36
+ newMap.delete(key);
37
+ return newMap;
37
38
  }
@@ -1,5 +1,5 @@
1
- export declare function mod(n: number, m: number): number
1
+ export declare function mod(n: number, m: number): number;
2
2
  /**
3
3
  * Clamp value to between min and max (inclusive)
4
4
  */
5
- export declare function clamp(value: number, min: number, max: number): number
5
+ export declare function clamp(value: number, min: number, max: number): number;
package/dist/MathUtils.js CHANGED
@@ -1,9 +1,9 @@
1
1
  export function mod(n, m) {
2
- return ((n % m) + m) % m
2
+ return ((n % m) + m) % m;
3
3
  }
4
4
  /**
5
5
  * Clamp value to between min and max (inclusive)
6
6
  */
7
7
  export function clamp(value, min, max) {
8
- return Math.max(min, Math.min(value, max))
8
+ return Math.max(min, Math.min(value, max));
9
9
  }
@@ -5,19 +5,19 @@
5
5
  * Changed: default concurrency level is 1 and not Infinite
6
6
  */
7
7
  export interface Options {
8
- /**
8
+ /**
9
9
  Number of concurrently pending promises returned by `mapper`.
10
10
  Must be an integer from 1 and up or `Infinity`.
11
11
  @default 1
12
12
  */
13
- readonly concurrency?: number
13
+ readonly concurrency?: number;
14
14
  }
15
15
  /**
16
16
  Function which is called for every item in `input`. Expected to return a `Promise` or value.
17
17
  @param element - Iterated element.
18
18
  @param index - Index of the element in the source array.
19
19
  */
20
- export declare type Mapper<Element, NewElement> = (element: Element, index: number) => Promise<NewElement> | NewElement
20
+ export declare type Mapper<Element, NewElement> = (element: Element, index: number) => Promise<NewElement> | NewElement;
21
21
  /**
22
22
  @param iterable - Iterated over concurrently in the `mapper` function.
23
23
  @param mapper - Function which is called for every item in `input`. Expected to return a `Promise` or value.
@@ -41,8 +41,4 @@ export declare type Mapper<Element, NewElement> = (element: Element, index: numb
41
41
  //=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
42
42
  ```
43
43
  */
44
- export declare function pMap<Element, NewElement>(
45
- iterable: Iterable<Element>,
46
- mapper: Mapper<Element, NewElement>,
47
- options?: Options,
48
- ): Promise<Array<NewElement>>
44
+ export declare function pMap<Element, NewElement>(iterable: Iterable<Element>, mapper: Mapper<Element, NewElement>, options?: Options): Promise<Array<NewElement>>;
@@ -22,53 +22,54 @@
22
22
  ```
23
23
  */
24
24
  export async function pMap(iterable, mapper, options = {}) {
25
- const { concurrency = 1 } = options
26
- return new Promise((resolve, reject) => {
27
- if (typeof mapper !== "function") {
28
- throw new TypeError("Mapper function is required")
29
- }
30
- if (!((Number.isSafeInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency >= 1)) {
31
- throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${concurrency}\` (${typeof concurrency})`)
32
- }
33
- const result = []
34
- const errors = []
35
- const iterator = iterable[Symbol.iterator]()
36
- let isRejected = false
37
- let isIterableDone = false
38
- let resolvingCount = 0
39
- let currentIndex = 0
40
- const next = () => {
41
- if (isRejected) {
42
- return
43
- }
44
- const nextItem = iterator.next()
45
- const index = currentIndex
46
- currentIndex++
47
- if (nextItem.done) {
48
- isIterableDone = true
49
- if (resolvingCount === 0) {
50
- resolve(result)
51
- }
52
- return
53
- }
54
- resolvingCount++
55
- ;(async () => {
56
- try {
57
- const element = await nextItem.value
58
- result[index] = await mapper(element, index)
59
- resolvingCount--
60
- next()
61
- } catch (error) {
62
- isRejected = true
63
- reject(error)
64
- }
65
- })()
66
- }
67
- for (let index = 0; index < concurrency; index++) {
68
- next()
69
- if (isIterableDone) {
70
- break
71
- }
72
- }
73
- })
25
+ const { concurrency = 1 } = options;
26
+ return new Promise((resolve, reject) => {
27
+ if (typeof mapper !== "function") {
28
+ throw new TypeError("Mapper function is required");
29
+ }
30
+ if (!((Number.isSafeInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency >= 1)) {
31
+ throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${concurrency}\` (${typeof concurrency})`);
32
+ }
33
+ const result = [];
34
+ const errors = [];
35
+ const iterator = iterable[Symbol.iterator]();
36
+ let isRejected = false;
37
+ let isIterableDone = false;
38
+ let resolvingCount = 0;
39
+ let currentIndex = 0;
40
+ const next = () => {
41
+ if (isRejected) {
42
+ return;
43
+ }
44
+ const nextItem = iterator.next();
45
+ const index = currentIndex;
46
+ currentIndex++;
47
+ if (nextItem.done) {
48
+ isIterableDone = true;
49
+ if (resolvingCount === 0) {
50
+ resolve(result);
51
+ }
52
+ return;
53
+ }
54
+ resolvingCount++;
55
+ (async () => {
56
+ try {
57
+ const element = await nextItem.value;
58
+ result[index] = await mapper(element, index);
59
+ resolvingCount--;
60
+ next();
61
+ }
62
+ catch (error) {
63
+ isRejected = true;
64
+ reject(error);
65
+ }
66
+ })();
67
+ };
68
+ for (let index = 0; index < concurrency; index++) {
69
+ next();
70
+ if (isIterableDone) {
71
+ break;
72
+ }
73
+ }
74
+ });
74
75
  }
@@ -1,6 +1,6 @@
1
- import type { Options as PromiseMapOptions } from "./PromiseMap.js"
2
- export declare type $Promisable<T> = Promise<T> | T
3
- declare type PromiseMapCallback<T, U> = (el: T, index: number) => $Promisable<U>
1
+ import type { Options as PromiseMapOptions } from "./PromiseMap.js";
2
+ export declare type $Promisable<T> = Promise<T> | T;
3
+ declare type PromiseMapCallback<T, U> = (el: T, index: number) => $Promisable<U>;
4
4
  /**
5
5
  * Map array of values to promise of arrays or array. Mapper function may return promise or value. If value is returned,
6
6
  * we avoid promise scheduling.
@@ -8,27 +8,24 @@ declare type PromiseMapCallback<T, U> = (el: T, index: number) => $Promisable<U>
8
8
  * This is needed to run the whole operation in one microtask (e.g. keep IndexedDB transaction active, which is closed in
9
9
  * some browsers (e.g. Safari) when event loop iteration ends).
10
10
  */
11
- export declare function mapInCallContext<T, U>(values: T[], callback: PromiseMapCallback<T, U>): PromisableWrapper<Array<U>>
12
- export { pMap as promiseMap } from "./PromiseMap.js"
13
- export declare type PromiseMapFn = <T, U>(values: T[], callback: PromiseMapCallback<T, U>, options?: PromiseMapOptions) => PromisableWrapper<U[]>
11
+ export declare function mapInCallContext<T, U>(values: T[], callback: PromiseMapCallback<T, U>): PromisableWrapper<Array<U>>;
12
+ export { pMap as promiseMap } from "./PromiseMap.js";
13
+ export declare type PromiseMapFn = <T, U>(values: T[], callback: PromiseMapCallback<T, U>, options?: PromiseMapOptions) => PromisableWrapper<U[]>;
14
14
  /** Factory function which gives you ack promiseMap implementation. {@see mapInCallContext} for what it means. */
15
- export declare function promiseMapCompat(useMapInCallContext: boolean): PromiseMapFn
15
+ export declare function promiseMapCompat(useMapInCallContext: boolean): PromiseMapFn;
16
16
  export declare class PromisableWrapper<T> {
17
- static from<U>(value: $Promisable<U>): PromisableWrapper<U>
18
- value: $Promisable<T>
19
- constructor(value: $Promisable<PromisableWrapper<T> | T>)
20
- thenOrApply<R>(
21
- onFulfill: (arg0: T) => $Promisable<PromisableWrapper<R> | R>,
22
- onReject?: (arg0: any) => $Promisable<R | PromisableWrapper<R>>,
23
- ): PromisableWrapper<R>
24
- toPromise(): Promise<T>
17
+ static from<U>(value: $Promisable<U>): PromisableWrapper<U>;
18
+ value: $Promisable<T>;
19
+ constructor(value: $Promisable<PromisableWrapper<T> | T>);
20
+ thenOrApply<R>(onFulfill: (arg0: T) => $Promisable<PromisableWrapper<R> | R>, onReject?: (arg0: any) => $Promisable<R | PromisableWrapper<R>>): PromisableWrapper<R>;
21
+ toPromise(): Promise<T>;
25
22
  }
26
- export declare function delay(ms: number): Promise<void>
23
+ export declare function delay(ms: number): Promise<void>;
27
24
  /**
28
25
  * Pass to Promise.then to perform an action while forwarding on the result
29
26
  * @param action
30
27
  */
31
- export declare function tap<T>(action: (arg0: T) => unknown): (arg0: T) => T
28
+ export declare function tap<T>(action: (arg0: T) => unknown): (arg0: T) => T;
32
29
  /**
33
30
  * Helper utility intended to be used with typed exceptions and .catch() method of promise like so:
34
31
  *
@@ -44,8 +41,8 @@ export declare function tap<T>(action: (arg0: T) => unknown): (arg0: T) => T
44
41
  * @param catcher to handle only errors of type cls
45
42
  * @returns handler which either forwards to catcher or rethrows
46
43
  */
47
- export declare function ofClass<E, R>(cls: Class<E>, catcher: (arg0: E) => $Promisable<R>): (arg0: any) => Promise<R>
44
+ export declare function ofClass<E, R>(cls: Class<E>, catcher: (arg0: E) => $Promisable<R>): (arg0: any) => Promise<R>;
48
45
  /**
49
46
  * Filter iterable. Just like Array.prototype.filter but callback can return promises
50
47
  */
51
- export declare function promiseFilter<T>(iterable: Iterable<T>, filter: (item: T, index: number) => $Promisable<boolean>): Promise<Array<T>>
48
+ export declare function promiseFilter<T>(iterable: Iterable<T>, filter: (item: T, index: number) => $Promisable<boolean>): Promise<Array<T>>;
@@ -1,4 +1,4 @@
1
- import { pMap as promiseMap } from "./PromiseMap.js"
1
+ import { pMap as promiseMap } from "./PromiseMap.js";
2
2
  /**
3
3
  * Map array of values to promise of arrays or array. Mapper function may return promise or value. If value is returned,
4
4
  * we avoid promise scheduling.
@@ -7,78 +7,81 @@ import { pMap as promiseMap } from "./PromiseMap.js"
7
7
  * some browsers (e.g. Safari) when event loop iteration ends).
8
8
  */
9
9
  export function mapInCallContext(values, callback) {
10
- return new PromisableWrapper(_mapInCallContext(values, callback, 0, []))
10
+ return new PromisableWrapper(_mapInCallContext(values, callback, 0, []));
11
11
  }
12
12
  function _mapInCallContext(values, callback, index, acc) {
13
- if (index >= values.length) {
14
- return acc
15
- }
16
- let mappedValue = callback(values[index], index)
17
- if (mappedValue instanceof Promise) {
18
- return mappedValue.then(v => {
19
- acc.push(v)
20
- return _mapInCallContext(values, callback, index + 1, acc)
21
- })
22
- } else {
23
- acc.push(mappedValue)
24
- return _mapInCallContext(values, callback, index + 1, acc)
25
- }
13
+ if (index >= values.length) {
14
+ return acc;
15
+ }
16
+ let mappedValue = callback(values[index], index);
17
+ if (mappedValue instanceof Promise) {
18
+ return mappedValue.then(v => {
19
+ acc.push(v);
20
+ return _mapInCallContext(values, callback, index + 1, acc);
21
+ });
22
+ }
23
+ else {
24
+ acc.push(mappedValue);
25
+ return _mapInCallContext(values, callback, index + 1, acc);
26
+ }
26
27
  }
27
- export { pMap as promiseMap } from "./PromiseMap.js"
28
+ export { pMap as promiseMap } from "./PromiseMap.js";
28
29
  function mapNoFallback(values, callback, options) {
29
- return PromisableWrapper.from(promiseMap(values, callback, options))
30
+ return PromisableWrapper.from(promiseMap(values, callback, options));
30
31
  }
31
32
  /** Factory function which gives you ack promiseMap implementation. {@see mapInCallContext} for what it means. */
32
33
  export function promiseMapCompat(useMapInCallContext) {
33
- return useMapInCallContext ? mapInCallContext : mapNoFallback
34
+ return useMapInCallContext ? mapInCallContext : mapNoFallback;
34
35
  }
35
36
  function flatWrapper(value) {
36
- return value instanceof PromisableWrapper ? value.value : value
37
+ return value instanceof PromisableWrapper ? value.value : value;
37
38
  }
38
39
  // It kinda implements 'thenable' protocol so you can freely pass it around as a generic promise
39
40
  export class PromisableWrapper {
40
- constructor(value) {
41
- this.value = value instanceof Promise ? value.then(flatWrapper) : flatWrapper(value)
42
- }
43
- static from(value) {
44
- return new PromisableWrapper(value)
45
- }
46
- thenOrApply(onFulfill, onReject) {
47
- if (this.value instanceof Promise) {
48
- const v = this.value.then(onFulfill, onReject)
49
- return new PromisableWrapper(v)
50
- } else {
51
- try {
52
- return new PromisableWrapper(onFulfill(this.value))
53
- } catch (e) {
54
- if (onReject) {
55
- return new PromisableWrapper(onReject(e))
56
- }
57
- throw e
58
- }
59
- }
60
- }
61
- toPromise() {
62
- return Promise.resolve(this.value)
63
- }
41
+ constructor(value) {
42
+ this.value = value instanceof Promise ? value.then(flatWrapper) : flatWrapper(value);
43
+ }
44
+ static from(value) {
45
+ return new PromisableWrapper(value);
46
+ }
47
+ thenOrApply(onFulfill, onReject) {
48
+ if (this.value instanceof Promise) {
49
+ const v = this.value.then(onFulfill, onReject);
50
+ return new PromisableWrapper(v);
51
+ }
52
+ else {
53
+ try {
54
+ return new PromisableWrapper(onFulfill(this.value));
55
+ }
56
+ catch (e) {
57
+ if (onReject) {
58
+ return new PromisableWrapper(onReject(e));
59
+ }
60
+ throw e;
61
+ }
62
+ }
63
+ }
64
+ toPromise() {
65
+ return Promise.resolve(this.value);
66
+ }
64
67
  }
65
68
  export function delay(ms) {
66
- if (Number.isNaN(ms) || ms < 0) {
67
- throw new Error(`Invalid delay: ${ms}`)
68
- }
69
- return new Promise(resolve => {
70
- setTimeout(resolve, ms)
71
- })
69
+ if (Number.isNaN(ms) || ms < 0) {
70
+ throw new Error(`Invalid delay: ${ms}`);
71
+ }
72
+ return new Promise(resolve => {
73
+ setTimeout(resolve, ms);
74
+ });
72
75
  }
73
76
  /**
74
77
  * Pass to Promise.then to perform an action while forwarding on the result
75
78
  * @param action
76
79
  */
77
80
  export function tap(action) {
78
- return function (value) {
79
- action(value)
80
- return value
81
- }
81
+ return function (value) {
82
+ action(value);
83
+ return value;
84
+ };
82
85
  }
83
86
  /**
84
87
  * Helper utility intended to be used with typed exceptions and .catch() method of promise like so:
@@ -96,28 +99,29 @@ export function tap(action) {
96
99
  * @returns handler which either forwards to catcher or rethrows
97
100
  */
98
101
  export function ofClass(cls, catcher) {
99
- return async e => {
100
- if (e instanceof cls) {
101
- return catcher(e)
102
- } else {
103
- // It's okay to rethrow because:
104
- // 1. It preserves the original stacktrace
105
- // 2. Because of 1. it is not that expensive
106
- throw e
107
- }
108
- }
102
+ return async (e) => {
103
+ if (e instanceof cls) {
104
+ return catcher(e);
105
+ }
106
+ else {
107
+ // It's okay to rethrow because:
108
+ // 1. It preserves the original stacktrace
109
+ // 2. Because of 1. it is not that expensive
110
+ throw e;
111
+ }
112
+ };
109
113
  }
110
114
  /**
111
115
  * Filter iterable. Just like Array.prototype.filter but callback can return promises
112
116
  */
113
117
  export async function promiseFilter(iterable, filter) {
114
- let index = 0
115
- const result = []
116
- for (let item of iterable) {
117
- if (await filter(item, index)) {
118
- result.push(item)
119
- }
120
- index++
121
- }
122
- return result
118
+ let index = 0;
119
+ const result = [];
120
+ for (let item of iterable) {
121
+ if (await filter(item, index)) {
122
+ result.push(item);
123
+ }
124
+ index++;
125
+ }
126
+ return result;
123
127
  }