Skip to content

Commit

Permalink
update readme, add date decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisShank committed Jan 9, 2024
1 parent 6fb016e commit 281a432
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# XRouter
# Routtl (pronounced rout·le)

> Lightweight routing primitives.
Expand All @@ -20,11 +20,11 @@ const data = todoRoute.decode('/hello/world');

## Overview

`Routtl` is a small set of primitives for defining routes and encoding/decoding data to/from that route. It is small (less than 500kb of JS), has no dependencies, and provides type-safe decoding. It uses type
`Routtl` is a small set of primitives for defining routes and encoding/decoding data to/from that route. It is small (less than 500kb of JS), has no dependencies, and provides type-safe decoding. It uses JavaScript tagged template literals to provide a declarative, composable API for defining routes.

## Decoders

Default decoders are provided for primitive JS types (e.g. string, number, boolean, date). A simple `Decoder` interface is provided to extend or build your own decoding. Additionally, a decoder factory is provided for arrays.
Default decoders are provided for primitive JS types (e.g. string, number, boolean, date). A simple `Decoder` interface is provided to extend or build your own decoding. Additionally, a decoder factory is provided for arrays of arbitrary types.

## Roadmap

Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export const num: Decoder<number> = {
encode: (data) => data.toString(),
};

export const date: Decoder<Date> = {
decode: (str) => new Date(str),
encode: (data) => data.toString(),
};

export function array<Data>(decoder: Decoder<Data>): Decoder<Data[]> {
return {
decode: (str) => {
Expand Down

0 comments on commit 281a432

Please sign in to comment.