1.0.7 • Published 3 months ago

typescript-schema-to-joi v1.0.7

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
3 months ago

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
  )
1.0.7

3 months ago

1.0.6

3 months ago

1.0.5

3 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago