by mnr · 8y ago · 0 comments
Example:
const lines = (await fetch(myUrl)).text().split('\n');
[1] http://vanilla-js.com/Edit: magic-promises promotes all accessed properties to magic-promises as well, and performs magic on functions, so it's not exactly the same, but I'm not sure if I'd want to add the proxy overhead to my code just to make my code more "fluent".
With magic-promises you don't need to worry about whether something regurns a promise or not. See fs-array, some methods will return promises and some won't, but you can just treat them all the same.
const lines = (await (await fetch(myUrl)).text()).split('\n'); function fetchText(input?: string | Request, init?: RequestInit) {
return fetch(input, init).then(x => x.text())
}
function fetchJson(input?: string | Request, init?: RequestInit) {
return fetch(input, init).then(x => x.json())
}