https://github.com/watchdg/node-result
https://github.com/watchdg/node-result
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/watchdg/node-result
- Owner: WatchDG
- License: mit
- Created: 2020-06-27T01:22:38.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-07T00:03:13.000Z (over 3 years ago)
- Last Synced: 2025-02-01T00:25:38.702Z (over 1 year ago)
- Language: TypeScript
- Size: 60.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-result
## install
```shell
npm install node-result
# or
yarn add node-result
```
## example
```ts
import { ok, fail } from "node-result";
async function checker(data: any) {
try {
if (typeof data !== 'string') {
return fail(void 0);
}
return ok(null);
} catch (error) {
return fail(error);
}
}
(async () => {
(await checker('foo')); // return Result
(await checker(5)); // return Result
(await checker('bar')); // return Result
(await checker('foo')).unwrap(); // return null
(await checker(5)).unwrap(); // throw undefined
(await checker('bar')).unwrap(); // not done
})();
```