promison
Version:
await json promise data
14 lines (11 loc) • 390 B
JavaScript
module.exports = async function promison (json) {
function isPromise(obj) {
return !!obj && (obj instanceof Object || obj instanceof Function) && obj.then instanceof Function;
}
for (const key in json) {
if (isPromise(json[key])) json[key] = await json[key];
else if (json[key] instanceof Object) json[key] = await promison(json[key]);
}
return json
}