JSPM

@zambit/elevate-ts

0.4.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 12
  • Score
    100M100P100Q95699F
  • License AGPL-3.0-or-later

Functional programming library for TypeScript. Available under AGPL-3.0 or Commercial License.

Package Exports

  • @zambit/elevate-ts
  • @zambit/elevate-ts/Audit
  • @zambit/elevate-ts/Either
  • @zambit/elevate-ts/EitherAsync
  • @zambit/elevate-ts/Function
  • @zambit/elevate-ts/HTTP
  • @zambit/elevate-ts/List
  • @zambit/elevate-ts/Maybe
  • @zambit/elevate-ts/MaybeAsync
  • @zambit/elevate-ts/NonEmptyList
  • @zambit/elevate-ts/Reader
  • @zambit/elevate-ts/State
  • @zambit/elevate-ts/Tuple
  • @zambit/elevate-ts/Validation

Readme

elevate-ts

Coverage npm License: AGPL%20v3%2B

Point-free, data-last functional programming for TypeScript. Fantasy Land 5 compliant. Zero dependencies. Cloudflare Workers ready.

Install

pnpm add @zambit/elevate-ts

Philosophy

  • Point-free: Functions are composed by shape, not by naming intermediate values
  • Data-last: Configuration arguments precede the data being transformed
  • Pure: No classes, no mutations, ≤15 lines per function
  • Cloudflare Workers: No Node.js built-ins, no DOM APIs
  • Fantasy Land 5: All applicable types implement the spec
  • Zero runtime dependencies: Ship only pure TypeScript

Quick Start

import { pipe } from '@zambit/elevate-ts/Function';
import { Just, Nothing, map, chain } from '@zambit/elevate-ts/Maybe';

// When condition is met
const result1 = pipe(
  Just(5),
  map((a) => a * 2), // Just(10)
  chain((b) => (b > 5 ? Just(b) : Nothing)) // Just(10)
);

// When condition fails
const result2 = pipe(
  Just(2),
  map((a) => a * 2), // Just(4)
  chain((b) => (b > 5 ? Just(b) : Nothing)) // Nothing
);

Modules

Module Description
Maybe Optional values; Functor, Applicative, Monad, Alt, Filter
Either Values with a Left error branch; Bifunctor, Monad, Alt
Validation Functor for collecting all errors during applicative (not short-circuit)
Reader Dependency injection / environment access; Monad
State Pure stateful computation; track state through a sequence of operations
Tuple Immutable 2-tuple; Bifunctor, Monoid
NonEmptyList Guaranteed-nonempty array; Functor, Applicative, Monad, Monoid
List Utilities over plain readonly arrays; map, filter, partition, zip, etc.
Function Function composition and utilities; pipe, flow, curry, memoize, once, tap
MaybeAsync Lazy async Maybe; rejects or throws become Nothing; never rejects
EitherAsync Lazy async Either; rejects become Left; never throws
Audit Operation tracking with time-travel replay; configurable ID generation
HTTP CloudFlare Workers & Web Fetch API helpers; safe JSON, env, error mapping

Quick API Reference

Browse the complete API reference → for all functions and types.

Maybe

Just(value) | Nothing
map(f) | chain(f) | getOrElse(default)
fromNullable(a) | filter(predicate) | fold(onNothing, onJust)

Either

Left(error) | Right(value)
map(f) | mapLeft(f) | bimap(f, g) | chain(f)
getOrElse(default) | fold(onLeft, onRight)
fromPredicate(p, onFalse) | tryCatch(f, onError)

Validation

Failure(errors) | Success(value);
ap(vf) | chain(f) | fold(onFailure, onSuccess);
fromEither(ea) | sequence(validations);

Reader

Reader(run) | ask() | asks(f) | local(f);
map(f) | chain(f) | runReader(env);

State

State(run) | get() | put(s) | modify(f) | gets(f);
map(f) | chain(f);
runState(s) | evalState(s) | execState(s);

Tuple

Tuple(fst, snd);
fst | snd | mapFst(f) | mapSnd(f) | bimap(f, g) | swap();
fanout(f, g);

NonEmptyList

fromArray(arr) | fromArrayUnsafe(arr);
head(nel) | tail(nel) | last(nel) | init(nel);
map(f) | chain(f) | concat(nel2);

List

head(arr) | tail(arr) | take(n) | drop(n);
partition(p) | groupBy(eq) | sortBy(ord);
zip(arr2) | zipWith(f) | flatten();

Function

identity | constant(a) | flip(f)
pipe(a, f1, f2, ...) | flow(f1, f2, ...)
curry2(f) | curry3(f) | curry4(f)
memoize(f) | once(f) | tap(f)

MaybeAsync

MaybeAsync(run) | liftMaybe(ma)
of(value) | nothing()
map(f) | chain(f) | getOrElse(default)
fromPromise(p) | tryCatch(f)
fold(onNothing, onJust) | toEitherAsync(onNothing)

EitherAsync

EitherAsync(run) | liftEither(ea)
of(value) | right(value) | left(error)
map(f) | mapLeft(f) | chain(f)
getOrElse(default) | fold(onLeft, onRight)
fromPromise(p, onError) | tryCatch(f, onError)
toMaybeAsync(ea)

Audit

createSession(opts) | withEnabled(bool) | withCaptureInputs(bool);
track(op, fn) | record(op, result) | getLog() | replay(index);
filterByOperation(op) | filterByMonadType(monad) | entryAt(index);

See docs/AUDIT.md for comprehensive guide with worked examples (simple, medium, complex scenarios).

HTTP

jsonResponse(status) | parseJSON(raw) | askEnv(key) | requireEnv(key);
withStatusCode(codes) | handleEither(onL, onR) | handleEitherAsync(onL, onR);

See docs/HTTP.md for comprehensive guide with CloudFlare Workers examples (simple, medium, complex scenarios).

Learning & Examples

  • elevate-ts-learning - Comprehensive tutorial with interactive todo app and 4 learning guides
  • elevate-ts-samples - Production-ready examples (form validation, state management, list operations, workers)

Contributing

See CONTRIBUTING.md for details on how to contribute. Non-trivial contributions must be covered by the applicable contributor license agreement: CLA-INDIVIDUAL.md or CLA-CORPORATE.md.

License

Dual-licensed:

  • Public license: GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later). See LICENSE.
  • Commercial license: available from Zambit for customers who want to use elevate-ts in closed-source products or services. See COMMERCIAL-LICENSE.md.