1.0.0 • Published 9 years ago
try-expression v1.0.0
try-expression
JavaScript's try statement as an expression.
Install
npm install --save try-expressionUse
Try some code out and deal with an error, like try-catch:
import tryy from "try-expression";
const result = tryy(
  () => doRiskyThing(),
  error => {
    logError(error);
    return 'Sorry!';
  }
); // => 'Sorry!'Fall back to a value if there's an error:
import tryy from "try-expression";
const config = tryy(
  () => loadConfig(),
  { squibbles: 4 }
); // => { squibbles: 4 }Run some code to clean up, like try-catch-finally:
import tryy from "try-expression";
const result = tryy(
  () => ['Success', readFile()],
  err => ['Failure', err],
  () => closeFile()
); // => ['Failure', err]Note that, to avoid confusing JavaScript behaviour you cannot return a value from finally.
Development
$ npm install
$ npm testCommit messages should follow the Angular commit message guidelines.
Release
This repository uses semantic-release. Changes will automatically be released to npm.
1.0.0
9 years ago