* @param {!(Array|Object)} obj the object to resolve. * @return {!Thenable} A promise that will be resolved with the * input object once all of its values have been fully resolved.
(obj)
| 224 | * input object once all of its values have been fully resolved. |
| 225 | */ |
| 226 | async function fullyResolveKeys(obj) { |
| 227 | const isArray = Array.isArray(obj) |
| 228 | const numKeys = isArray ? obj.length : Object.keys(obj).length |
| 229 | |
| 230 | if (!numKeys) { |
| 231 | return obj |
| 232 | } |
| 233 | |
| 234 | async function forEachProperty(obj, fn) { |
| 235 | for (let key in obj) { |
| 236 | await fn(obj[key], key) |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | async function forEachElement(arr, fn) { |
| 241 | for (let i = 0; i < arr.length; i++) { |
| 242 | await fn(arr[i], i) |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | const forEachKey = isArray ? forEachElement : forEachProperty |
| 247 | await forEachKey(obj, async function (partialValue, key) { |
| 248 | if (!Array.isArray(partialValue) && (!partialValue || typeof partialValue !== 'object')) { |
| 249 | return |
| 250 | } |
| 251 | obj[key] = await fullyResolved(partialValue) |
| 252 | }) |
| 253 | return obj |
| 254 | } |
| 255 | |
| 256 | // PUBLIC API |
| 257 |
no test coverage detected