-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.d.ts
87 lines (71 loc) · 2.21 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import type {Options} from 'p-map';
/**
Filter promises concurrently.
@param input - Iterated over concurrently in the `filterer` function.
@param filterer - The filterer function that decides whether an element should be included into result.
@example
```
import pFilter from 'p-filter';
import getWeather from 'get-weather'; // Not a real module
const places = [
getCapital('Norway').then(info => info.name),
'Bangkok, Thailand',
'Berlin, Germany',
'Tokyo, Japan',
];
const filterer = async place => {
const weather = await getWeather(place);
return weather.temperature > 30;
};
const result = await pFilter(places, filterer);
console.log(result);
//=> ['Bangkok, Thailand']
```
*/
export default function pFilter<ValueType>(
input: Iterable<ValueType | PromiseLike<ValueType>>,
filterer: (
element: ValueType,
index: number
) => boolean | PromiseLike<boolean>,
options?: Options
): Promise<ValueType[]>;
/**
Filter promises concurrently.
@param input - Iterated over concurrently in the `filterer` function.
@param filterer - The filterer function that decides whether an element should be included into result.
@param options - See the [`p-map` options](https://github.com/sindresorhus/p-map#options).
@returns An async iterable that iterates over the promises in `iterable` and ones returned from `filterer` concurrently, calling `filterer` for each element.
@example
```
import {pFilterIterable} from 'p-filter';
import getWeather from 'get-weather'; // Not a real module
async function * getPlaces() {
const name = await getCapital('Norway');
yield name;
yield 'Bangkok, Thailand';
yield 'Berlin, Germany';
yield 'Tokyo, Japan';
}
const places = getPlaces();
const filterer = async place => {
const weather = await getWeather(place);
return weather.temperature > 30;
};
for await (const element of pFilterIterable(places, filterer)) {
console.log(element);
}
//=> ['Bangkok, Thailand']
```
*/
export function pFilterIterable<ValueType>(
input:
| AsyncIterable<ValueType | PromiseLike<ValueType>>
| Iterable<ValueType | PromiseLike<ValueType>>,
filterer: (
element: ValueType,
index: number
) => boolean | PromiseLike<boolean>,
options?: Options
): AsyncIterable<ValueType>;
export {Options} from 'p-map';