1.0.0 • Published 4 years ago
@kherge/result v1.0.0
Result
A zero dependencies library for bringing Rust's Option<T> and Result<T, E> to TypeScript.
Installation
npm install @kherge/resultExample
import { Option, Result, err, none, ok, some } from '@kherge/result';
// Using Option<T>.
let option: Option<string>;
option = some('My string.');
console.log(option.unwrap()); // My string.
option = none();
console.log(option.unwrap()); // throws error
// Using Result<T, E>.
let result: Result<string, number>;
result = ok('My string.');
console.log(result.unwrap()); // My string.
result = err(123);
console.log(result.unwrap()); // throws errorDocumentation
Please see the GitHub Pages site for documentation.
Development
Created using TSDX.
Requirements
- NPM
Development can be started after installing the development dependencies.
npm installBuilding
npm run buildBuilds to the dist/ folder.
npm run build:docsBuilds the documentation to the docs/ folder.
Unit Testing
npm testYou can also run
npm run test:watchto use interactive watch mode.