unhoax
TypeScript icon, indicating that this package has built-in type declarations

0.9.2 • Public • Published

Package Size Total coverage Downloads

A safe-by-default schema library that is functional and type/data-driven rather than schema-centric: you bring your entity types, we provide simple schema typings.
Particularly lightweight and extendible by design.


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 { 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 {
  x.unsafeParse(personSchema, { name: , age:  })
  // Person
} catch (err) {
  // although `err` is typed as `unknown`, this is what you get inside:
  err // Error
  err.cause // x.ParseError
}

Generating random fixtures from your schemas

Visit unhoax-chance to see how to generate random fixtures from your schemas using ChanceJS.

The purpose of this library – Why yet-another?

See here

Package Sidebar

Install

npm i unhoax

Weekly Downloads

24

Version

0.9.2

License

MIT

Unpacked Size

247 kB

Total Files

9

Last publish

Collaborators

  • sacdenoeuds