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

fp-ts-codegen

v0.4.0

Published

TypeScript code generation from a haskell-like syntax for ADT

Readme

TypeScript code generation from a haskell-like syntax for ADT (algebraic data types)

Playground

A playground with a few examples

Installation

To install the stable version:

npm install fp-ts-codegen

Usage

Signature

function run(input: string, options: Options = defaultOptions): Either<string, string>

Example

import { run } from 'fp-ts-codegen'

console.log(run('data Option A = None | Some A'))

Output

/** type definition */

export type Option<A> =
  | {
      readonly type: 'None'
    }
  | {
      readonly type: 'Some'
      readonly value0: A
    }

/** constructors */

export const none: Option<never> = { type: 'None' }

export function some<A>(value0: A): Option<A> {
  return { type: 'Some', value0 }
}

/** pattern matching */

export function fold<A, R>(onNone: () => R, onSome: (value0: A) => R): (fa: Option<A>) => R {
  return fa => {
    switch (fa.type) {
      case 'None':
        return onNone()
      case 'Some':
        return onSome(fa.value0)
    }
  }
}

/** prisms */

import { Prism } from 'monocle-ts'

export function _none<A>(): Prism<Option<A>, Option<A>> {
  return Prism.fromPredicate(s => s.type === 'None')
}

export function _some<A>(): Prism<Option<A>, Option<A>> {
  return Prism.fromPredicate(s => s.type === 'Some')
}

/** Eq instance */

import { Eq } from 'fp-ts/lib/Eq'

export function getEq<A>(eqSomeValue0: Eq<A>): Eq<Option<A>> {
  return {
    equals: (x, y) => {
      if (x === y) {
        return true
      }
      if (x.type === 'None' && y.type === 'None') {
        return true
      }
      if (x.type === 'Some' && y.type === 'Some') {
        return eqSomeValue0.equals(x.value0, y.value0)
      }
      return false
    }
  }
}

Records

Syntax: { name :: type }

Example

Source

--     record ---v
data User = User { name :: string, surname :: string }

Output

export type User = {
  readonly type: 'User'
  readonly name: string
  readonly surname: string
}

export function user(name: string, surname: string): User {
  return { type: 'User', name, surname }
}

Tuples

Syntax: (type1, type2, ...types)

Example

Source

--              tuple ---v
data Tuple2 A B = Tuple2 (A, B)

Output

export type Tuple2<A, B> = {
  readonly type: 'Tuple2'
  readonly value0: [A, B]
}

export function tuple2<A, B>(value0: [A, B]): Tuple2<A, B> {
  return { type: 'Tuple2', value0 }
}

Constraints

Syntax: (<name> :: <constraint>)

Example

Source

--    constraint ---v
data Constrained (A :: string) = Fetching | GotData A

Output

export type Constrained<A extends string> =
  | {
      readonly type: 'Fetching'
    }
  | {
      readonly type: 'GotData'
      readonly value0: A
    }

Options

// fp-ts-codegen/lib/ast module

export interface Options {
  /** the name of the field used as tag */
  tagName: string
  /** the name prefix used for pattern matching functions */
  foldName: string
  /**
   * the pattern matching handlers can be expressed as positional arguments
   * or a single object literal `tag -> handler`
   */
  handlersStyle: { type: 'positional' } | { type: 'record'; handlersName: string }
}

export const defaultOptions: Options = {
  tagName: '_tag',
  foldName: 'fold',
  handlersStyle: { type: 'positional' }
}

Options management

Example

import { lenses, defaultOptions } from 'fp-ts-codegen/lib/ast'

lenses.tagName.set('tag')(defaultOptions)
/*
{
  tagName: 'tag',
  foldName: 'fold',
  ...
}
*/

Modules

  • ast module: internal model -> TypeScript AST
  • model module: internal model
  • printer module: internal model -> TypeScript code
  • haskell module: haskell-like syntax -> internal model
  • index module: haskell-like syntax -> TypeScript code

Roadmap

  • derive type class instances? (Functor, Foldable, etc...)
  • ???