0.3.2 • Published 5 years ago

@ianliu/tsjoi v0.3.2

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

tsjoi

Tool to convert TypeScript interfaces to Joi schemas

Example

Given the following TypeScript file:

// foo.ts
interface User {
  name: string
  age?: number
  address: string | null
  status: "opened" | "closed"
}

One can generate Joi schemas by running tsjoi foo.ts to obtain

// Automatically generated by tsjoi
import Joi from 'joi'
import * as T from './foo'

export const User = Joi.object({
  name: Joi.string().required(),
  age: Joi.number(),
  address: Joi.string().allow(null).required(),
  status: Joi.string().valid(["opened", "closed"]).required()
})
export function isUser(obj: any): obj is T.User {
  return User.validate(obj).error === null
}
0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago