0.0.5 • Published 2 years ago

fp-ts-routing-adt v0.0.5

Weekly downloads
9
License
MIT
Repository
github
Last release
2 years ago

fp-ts-routing-adt

Parses route strings to a sum type using Matches from fp-ts-routing. Tangentially inspired by purescript-routing-duplex. Simplified version of morphic-ts-routing

Usage

Installation

yarn add fp-ts-routing-adt

Notes

  • Formatting the NotFound type will return '/'
import * as R from 'fp-ts-routing'
import { routingFromMatches } from 'fp-ts-routing-adt'

const landing = R.end // landing: R.Match<{}>
const show = R.lit('show').then(R.end) // show: R.Match<{}>
const id = R.int('id').then(R.end) // id: R.Match<{ id: number }>

const { parse, format } = routingFromMatches(
  ['Landing', landing],
  ['Show', show],
  ['Id', id],
);
type RouteADT = ReturnType<typeof parse>

/*
  type RouteADT = {
      type: "NotFound";
  } | {
      type: "Landing";
  } | {
      type: "Show";
  } | {
      type: "Id";
      id: number;
  }
  const parse: (path: string) => RouteADT
  const format: (adt: RouteADT) => string
 */

TODO:

  • prevent duplicate routes at the type level?
    • implementation using this only supports up to 15 routes (example)
    • if a stable solution is possible, PRs are welcome!
0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago