diff --git a/.gitignore b/.gitignore index a8f2441..085e889 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,11 @@ node_modules # Optional npm cache directory .npm +# Yarn +yarn.lock + +# intellij idea +.idea + # Optional REPL history .node_repl_history diff --git a/README.md b/README.md index f167fde..755dad9 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,28 @@ No chaining, no prototype violations, no magic. Just some simple, stateless, jav All you have to do is import some base validation functions and declare the validation rules for your request. +## Table of contents +- [Installation](#installation) +- [Usage](#usage) +- [Usage in NodeJS](#usage-in-nodejs) + - [Request Validation](#request-validation) + - [Request Parameters](#request-parameters) + - [Query String](#query-string) + - [Body](#body) + - [Headers](#headers) + - [Everything](#everything) + - [Assert Middleware](#assert-middleware) +- [Advanced usage](#advanced-usage) + - [Optional Validation](#optional-validation) + - [Custom Error Messages](#custom-error-messages) + - [Custom Validation Functions](#custom-validation-functions) +- [Validation Helpers](#validation-helpers) + - [Supported Helpers](#supported-helpers) + - [Not currently supported](#not-currently-supported) +- [Usage with TypeScript](#usage-with-typescript) +- [Contributing](#contributing) +- [License](#license) + ## Installation ```bash npm install --save property-validator @@ -368,7 +390,7 @@ Validation helpers are functions you can use to validate incoming request proper property-validator relies on the super battle tested [validator.js](https://github.com/chriso/validator.js) library. -#### Supported Helpers +### Supported Helpers Here's a list of currently supported helpers: | Helper | Description | @@ -395,7 +417,7 @@ Here's a list of currently supported helpers: |isUUID(paramName [, version])| check if the string is a UUID (version 3, 4 or 5). | |matches(paramName, pattern [, modifiers])| check if string matches the pattern. Either `matches('foo', /foo/i)` or `matches('foo', 'foo', 'i')`. | |isPlainObject(paramName)| check if the current param is a plain object. | -| isLength(paramName, options) | check if the string's length falls in a range. Note: this function takes into account surrogate pairs. | +|isLength(paramName, options) | check if the string's length falls in a range. Note: this function takes into account surrogate pairs. `options` is an object which can contain the keys `min` and/or `max` to check the integer is within boundaries (e.g. `{ min: 10, max: 99 }`). | ### Not currently supported These are a few other helpers avaliable in [validator.js](https://github.com/chriso/validator.js) that could be used in property-validator. @@ -430,6 +452,10 @@ Feel free to submit a PR if you need any of these functions. | isVariableWidth(paramName) | check if the string contains a mixture of full and half-width chars. | | isWhitelisted(paramName, chars) | checks characters if they appear in the whitelist. | +## Usage with TypeScript + +There is no need to install additional type definitions for property-validator since it ships with TypeScript definition files. + ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/nettofarah/property-validator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Code of Conduct](https://github.com/nettofarah/property-validator/blob/master/CODE_OF_CONDUCT.md). diff --git a/index.d.ts b/index.d.ts index a4ee52f..1d73b50 100644 --- a/index.d.ts +++ b/index.d.ts @@ -38,7 +38,7 @@ declare module 'property-validator' { } //request validators - export function validate(subject: {}, string[], validations: Validator[]): ValidateResult; + export function validate(subject: {}, validations: Validator[]): ValidateResult; export function validateParams(request: { params: {} }, validations: Validator[]): ValidateResult; export function validateQuery(request: { query: {} }, validations: Validator[]): ValidateResult; export function validateBody(request: { body: {} }, validations: Validator[]): ValidateResult; @@ -63,14 +63,14 @@ declare module 'property-validator' { export function isAlphanumeric(paramName: string, customMessage?: string): Validator; export function isArray(paramName: string, customMessage?: string): Validator; export function isCreditCard(paramName: string, customMessage?: string): Validator; - export function isCurrency(paramName: string, options: ValidatorJS.IsCurrencyOptions, customMessage?: string): Validator; + export function isCurrency(paramName: string, options: IsCurrencyOptions, customMessage?: string): Validator; export function isDate(paramName: string, customMessage?: string): Validator; export function isDecimal(paramName: string, customMessage?: string): Validator; - export function isInt(paramName: string, options: ValidatorJS.IsIntOptions, customMessage?: string): Validator; + export function isInt(paramName: string, options: IsIntOptions, customMessage?: string): Validator; export function isJSON(paramName: string, customMessage?: string): Validator; export function isNull(paramName: string, customMessage?: string): Validator; export function isNumeric(paramName: string, customMessage?: string): Validator; - export function isURL(paramName: string, options: ValidatorJS.IsURLOptions, customMessage?: string): Validator; + export function isURL(paramName: string, options: IsURLOptions, customMessage?: string): Validator; export function isPlainObject(paramName: string, customMessage?: string): Validator; //same named (pair) validation functions diff --git a/package.json b/package.json index b0ad005..cd9fa31 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "supertest": "^1.1.0" }, "dependencies": { + "@types/validator": "^6.2.0", "lodash": "^4.0.0", "validator": "^4.5.0" }