purify-ts

Functional programming standard library for TypeScript with Maybe, Either, and Codec

Library
npm
v2.1.4
1,603stars
ISC

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
46/100Fair
Development Activity0
Maintenance32
Community52
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
86/100Excellent
Architecture86
Code Quality90
Innovation84
Learning Curve62

purify-ts is a functional programming standard library for TypeScript that brings popular patterns from functional languages to everyday TypeScript code. It provides algebraic data types like Maybe, Either, and their async variants, plus List helpers, NonEmptyList, Tuple, and a Codec module for type-safe decoding.

Designed around developer experience and type safety, purify-ts is Fantasy Land conformant and works in vanilla JavaScript as well. Rather than changing how you write TypeScript, it offers composable tools that make handling optional values, errors, and data validation more explicit and maintainable.

What You Get

  • Maybe and Either types for modeling optional values and typed errors
  • Async counterparts MaybeAsync and EitherAsync for promise-based flows
  • A Codec module for type-safe encoding, decoding, and validation
  • List, NonEmptyList, and Tuple helpers for functional data handling
  • Fantasy Land conformance and full TypeScript type definitions

Common Use Cases

  • Replacing null and undefined checks with explicit Maybe handling
  • Modeling operations that can fail using Either instead of thrown exceptions
  • Decoding and validating API responses into typed values with Codec
  • Composing async success/failure flows with EitherAsync

Under The Hood

Architecture — Each abstraction lives in its own module under src/ (Maybe.ts, Either.ts, MaybeAsync.ts, EitherAsync.ts, Codec.ts, List.ts, NonEmptyList.ts, Tuple.ts, Function.ts) and is re-exported from index.ts. The data types are implemented as small tagged objects carrying map/chain/etc. methods that conform to the Fantasy Land algebraic specifications, while Codec builds composable decoders that produce Either results, so validation reuses the same error-handling primitives.

Tech Stack — Written entirely in TypeScript and compiled to both CommonJS and ESM outputs (tsconfig.json and tsconfig.esm.json). The only runtime dependency is @types/json-schema (used by Codec’s JSON Schema support); tooling includes Vitest with v8 coverage, Prettier, and AJV in tests.

Code Quality — The project is thoroughly tested: every module ships a co-located *.test.ts file and coverage is tracked via Coveralls. Strict TypeScript, Prettier formatting, and a clean one-module-per-concept layout make the code approachable and the abstractions easy to reason about.

API Design — DX is an explicit design goal: the API stays close to idiomatic TypeScript, method names (map, chain, caseOf, decode) follow familiar functional conventions, and a dedicated documentation site with per-type references supports learning. The main cost is conceptual — developers new to Maybe/Either and Fantasy Land face a real functional-programming learning curve despite the friendly surface.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search