npm.io
13.0.0 • Published 3 years ago

node-result

Licence
MIT
Version
13.0.0
Deps
0
Size
7 kB
Vulns
0
Weekly
0
Stars
1

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

Keywords