UNPKG

@bredele/reconcile

Version:

Reconcile data from multiple async sources.

19 lines (18 loc) 634 B
export default async function reconcile(sources) { const results = await Promise.allSettled(sources.map((source)=>source())); const result = {}; for(let i = results.length - 1; i >= 0; i--){ if (results[i].status === 'fulfilled') { const data = results[i].value; if (data && typeof data === 'object') { for(const key in data){ if (data.hasOwnProperty(key) && data[key] != null) { result[key] = data[key]; } } } } } return result; } //# sourceMappingURL=index.js.map