npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

literium-base

v0.2.4

Published

Core types and functions widely used by Literium web-application framework.

Readme

Useful core types and functions

npm version npm downloads Build Status

This project is part of Literium WEB-framework but can be used standalone.

Types

Keyed<Key, Value>

A key-value pair for using as an enumerated (algebraic) type.

interface Keyed<Key, Value> { $: Key; _: Value; }
function keyed<Key, Value>($: Key, _: Value): Keyed<Key, Value>;
function to_keyed<Key>($: Key): <Value>(_: Value) => Keyed<Key, Value>;
function map_key<Key, NewKey>(fn: ($: Key) => NewKey): <Value>(_: Keyed<Key, Value>) => Keyed<NewKey, Value>;
function map_value<Value, NewValue>(fn: (_: Value) => NewValue): <Key>(_: Keyed<Key, Value>) => Keyed<Key, NewValue>;
function un_key<Key, Value>(v: Keyed<Key, Value>): Key;
function un_value<Key, Value>(v: Keyed<Key, Value>): Value;

Option<Value>

An Option type makes some value to be optional, i.e. it can hold some value or none. This type is preferred to use instead of special values like null or undefined.

type Option<Value> = Some<Value> | None;
function some<Value>(_: Value): Option<Value>;
function none<Value>(): Option<Value>;
function is_some<Value>(o: Option<Value>): o is Some<Value>;
function is_none<Value>(o: Option<Value>): o is None;
function then_some<Value, NewValue>(fn: (_: Value) => Option<NewValue>): (_: Option<Value>) => Option<NewValue>;
function then_none<Value>(fn: () => Option<Value>): (_: Option<Value>) => Option<Value>;
function map_some<Value, NewValue>(fn: (_: Value) => NewValue): (_: Option<Value>) => Option<NewValue>;
function map_none(fn: () => void): <Value>(o: Option<Value>) => Option<Value>;
function and_some<NewValue>(v: NewValue): <Value>(o: Option<Value>) => Option<NewValue>;
function un_some<Value>(opt: Option<Value>): Value;
function un_some_or<Value>(def: Value): (_: Option<Value>) => Value;
function un_some_else<Value>(def: () => Value): (_: Option<Value>) => Value;
function ok_some<Error>(e: Error): <Value>(_: Option<Value>) => Result<Value, Error>;
function err_some<Value>(v: Value): <Error>(_: Option<Error>) => Result<Value, Error>;
function a_some<B>(b: B): <A>(_: Option<A>) => Either<A, B>;
function b_some<A>(a: A): <B>(_: Option<B>) => Either<A, B>;

Result<Value, Error>

The result can hold resulting value or error. This type helpful to return from functions or asynchronous operations which may be failed. This type is preferred than throwing errors or using nullable error-result arguments in NodeJS style callbacks or using different callbacks in Promise-style.

type Result<Value, Error> = Ok<Value> | Err<Error>;
function ok<Value, Error>(val: Value): Result<Value, Error>;
function err<Value, Error>(err: Error): Result<Value, Error>;
function is_ok<Value, Error>(r: Result<Value, Error>): r is Ok<Value>;
function is_err<Value, Error>(r: Result<Value, Error>): r is Err<Error>;
function then_ok<Value, Error, NewValue>(fn: (_: Value) => Result<NewValue, Error>): (res: Result<Value, Error>) => Result<NewValue, Error>;
function then_err<Value, Error, NewError>(fn: (_: Error) => Result<Value, NewError>): (res: Result<Value, Error>) => Result<Value, NewError>;
function map_ok<Value, NewValue>(fn: (_: Value) => NewValue): <Error>(res: Result<Value, Error>) => Result<NewValue, Error>;
function map_err<Error, NewError>(fn: (_: Error) => NewError): <Value>(res: Result<Value, Error>) => Result<Value, NewError>;
function and_ok<NewValue>(v: NewValue): <Value, Error>(res: Result<Value, Error>) => Result<NewValue, Error>;
function or_err<NewError>(e: NewError): <Value, Error>(res: Result<Value, Error>) => Result<Value, NewError>;
function un_ok<Value, Error>(res: Result<Value, Error>): Value;
function un_err<Value, Error>(res: Result<Value, Error>): Error;
function un_ok_or<Value>(def: Value): <Error>(res: Result<Value, Error>) => Value;
function un_err_or<Error>(def: Error): <Value>(res: Result<Value, Error>) => Error;
function un_ok_else<Value, Error>(def: (e: Error) => Value): (res: Result<Value, Error>) => Value;
function un_err_else<Value, Error>(def: (v: Value) => Error): (res: Result<Value, Error>) => Error;
function some_ok<Value, Error>(res: Result<Value, Error>): Option<Value>;
function some_err<Value, Error>(res: Result<Value, Error>): Option<Error>;
function a_ok<A, B>(res: Result<A, B>): Either<A, B>;
function b_ok<A, B>(res: Result<B, A>): Either<A, B>;

