-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.d.ts
68 lines (60 loc) · 2.22 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
import {type Options} from 'p-map';
export type Mapper<ValueType, KeyType, MappedValueType> = (
value: ValueType,
key: KeyType
) => MappedValueType | PromiseLike<MappedValueType>;
/**
Like [`Promise.all()`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise/all) but for `Map` and `Object`.
@param map - Resolves entry values that are promises. Other values are passed through.
@param mapper - Receives the current value and key as parameters. Expected to return a `Promise` or value.
@param options - See the [`p-map` options](https://github.com/sindresorhus/p-map#options).
@returns A promise that is fulfilled when all promises in `map` and ones returned from `mapper` are fulfilled, or rejects if any of the promises reject. The fulfilled value is the same as `map`, but with a fulfilled version of each entry value, or the fulfilled value returned from `mapper`, if defined.
@example
```
import pProps from 'p-props';
import got from 'got';
const fetch = async url => {
const {body} = await got(url);
return body;
};
const sites = {
ava: fetch('https://avajs.dev'),
todomvc: fetch('https://todomvc.com'),
github: fetch('https://github.com'),
foo: 'bar'
};
console.log(await pProps(sites));
// {
// ava: '<!doctype …',
// todomvc: '<!doctype …',
// github: '<!doctype …',
// foo: 'bar'
// }
```
*/
export default function pProps< // This overload exists to get more accurate results when the mapper is not defined.
InputType extends Record<PropertyKey, unknown>,
>(
map: InputType,
mapper?: undefined,
options?: Options
): Promise<{[key in keyof InputType]: Awaited<InputType[key]>}>;
export default function pProps<
InputType extends Record<string, unknown>,
ValueType extends InputType[keyof InputType],
MappedValueType = Awaited<ValueType>,
>(
map: InputType,
mapper?: Mapper<Awaited<ValueType>, keyof InputType, MappedValueType>,
options?: Options
): Promise<{[key in keyof InputType]: MappedValueType}>;
export default function pProps<
KeyType,
ValueType,
MappedValueType = Awaited<ValueType>,
>(
map: ReadonlyMap<KeyType, ValueType>,
mapper?: Mapper<Awaited<ValueType>, KeyType, MappedValueType>,
options?: Options
): Promise<Map<KeyType, MappedValueType>>;
export {Options} from 'p-map';