Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a bug in the typescript definition and updated readme. #17

Merged
merged 1 commit into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-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
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