@kherge/result
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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.

Package Sidebar

Install

npm i @kherge/result

Weekly Downloads

82

Version

1.0.0

License

MIT

Unpacked Size

201 kB

Total Files

43

Last publish

Collaborators

  • kherge