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

1.1.0 • Public • Published

@kizahasi/result

GitHub npm version minified size CI publish

Represents a value which is either OK or error.

Installation

Run npm install @kizahasi/result or yarn add @kizahasi/result

Usage

import { Result } from '@kizahasi/result';

const okObj = Result.ok(1); // Creates an "ok" object
// const okObj: Result<number> = { isError: false, value: 1 }; // …or you can create the object like this instead
if (okObj.isError) {
    console.log(okObj.error); // This cannot happen
} else {
    console.log(okObj.value); // output: 1
}

const errorObj = Result.error('ERROR!'); // Creates an "error" object
// const errorObj: Result<ANY-VALUE-TYPE> = { isError: true, error: 'ERROR!' }; // …or you can create the object like this instead
if (errorObj.isError) {
    console.log(errorObj.error); // output: ERROR!
} else {
    console.log(errorObj.value); // This cannot happen
}

Readme

Keywords

none

Package Sidebar

Install

npm i @kizahasi/result

Weekly Downloads

426

Version

1.1.0

License

MIT

Unpacked Size

8.67 kB

Total Files

6

Last publish

Collaborators

  • kizahasi