Warning
The unwrap-or library has moved off Github.
The canonical Git repository is located at https://codeberg.org/hnatiukr/unwrap-or.
There is a mirror of the repository at https://github.com/hnatiukr/unwrap-or.
A TypeScript implementation of Rust's Option and Result types.
no deps | tree-shakeable | side-effect free
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
nullchecks - make optional logic explicit
- chain transformations on values that might not exist
- handle errors gracefully
The name unwrap-or is a reference to the unwrap_or method in the
Option/Result types and a combination of the first letters "-OR" of two
monads for Option and Result types. It also relfects the logical OR
operation reflecting two possible states.
Via deno:
deno add jsr:@lab/unwrap-orYou can also use your favorite package manager:
# pnpm
pnpm i jsr:@lab/unwrap-or
# npm
npx jsr add @lab/unwrap-or
# bun
bunx jsr add @lab/unwrap-or
# yarn
yarn add jsr:@lab/unwrap-orSee the documentation for unwrap-or usage, module specifications and API/methods 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.