Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ikasoba/tokoroten


https://github.com/ikasoba/tokoroten

Last synced: 15 days ago
JSON representation

Awesome Lists containing this project

README

        

# tokoroten

tokoroten is a utility for matching JSON-like input to a schema.

```ts
import * as t from "@ikasoba000/tokoroten"

const Note = t.object({
type: t.const("Note"),
content: t.string,
mediaType: t.opt(t.string),
published: t.map(t.string, x => new Date(x))
})

const note = Note({
type: "Note",
content: "hogehoge",
mediaType: 1234,
published: "2024-02-14T04:48:47.155Z"
})

console.log(note)
// {
// value: {
// type: "Note",
// content: "hoogehoge",
// published: 2024-02-14T04:48:47.155Z
// }
// }
```