@nkp/result
Minimal zero dependency utility library for the Result type. Result represents the output of an operation that either succeded or failed.
import { Result } from '@nkp/result';
function work(): Result<number, string> {
const input = 'this is user input';
if (input.length >= 5){
return Result.err('input must be less-than 5 characters long');
}
return Result.ok(input.length);
}
const result = work();
if (Result.isOk(result)) {
const success: number = reuslt.value;
}
if (Result.isErr(result)) {
const message: string = result.value;
}
Table of contents
Exports
@nkp/result
exports both CommonJS and ES modules.
Installation
npm
npm install @nkp/result
yarn
yarn add @nkp/result
pnpm
pnpm add @nkp/result
Publishing
To a release a new version:
- Update the version number in package.json
- Push the new version to the
master
branch on GitHub - Create a
new release
on GitHub for the latest version
This will trigger a GitHub action that tests and publishes the npm package.