0.0.49 • Published 3 years ago

morphic-ts-routing v0.0.49

Weekly downloads
54
License
MIT
Repository
github
Last release
3 years ago

morphic-ts-routing

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

Usage

Note

Formatting the NotFound type will return '/'

import * as R from 'fp-ts-routing'
import { routingFromMatches3 } from 'morphic-ts-routing'
import { ADTType, ADT } from '@morphic-ts/adt'

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

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

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

Limitation

The library supports up to sixteen (16) routes. It cannot support more than that - if you try, you get this error:

Expression produces a union type that is too complex to represent.

I'm uncertain what to do about this. Please make a PR if you have any ideas. Thanks!

0.0.47

3 years ago

0.0.48

3 years ago

0.0.49

3 years ago

0.0.46

4 years ago

0.0.40

4 years ago

0.0.41

4 years ago

0.0.42

4 years ago

0.0.20

4 years ago

0.0.43

4 years ago

0.0.21

4 years ago

0.0.44

4 years ago

0.0.22

4 years ago

0.0.45

4 years ago

0.0.23

4 years ago

0.0.24

4 years ago

0.0.25

4 years ago

0.0.15

4 years ago

0.0.38

4 years ago

0.0.16

4 years ago

0.0.39

4 years ago

0.0.17

4 years ago

0.0.18

4 years ago

0.0.19

4 years ago

0.0.30

4 years ago

0.0.31

4 years ago

0.0.32

4 years ago

0.0.33

4 years ago

0.0.34

4 years ago

0.0.12

4 years ago

0.0.35

4 years ago

0.0.13

4 years ago

0.0.14

4 years ago

0.0.26

4 years ago

0.0.27

4 years ago

0.0.28

4 years ago

0.0.29

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.5

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.4

4 years ago

0.0.1

4 years ago