m2e-validator

1.3.11 • Public • Published

🔌 Mongoose to Express-Validator adapter

Status Coverage Status

This package converts Mongoose schema into a validation chain for Express. Currently, it supports most default schema types as well as a few custom ones. For instance, schema types named Email or Phone match validator's implementation. See the full list of supported properties below.

The plugin

This module works through a custom Mongoose plugin that appends two static methods, getSchemaPaths and getChildPaths. Both work recursively and support child and discriminator schemas. To access a discriminator, though, the request object must contain a reference to its key. See the examples below for more detail.

// coming soon

The schemas

All schema types support required and systemOnly properties. The latter omits the field from validation altogether.

Name Options Notes
String minLength, maxLength, enum Auto escapes and trims
Number min, max
ObjectId
SchemaArray
Date Auto converts to ISO string
Boolean Auto converts any non-falsy value to true
URL -- Auto normalizes
Email -- Auto normalizes
Phone --

Readme

Keywords

none

Package Sidebar

Install

npm i m2e-validator

Weekly Downloads

4

Version

1.3.11

License

MIT

Unpacked Size

26 kB

Total Files

25

Last publish

Collaborators

  • 3merge