forked from typestack/class-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add minimal skeleton for gitbook
- Loading branch information
1 parent
b1e1bb5
commit ee81c0a
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
root: docs | ||
structure: | ||
readme: README.md | ||
summary: docs/README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Table of Contents | ||
|
||
* [Read Me](../README.md) | ||
* Getting Started | ||
* [Installation](introduction/installation.md) | ||
* [Usage with Typescript](introduction/usage-with-typescript.md) | ||
* [Usage with Javascript](introduction/usage-with-javascript.md) | ||
* [Dependency Injection](introduction/usage-with-di.md) | ||
* [Core Principes](introduction/core-principes.md) | ||
* [Basic Usage](basics/README.md) | ||
* [Validating objects](basics/validating-objects.md) | ||
* [Validating arrays](basics/validating-arrays.md) | ||
* [Validating nested objects](basics/validating-nested-objects.md) | ||
* [Advanced Usage](advanced/README.md) | ||
* [Conditional Validation](advanced/conditional-validation.md) | ||
* [Validation Groups](advanced/validation-groups.md) | ||
* [Inheritance](advanced/inheritance.md) | ||
* [Custom Validation Decorators](advanced/validations-decoratos.md) | ||
* [Custom Validation Classes](advanced/validation-classes.md) | ||
* [Decorators Reference](reference/decoratos.md) | ||
* [Common Decorators](reference/common-decoratos.md) | ||
* [Number Decorators](reference/number-decoratos.md) | ||
* [String Decorators](reference/string-decoratos.md) | ||
* [Date Decorators](reference/date-decoratos.md) | ||
* [Array Decorators](reference/array-decoratos.md) | ||
* [Recipes](recipes/README.md) | ||
* [Simple Validations](https://stackblitz.com/edit/class-transformer-simple-validations) | ||
* [Nested Objects](https://stackblitz.com/edit/class-transformer-nested-objects) | ||
* [Using Groups](https://stackblitz.com/edit/class-transformer-using-groups) | ||
* [Custom Validators](https://stackblitz.com/edit/class-transformer-custom-validator) | ||
* [Custom Decorators](https://stackblitz.com/edit/class-transformer-custom-decorators) | ||
* [Using Schemas](https://stackblitz.com/edit/class-transformer-schemas) | ||
* [Inheritance](https://stackblitz.com/edit/class-transformer-inheritance) | ||
* [API Reference](api/README.md) | ||
* [validate](api/validate.md) | ||
* [ValidatorOptions ](api/ValidatorOptions.md) | ||
* [ValidationError ](api/ValidationError.md) | ||
* [Change Log](../CHANGELOG.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Validating objects | ||
|
||
```ts | ||
import { validate, IsString, IsInt, IsDate, MaxLength, Min, Max} from "class-validator"; | ||
|
||
export class Book { | ||
|
||
@IsString() | ||
@MaxLength(255) | ||
title: string; | ||
|
||
@IsString() | ||
@MaxLength(255) | ||
author: string; | ||
|
||
@IsInt() | ||
@Min(0) | ||
@Max(10) | ||
rating: number; | ||
|
||
@IsDate() | ||
publishDate: Date; | ||
|
||
} | ||
|
||
const book = new Book(); | ||
post.title = 'Don Quixote'; | ||
post.author = 'Miguel De Cervantes'; | ||
post.rating = 11; | ||
post.publishDate = 1615; | ||
|
||
validate(book).then(errors => { | ||
// errors is an array of ValidationErrors | ||
if (errors.length > 0) { | ||
console.warn("validation failed. errors: ", errors); | ||
} | ||
}); | ||
``` | ||
|
||
Run this example on [Stackblitz](https://stackblitz.com/edit/class-validator-simple-example) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Installation | ||
|
||
To install the stable version: | ||
|
||
``` | ||
npm install --save class-validator | ||
``` | ||
|
||
### Usage in the browser | ||
|
||
If you want to use `class-validator` in the browser and you use Webpack then just import it into your project and Webpack will take care of the rest. | ||
|
||
### Next version | ||
|
||
You can install the next version of `class-validator` via | ||
|
||
``` | ||
npm install --save class-validator@next | ||
``` | ||
|
||
> Note: The next version can break anytime without notice. Do not use this in production. |