@resulted/results
v1.0.0
Published
A TypeScript library for handling results and errors in a functional programming style.
Maintainers
Readme
@resulted/results
A TypeScript library for handling results and errors in a functional programming style.
Installation
NPM:
npm install @resulted/results
yarn add @resulted/results
pnpm add @resulted/resultsJSR:
deno add jsr:@resulted/results
pnpm add jsr:@resulted/resultsUsage
import { Result } from '@resulted/results';
function divide(a: number, b: number): Result<number, 'ZeroDivisionError'> {
if (b === 0) {
return Result.err('ZeroDivisionError');
}
return Result.ok(a / b);
}
function doMath(): Result<number, 'DivisionError'> {
const randomNum = Math.floor(Math.random() * 10);
return divide(10, randomNum).mapErr(() => 'DivisionError');
}
function main() {
const result = doMath();
if (result.isOk()) {
console.log('Result:', result.value);
} else {
console.error('Error:', result.error);
}
}Contributing
Contributions are welcome! This project uses pnpm as its package manager.
Setup
git clone https://github.com/resulted-io/results.git
cd results
pnpm installScripts
pnpm run build: Build CJS and ESM outputspnpm run typecheck: Run TypeScript type checkingpnpm run lint: Run Biome linterpnpm run format: Auto-fix lint and formatting issues
Submitting Changes
- Fork the repository and create a feature branch.
- Make your changes and ensure
pnpm run lintandpnpm run typecheckpass. - Open a pull request with a clear description of your changes.
License
This project is licensed under the ISC License. See LICENSE.md for details.
