{"id":16188296,"url":"https://github.com/konsumer/mongoose-type-email","last_synced_at":"2025-03-19T03:30:39.841Z","repository":{"id":26459122,"uuid":"29910438","full_name":"konsumer/mongoose-type-email","owner":"konsumer","description":"An email field-type for Mongoose schemas","archived":false,"fork":false,"pushed_at":"2020-11-13T03:52:51.000Z","size":882,"stargazers_count":26,"open_issues_count":1,"forks_count":13,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-17T02:51:23.931Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/konsumer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-27T11:06:55.000Z","updated_at":"2022-06-07T22:28:28.000Z","dependencies_parsed_at":"2022-08-31T23:51:42.785Z","dependency_job_id":null,"html_url":"https://github.com/konsumer/mongoose-type-email","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konsumer%2Fmongoose-type-email","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konsumer%2Fmongoose-type-email/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konsumer%2Fmongoose-type-email/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konsumer%2Fmongoose-type-email/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/konsumer","download_url":"https://codeload.github.com/konsumer/mongoose-type-email/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244350663,"owners_count":20439284,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T07:25:53.207Z","updated_at":"2025-03-19T03:30:39.432Z","avatar_url":"https://github.com/konsumer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongoose-type-email\n\nAn email field-type for Mongoose schemas\n\n[![Code Climate](https://codeclimate.com/github/konsumer/mongoose-type-email/badges/gpa.svg)](https://codeclimate.com/github/konsumer/mongoose-type-email)\n\n[![npm](https://nodei.co/npm/mongoose-type-email.png)](https://www.npmjs.com/package/mongoose-type-email)\n\n## usage\n\nThis will validate email, correctly:\n\n```js\nvar mongoose = require('mongoose');\nrequire('mongoose-type-email');\n\nvar UserSchema = new mongoose.Schema({\n    email: {\n        work: mongoose.SchemaTypes.Email,\n        home: mongoose.SchemaTypes.Email\n    }\n});\n```\n\nYou can also use the stuff in `String` type:\n\n```js\nvar UserSchema = new mongoose.Schema({\n    email: {\n        work: {type: mongoose.SchemaTypes.Email, required: true},\n        home: {type: mongoose.SchemaTypes.Email, required: true},\n    }\n});\n```\n\nYou can also use it as an array:\n\n\n```js\nvar UserSchema = new mongoose.Schema({\n    emails: [{type: mongoose.SchemaTypes.Email}]\n});\n```\n\nYou can add 'allowBlank: true' in order to allow empty string ('') when the field is not required\n\n```js\nvar mongoose = require('mongoose');\nrequire('mongoose-type-email');\n\nvar UserSchema = new mongoose.Schema({\n    email: {\n        work: { type: mongoose.SchemaTypes.Email, allowBlank: true }, // allows '' as a value\n        home: mongoose.SchemaTypes.Email // throws when the value is ''\n    }\n});\n```\n\nYou can specify a default custom error message by overriding `mongoose.SchemaTypes.Email.defaults.message`\n\n```js\nvar mongoose = require('mongoose');\nrequire('mongoose-type-email');\nmongoose.SchemaTypes.Email.defaults.message = 'Email address is invalid'\n\nvar UserSchema = new mongoose.Schema({\n    email: {\n        work: mongoose.SchemaTypes.Email,\n        home: mongoose.SchemaTypes.Email\n    }\n});\n```\n\nBy default, this library follows the same validation you see in the [html spec for `type=email`](https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address) which allows local email addresses, and other non-standard email types. If you want more complete TLD validation (eg `user@host.com`) you can use the `correctTld` options:\n\n```js\nvar UserSchema = new mongoose.Schema({\n    email: {\n        work: {type: mongoose.SchemaTypes.Email, correctTld: true},\n        home: {type: mongoose.SchemaTypes.Email, correctTld: true},\n    }\n});\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkonsumer%2Fmongoose-type-email","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkonsumer%2Fmongoose-type-email","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkonsumer%2Fmongoose-type-email/lists"}