Skip to content

Commit

Permalink
Fixed a bug in the typescript definition and updated readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
DJWassink committed Apr 11, 2017
1 parent 352fa2c commit 61cfff3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ node_modules
# Optional npm cache directory
.npm

# Yarn
yarn.lock

# intellij idea
.idea

# Optional REPL history
.node_repl_history
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-strin)
- [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
Expand Down Expand Up @@ -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 |
Expand All @@ -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.
Expand Down Expand Up @@ -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).
Expand Down
8 changes: 4 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"supertest": "^1.1.0"
},
"dependencies": {
"@types/validator": "^6.2.0",
"lodash": "^4.0.0",
"validator": "^4.5.0"
}
Expand Down

0 comments on commit 61cfff3

Please sign in to comment.