KrustyKrab provides idiomatic implementations of Rust's `Option` and `Result` types, along with several utility functions inspired by Rust's standard library, for JavaScript and TypeScript projects. It aims to enhance error handling and null safety by introducing concepts like explicit handling of present/absent values and success/failure states. The current stable version is 1.1.0. As a relatively new library focused on bringing Rust paradigms to TypeScript, its release cadence is likely driven by feature additions and improvements rather than a fixed schedule. Key differentiators include its faithful adaptation of `Option` and `Result` with methods like `unwrap`, `unwrapOr`, `map`, and `andThen`, as well as practical utilities such as `getResult` for converting Promises, `toOption` for nullable conversions, and `tryCatch` for wrapping synchronous operations in `Result` types. This approach encourages more robust, explicit, and functional error management compared to traditional try-catch blocks and null checks.
npm install krustykrabVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the core `Option` and `Result` types, along with key utilities like `unwrap`, `getResult`, and `tryCatch`, showcasing their usage for null safety and robust error handling in TypeScript.
Prefer `unwrapOr(defaultValue)` or conditional checks like `if (option.isSome()) { option.unwrap(); }` to safely access values, or use `map()` and `andThen()` for chained operations.Integrate KrustyKrab into a TypeScript project and ensure your `tsconfig.json` enables strict null checks (`strictNullChecks: true`) for optimal type safety.
Ensure the `Option` is `Some` before calling `unwrap()` using `isSome()`, or use safer alternatives like `unwrapOr(defaultValue)`, `map()`, or `andThen()`.
Check if the `Result` is `Ok` using `isOk()` before calling `unwrap()`, or handle the error gracefully using `unwrapOr(defaultValue)`, `mapErr()`, or `andThen()`.
No dependency data recorded yet.