fp-ts-routing-adt
v0.0.5
Published
Helper function that builds an fp-ts-routing parser and formatter from keyed Matches.
Downloads
4
Readme
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
*/