A TypeScript implementation of Rust's Option and Result types.
no deps | tree-shakeable | side-effect free | < 1KB gzipped
It is a playground library that closely mirrors Rust's Option and Result API. While created primarily for fun and learning, it's robust enough for real-world applications. It allows for safer, more expressive handling of optional values through a monadic interface. Snake_case is used for the plausibility of the original.
Use it to:
- eliminate
null
checks - make optional logic explicit
- chain transformations on values that might not exist
- handle errors gracefully
The name unwrap-or
is a playful reference to both the unwrap_or
method found in the Option
/Result
types, and a hint at the package's contents - "-OR" standing for Option and Result types. It also cleverly references the logical OR
operation, reflecting how these monadic types encapsulate one of two possible states - either Some
or None
for Option
; either Ok
or Err
for Result
.
Via npm:
npm install unwrap-or
You can also use your favorite package manager:
# pnpm
pnpm add unwrap-or
# bun
bun add unwrap-or
# yarn
yarn add unwrap-or
# deno
deno add npm:unwrap-or
See the documentation for unwrap-or usage and API details.
-
fnts - minimal functional programming utilities for TypeScript & JavaScript inspired by the programming language Haskell.
-
ts-expression - pair constructor, binary representation, a minimal implementation of
Lisp
's symbolic expressions (s-expressions
) for TypeScript.
Made by a human being, not LLM.
Copyright © 2025 Roman Hnatiuk
Licensed under MIT.