Either<A, B>

The either type is similar to result but preffered for another usecases where both values are success.

type Either<A, B> = A<A> | B<B>;
function a<A, B>(a: A): Either<A, B>;
function b<A, B>(b: B): Either<A, B>;
function is_a<A, B>(r: Either<A, B>): r is A<A>;
function is_b<A, B>(r: Either<A, B>): r is B<A>;
function then_a<A, B, NewA>(fn: (_: A) => Either<NewA, B>): (res: Either<A, B>) => Either<NewA, B>;
function then_b<A, B, NewB>(fn: (_: B) => Either<A, NewB>): (res: Either<A, B>) => Either<A, NewB>;
function map_a<A, NewA>(fn: (_: A) => NewA): <B>(res: Either<A, B>) => Either<NewA, B>;
function map_b<B, NewB>(fn: (_: B) => NewB): <A>(res: Either<A, B>) => Either<A, NewB>;
function and_a<NewA>(v: NewA): <A, B>(r: Either<A, B>) => Either<NewA, B>;
function and_b<NewA>(v: NewB): <A, B>(r: Either<A, B>) => Either<A, NewB>;
function un_a<A, B>(r: Either<A, B>): A;
function un_b<A, B>(r: Either<A, B>): B;
function un_a_or<B>(def: A): <B>(r: Either<A, B>) => A;
function un_b_or<A>(def: B): <A>(r: Either<A, B>) => B;
function un_a_else<A, B>(def: (a: A) => B): (res: Either<A, B>) => A;
function un_b_else<A, B>(def: (b: B) => A): (res: Either<A, B>) => B;
function some_a<A, B>(r: Either<A, B>): Option<A>;
function some_b<A, B>(r: Either<A, B>): Option<B>;
function ok_a<A, B>(r: Either<A, B>): Result<B, A>;
function ok_b<A, B>(r: Either<A, B>): Result<A, B>;

Send<Event>

The method used for sending async events.

interface Send<Event> {
    (event: Event): void;
}
function map_send<Event, OtherEvent>(fn: (event: OtherEvent) => Event): (send: Send<Event>) => Send<OtherEvent>;
function keyed_send<Key>(key: Key): <Event>(send: Send<Keyed<Key, Event>>) => Send<Event>;

Fork<Event>

The method used for starting async tasks.

export interface Done {
    (): void;
}
export interface Fork<Event> {
    (): [Send<Event>, Done];
}
function map_fork<Event, OtherEvent>(fn: (event: OtherEvent) => Event): (fork: Fork<Event>) => Fork<OtherEvent>;
function keyed_fork<Key>(key: Key): <OtherEvent>(fork: Fork<Keyed<Key, OtherEvent>>) => Fork<OtherEvent>;

Functions

Helpers

function identity<Value>(_: Value): Value;
function dummy(): void;
function flat_map<Arg, Res>(list: Arg[], fn: (arg: Arg, idx: number) => Res | Res[]): Res[];
function flat_list<Type>(list: (Type | Type[])[]): Type[];
function flat_all<Type>(...args: (Type | Type[])[]): Type[];