Result is a small, dependency-free set of TypeScript helpers for explicit failures and plain absence. It uses discriminated unions, so checking result.ok narrows the value without a cast.
Pin the repository to an immutable version tag:
{
"dependencies": {
"@cclrte/result": "github:hraness/result#v0.1.0"
}
}Then install with Bun:
bun installimport { err, ok, type Result } from "@cclrte/result";
function parsePort(value: string): Result<number, "invalid port"> {
const port = Number(value);
return Number.isInteger(port) && port > 0 && port <= 65_535
? ok(port)
: err("invalid port");
}
const result = parsePort("3000");
if (result.ok) {
console.log(result.value);
} else {
console.error(result.error);
}Result<T, E> represents success or failure. Option<T> represents a value or null; it does not include undefined.
The package also exports Ok, Err, isOk, isErr, unwrapOr, mapOk, isRecord, and assertNever.
The package is ESM-only. Its committed JavaScript runs in Bun and modern Node.js projects; TypeScript reads the matching source types.
Read CONTRIBUTING.md before opening a pull request.
Report suspected vulnerabilities privately as described in SECURITY.md.
MIT