mongoose-type-mail
v1.0.0
Published
Mongoose simple type for email with validation and error name
Downloads
33
Readme
Mongoose type mail
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