UNPKG

@loopback/docs

Version:

Documentation files rendered at [https://loopback.io](https://loopback.io)

99 lines (54 loc) 2.3 kB
--- lang: en title: 'API docs: context.resolvemap' keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI sidebar: lb4_sidebar editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/context permalink: /doc/en/lb4/apidocs.context.resolvemap.html --- <!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@loopback/context](./context.md) &gt; [resolveMap](./context.resolvemap.md) ## resolveMap() function Resolve entries of an object into a new object with the same keys. If one or more entries of the source object are resolved to a promise by the `resolver` function, this method returns a promise which will be resolved to the new object with fully resolved entries. **Signature:** ```typescript export declare function resolveMap<T, V>(map: MapObject<T>, resolver: (val: T, key: string, values: MapObject<T>) => ValueOrPromise<V>): ValueOrPromise<MapObject<V>>; ``` ## Parameters <table><thead><tr><th> Parameter </th><th> Type </th><th> Description </th></tr></thead> <tbody><tr><td markdown="1"> map </td><td markdown="1"> [MapObject](./context.mapobject.md)<!-- -->&lt;T&gt; </td><td markdown="1"> The original object containing the source entries </td></tr> <tr><td markdown="1"> resolver </td><td markdown="1"> (val: T, key: string, values: [MapObject](./context.mapobject.md)<!-- -->&lt;T&gt;) =&gt; [ValueOrPromise](./context.valueorpromise.md)<!-- -->&lt;V&gt; </td><td markdown="1"> A function resolves an entry to a value or promise. It will be invoked with the property value, the property name, and the source object. </td></tr> </tbody></table> **Returns:** [ValueOrPromise](./context.valueorpromise.md)<!-- -->&lt;[MapObject](./context.mapobject.md)<!-- -->&lt;V&gt;&gt; ## Example - Example 1: resolve all entries synchronously ```ts const result = resolveMap({a: 'x', b: 'y'}, v => v.toUpperCase()); ``` The `result` will be `{a: 'X', b: 'Y'}`<!-- -->. - Example 2: resolve one or more entries asynchronously ```ts const result = resolveMap({a: 'x', b: 'y'}, v => Promise.resolve(v.toUpperCase()), ); ``` The `result` will be a promise of `{a: 'X', b: 'Y'}`<!-- -->.