Search


Search something to see results

unhoax

Package Size Total coverage Dependency Count

A safe-by-default schema library that is type/data-driven rather than schema-centric: you bring your entity types, we do not lose you with complex schema typings.
Particularly lightweight and extendible by design.


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

Check out the documentation website, you may want to start with the getting started guide 😊

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
}