unhoax
v0.6.6
Published
type/data-centric schema library. A schema library empower you, not constrain you with their types messy types.
Downloads
1,136
Maintainers
Readme
Installation
npm i -S unhoax
Although not required, I recommend using the library with a pipe
function, like pipe
from just-pipe
or pipeWith
from pipe-ts
Getting Started
Check out the documentation website, you may want to start with the getting started guide 😊
Quick Sample – we want code!
import * as x from 'unhoax'
// Type-Driven:
type Person = { name: string; age: number }
const personSchema = x.object<Person>({
name: x.string,
age: x.number,
})
// or using type inference
type Person = x.TypeOf<typeof personSchema>
// parsing safely
const result = personSchema.parse({ name: …, age: … })
if (result.success) result.value // Person
else result.error // x.ParseError
// parsing unsafely
try {
const result = x.unsafeParse(personSchema, { name: …, age: … })
result // Person
} catch (err) {
// although `err` is typed as `unknown`, this is what you get inside:
err // Error
err.cause // x.ParseError
}