Skip to content

Commit

Permalink
docs: add class intantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnucki committed Mar 16, 2020
1 parent 8cdb89b commit e3bd7df
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ $ npm i runtypor
Here is a simple example of request input validation with Express:
```ts
import express from 'express';
import { createRuntype } from '../src/index';

type Car = {
brand: string;
Expand Down Expand Up @@ -81,6 +82,17 @@ app.post('/car-purchase', (req: express.Request, res: express.Response): void =>

Note that you should only use the validated value when your data has a simple JSON structure, as it won't replicate prototypal chain or functions for instance.

Do you prefer object notation over functional one ? Use the class instantiation:
```ts
import { createRuntype, Runtype } from '../src/index';

// ...

createRuntype<Car>(validationSchema);
// is equivalent to
new Runtype<Car>(validationSchema);
```

## Testing
Many `npm` scripts are available to help testing:
```sh
Expand Down

0 comments on commit e3bd7df

Please sign in to comment.