https://github.com/tilap/mongoose-type-mail
Mongoose type mail with validator, string cast and clear error type
https://github.com/tilap/mongoose-type-mail
Last synced: 3 days ago
JSON representation
Mongoose type mail with validator, string cast and clear error type
- Host: GitHub
- URL: https://github.com/tilap/mongoose-type-mail
- Owner: tilap
- License: mit
- Created: 2016-04-25T12:58:15.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-25T12:59:11.000Z (about 10 years ago)
- Last Synced: 2025-10-11T01:03:12.272Z (9 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Mongoose type mail [![NPM version][npm-image]][npm-url]
============================
A field type mail, with validation and error type for mongoose
## Install
```
npm install --save mongoose-type-mail
```
## Usage
```
const Schema = require('mongoose').Schema;
const Email = require('mongoose-type-mail');
let MySchema = new Schema({
username: { type: String },
email: { type: Email },
});
```
Standard other mongoose stuff works fine too:
```
let MySchema = new Schema({
email: {
type: Email,
required: [true, 'email is required'],
unique: [true, 'this email is already use'],
},
});
```
## Error
On validation run (mongoose insert), if an item has a bad mail format, you'll get the full explicit error with ```invalid-email``` type.
```
{
message: 'Invalid email address',
name: 'ValidatorError',
properties:
{ type: 'invalid-email',
message: 'Invalid email address',
path: 'email',
value: 'not-an-email'
},
kind: 'invalid-email',
path: 'email',
value: 'not-an-email'
}
```
## License
MIT
[npm-image]: https://img.shields.io/npm/v/mongoose-type-mail.svg?style=flat
[npm-url]: https://npmjs.org/package/mongoose-type-mail