node-result
install
npm install node-result
# or
yarn add node-result
example
import {ResultOk, ResultFail} from "node-result";
async function checkIfNotString(data: any) {
try {
if (typeof data !== 'string') {
return ResultFail(void 0);
}
return ResultOk(null);
} catch (error) {
return ResultFail(error);
}
}
(async () => {
(await checkIfNotString('foo'));
(await checkIfNotString(5));
(await checkIfNotString('bar'));
(await checkIfNotString('foo')).unwrap();
(await checkIfNotString(5)).unwrap();
(await checkIfNotString('bar')).unwrap();
})();