Result
A zero dependencies library for bringing Rust's Option<T>
and Result<T, E>
to TypeScript.
Installation
npm install @kherge/result
Example
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 error
Documentation
Please see the GitHub Pages site for documentation.
Development
Created using TSDX.
Requirements
- NPM
Development can be started after installing the development dependencies.
npm install
Building
npm run build
Builds to the dist/
folder.
npm run build:docs
Builds the documentation to the docs/
folder.
Unit Testing
npm test
You can also run
npm run test:watch
to use interactive watch mode.