@await-to/chainable
v2.0.0
Published
## Install
Downloads
9
Readme
@await-to/chainable
Install
npm i @await-to/chainable
Example
import { to, OkResult } from '@await-to/chainable';
const result = await to(Promise.resolve({ test: 123 }))
.and((result) => {
if (!result.ok) return result;
return OkResult(result.data.text);
})
// Also supports chaining async functions
.and(async (result) => {
if (!result.ok) return result;
return OkResult(Number(result.data.text));
})
.get();
if (result.ok) {
result.data; // data is number
}