Introduction
Massaman is a Rust-inspired utility library for functional programming in JavaScript, with first-class TypeScript support. It favors pure functions, immutable data, function composition, errors returned as values, and pattern matching that handles every case.
What is Massaman?
Massaman provides a broad set of utilities for transforming data, composing functions, handling failure, and branching on values. Its API is ESM-native, tree-shakeable, and available from either one flat import surface or focused subpaths.
Much of the general utility surface comes from es-toolkit. Exhaustive pattern matching is powered by ts-pattern. Massaman connects those foundations and adds the pieces needed for a consistent functional programming model:
Resultvalues and helpers for explicit failureP.okandP.errpatterns for matchingResult- synchronous and asynchronous function composition
- branching and predicate combinators
- immutable collection and object transformations
- consistent coercion and error normalization
The goal is practical functional programming that still feels like JavaScript.
Why does it exist?
I built Massaman around two Rust patterns I kept wanting in TypeScript: exhaustive match expressions and Result values for expected failure. From there, the library grew into the small set of functional utilities I wanted those patterns to compose with.
JavaScript supports many programming styles but provides few defaults for how an application should be structured. A codebase can easily accumulate mutable helpers, inconsistent error handling, hidden state, nested conditional logic, and slightly different versions of the same utility.
Modern languages such as Rust provide stronger defaults. Massaman's maintainers prefer that more functional model:
- expected failures are represented in return values
- branching can be exhaustive
- mutation is deliberate rather than incidental
- small functions compose into larger operations
- state and side effects remain explicit
Massaman brings those Rust and functional programming ideas to JavaScript. Its TypeScript APIs preserve types through transformations, narrow values as they are matched, and report unhandled cases during type checking.
This does not mean reimplementing good tools. ts-pattern provides pattern matching, and es-toolkit provides most of the general utilities. Massaman gives them a shared surface, adds the missing pieces, and applies one set of conventions across the API.
If all you need is es-toolkit or ts-pattern, use it directly. Massaman is for codebases that want the broader utility surface and the programming model that connects it.
Similar projects
Effectprovides a full effect system and standard library; Massaman is smaller and uses ordinary functions and promises.es-toolkitandts-patternprovide Massaman's utility and pattern-matching foundations and can also be used directly.Ramda,Remeda, andLodash/fpfocus on functional data utilities.neverthrow, True Myth, andoxide.tsprovideResult-style APIs for typed failure.fp-tsand Purify provide typed functional data types and abstractions.
What does the API look like?
The difference is easiest to see in error handling. Assume fetchUser() throws a Response for HTTP failures. Both examples load the same user and produce the same message, but Massaman turns failure into a value while plain JavaScript handles the exception manually.
Massaman returns failure as data, so every match arm produces message directly. There is no exception-driven mutation to track.
What should I do next?
- Install Massaman — add the package and configure JavaScript or TypeScript.
- Read the philosophy — understand the programming model behind the API.
- Learn the core concepts — start with Result & Errors, Pattern Matching, and Composition.
- Browse the reference — find an exact function, type, or subpath.