From ee81c0a2ecf6bb861fee83ece8c2ab1ee5c13314 Mon Sep 17 00:00:00 2001 From: Attila Olah Date: Thu, 26 Apr 2018 00:00:54 +0200 Subject: [PATCH] docs: add minimal skeleton for gitbook --- .gitbook.yaml | 4 ++++ docs/README.md | 38 +++++++++++++++++++++++++++++ docs/basics/validating-objects.md | 40 +++++++++++++++++++++++++++++++ docs/introduction/installation.md | 21 ++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 .gitbook.yaml create mode 100644 docs/README.md create mode 100644 docs/basics/validating-objects.md create mode 100644 docs/introduction/installation.md diff --git a/.gitbook.yaml b/.gitbook.yaml new file mode 100644 index 0000000000..10b262dbae --- /dev/null +++ b/.gitbook.yaml @@ -0,0 +1,4 @@ +root: docs +structure: + readme: README.md + summary: docs/README.md \ No newline at end of file diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000000..72ff2e0f01 --- /dev/null +++ b/docs/README.md @@ -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) \ No newline at end of file diff --git a/docs/basics/validating-objects.md b/docs/basics/validating-objects.md new file mode 100644 index 0000000000..f7215bdbc3 --- /dev/null +++ b/docs/basics/validating-objects.md @@ -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) \ No newline at end of file diff --git a/docs/introduction/installation.md b/docs/introduction/installation.md new file mode 100644 index 0000000000..6b0d692c29 --- /dev/null +++ b/docs/introduction/installation.md @@ -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. \ No newline at end of file