An open API service indexing awesome lists of open source software.

https://github.com/maevadevs/mongoose-custom-validators

NPM: A collection of custom validators for Mongoose that complements Mongoose validators and the validator package.
https://github.com/maevadevs/mongoose-custom-validators

criterias isvalidpassword mongoose mongoose-schema

Last synced: 6 months ago
JSON representation

NPM: A collection of custom validators for Mongoose that complements Mongoose validators and the validator package.

Awesome Lists containing this project

README

          

# Custom Validators for Mongoose Schema

This repository contains some custom validators for Mongoose Schema. It complements the validators that are already found within [Mongoose](http://mongoosejs.com/docs/validation.html) itself *AND* the [`validator`](https://www.npmjs.com/package/validator) package.

## Installation

npm i mongoose-custom-validators --save

or

yarn add mongoose-custom-validators

## List of Custom Validators

- [isValidPassword](#isValidPassword)

### `isValidPassword`

#### Signature: `(String, require = defaultRequire) => Boolean`

Validates password string against the requirements properties. By default, we opt for a strong password that must meet the following criterias:

defaultRequire = {
minlength: 10, // At least 10 characters long (optional)
uppercase: true, // Have at least 1 uppercase character
lowercase: true, // Have at least 1 lowercase character
number: true, // Have at least 1 number
nonalpha: true // Have at least 1 Nonalpha character
}

#### Usage

const { isValidPassword } = require('mongoose-custom-validators')

To override some or all of the defaults, pass in an object with the criterias properties to override. **Non-overriden criterias will be using the `defaultRequire`.** The only acceptable properties are the ones listed under the `defaultRequire`

If using `defaultRequire`, simply pass the function as the validator

validate: {
validator: isValidPassword,
message: 'Password must have at least: 1 uppercase letter, 1 lowercase letter, 1 number, and 1 special character.'
}

If using with custom `userRequire`, pass validator through an anonymous function that takes the password string

validate: {
validator: (str) => isValidPassword(str, { uppercase: false }),
message: 'Password must have at least: 1 lowercase letter, 1 number, and 1 special character.'
}