unwrap-or
TypeScript icon, indicating that this package has built-in type declarations

0.1.4-beta • Public • Published

Unwrap OR

A TypeScript implementation of Rust's Option and Result types.

no deps | tree-shakeable | side-effect free | < 1KB gzipped

Workflow CI Release version License MIT

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.

Installation

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

Overview

See the documentation for unwrap-or usage and API details.

Inspirations

  • 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.

License

Made by a human being, not LLM.

Copyright © 2025 Roman Hnatiuk

Licensed under MIT.

Package Sidebar

Install

npm i unwrap-or

Weekly Downloads

239

Version

0.1.4-beta

License

MIT

Unpacked Size

37.8 kB

Total Files

9

Last publish

Collaborators

  • hnatiukr