typescript-schema-to-joi
v1.0.7
Published
package to convert typescript schema to joi schema
Downloads
34
Readme
Typescript schema to Joi
The purpose of this package is to convert a typescript type into a joi schema.
To install this package, run npm install typescript-schema-to-joi
This package is really easy to use, see example below:
import tsToJoi from 'typescript-schema-to-joi';
const config = {
path: './folder/toto.ts', // The path to the file in which the type is
tsconfig: './tsconfig.json', // The path to your typescript config
type: 'MyType', // The name of the typ
};
const schema = tsToJoi(config);
const payload = {
test: true
}
const { error } = schema.validate(payload)
if (error) {
console.log('invalid format')
} else {
console.log('format is valid')
}
You also have the possiblity to have json type descriptor generated by giving true
as second parameter:
tsToJoi(
config,
true,
'./path/to/write/file.json' // optional third param, it will write the file in the same folder as the type by default
)