node-result
TypeScript icon, indicating that this package has built-in type declarations

13.0.0 • Public • Published

node-result

install

npm install node-result
# or
yarn add node-result

example

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
})();

Readme

Keywords

Package Sidebar

Install

npm i node-result

Weekly Downloads

5

Version

13.0.0

License

MIT

Unpacked Size

7.47 kB

Total Files

5

Last publish

Collaborators

  • watchdg