{"id":14975749,"url":"https://github.com/lykmapipo/mongoose-valid8","last_synced_at":"2025-10-11T11:05:57.359Z","repository":{"id":32705226,"uuid":"36294765","full_name":"lykmapipo/mongoose-valid8","owner":"lykmapipo","description":"Additional mongoose schema validations","archived":false,"fork":false,"pushed_at":"2023-01-09T00:29:54.000Z","size":2537,"stargazers_count":6,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-04T19:43:13.199Z","etag":null,"topics":["array","mongoose","number","string","valdator","validations"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lykmapipo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null}},"created_at":"2015-05-26T12:36:00.000Z","updated_at":"2025-01-20T20:51:28.000Z","dependencies_parsed_at":"2023-01-14T21:59:48.069Z","dependency_job_id":null,"html_url":"https://github.com/lykmapipo/mongoose-valid8","commit_stats":null,"previous_names":[],"tags_count":59,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykmapipo%2Fmongoose-valid8","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykmapipo%2Fmongoose-valid8/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykmapipo%2Fmongoose-valid8/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lykmapipo%2Fmongoose-valid8/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lykmapipo","download_url":"https://codeload.github.com/lykmapipo/mongoose-valid8/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238508824,"owners_count":19484212,"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":["array","mongoose","number","string","valdator","validations"],"created_at":"2024-09-24T13:52:29.237Z","updated_at":"2025-10-11T11:05:52.323Z","avatar_url":"https://github.com/lykmapipo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongoose-valid8\n\n[![Build Status](https://app.travis-ci.com/lykmapipo/mongoose-valid8.svg?branch=master)](https://app.travis-ci.com/lykmapipo/mongoose-valid8)\n[![Dependencies Status](https://david-dm.org/lykmapipo/mongoose-valid8.svg)](https://david-dm.org/lykmapipo/mongoose-valid8)\n[![Coverage Status](https://coveralls.io/repos/github/lykmapipo/mongoose-valid8/badge.svg?branch=master)](https://coveralls.io/github/lykmapipo/mongoose-valid8?branch=master)\n[![GitHub License](https://img.shields.io/github/license/lykmapipo/mongoose-valid8)](https://github.com/lykmapipo/mongoose-valid8/blob/master/LICENSE)\n\n[![Commitizen Friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![Code Style](https://badgen.net/badge/code%20style/airbnb/ff5a5f?icon=airbnb)](https://github.com/airbnb/javascript)\n[![npm version](https://img.shields.io/npm/v/mongoose-valid8)](https://www.npmjs.com/package/mongoose-valid8)\n\nAdditional mongoose schema validations.\n\n## Requirements\n\n- [NodeJS v13+](https://nodejs.org)\n- [Npm v6.12+](https://www.npmjs.com/)\n- [MongoDB v4+](https://www.mongodb.com/)\n- [Mongoose v6+](https://github.com/Automattic/mongoose)\n\n## Installation\n\n```sh\nnpm install mongoose mongoose-valid8 --save\n```\n\n## Usage\n\n```javascript\nimport mongoose from 'mongoose'\nimport 'mongoose-valid8'\nimport {model, Schema} from 'mongoose'\n\nconst User = model('User', new Schema({\n  email: {\n    type: String,\n    email: true\n  }\n}));\n\nconst user = new User({ email: 'invalidemail' });\n\nuser.validate((error) =\u003e {\n  expect(error).to.exist;\n});\n\nuser.save((error) =\u003e {\n  expect(error).to.exist;\n});\n```\n\n## Validations\n\n## String\n\n\n### `email: Boolean`\nWhen set to `true` force value to be valid email address.\n```js\nnew Schema({\n  email: {\n    type: String,\n    email: true\n  }\n});\n```\n\n### `capitalize: Boolean`\nWhen set to `true` it converts the first character of string to upper case and the remaining to lower case.\n```js\nnew Schema({\n  firstName: {\n    type: String,\n    capitalize: true\n  }\n});\n```\n\n### `startcase: Boolean`\nWhen set to `true` converts string to start case(or title case).\n```js\nnew Schema({\n  name: {\n    type: String,\n    startcase: true\n  }\n});\n```\n\n\n### `macaddress: Boolean`\nWhen set to `true` force value to be valid macaddress.\n```js\nnew Schema({\n  address: {\n    type: String,\n    macaddress: true\n  }\n});\n```\n\n### `ip: Boolean`\nWhen set to `true` force value to be valid ip address.\n```js\nnew Schema({\n  address: {\n    type: String,\n    ip: true\n  }\n});\n```\n\n### `fqdn: Boolean`\nWhen set to `true` force value to be valid full qualified domain name.\n```js\nnew Schema({\n  address: {\n    type: String,\n    fqdn: true\n  }\n});\n```\n\n### `alpha: Boolean`\nWhen set to `true` force value to only contain alpha.\n```js\nnew Schema({\n  address: {\n    type: String,\n    alpha: true\n  }\n});\n```\n\n### `alphanumeric: Boolean`\nWhen set to `true` force value to contain only alphanumeric.\n```js\nnew Schema({\n  address: {\n    type: String,\n    aphanumeric: true\n  }\n});\n```\n\n### `md5: Boolean`\nWhen set to `true` force value to be valid md5 hash.\n```js\nnew Schema({\n  hash: {\n    type: String,\n    md5: true\n  }\n});\n```\n\n### `uuid: Boolean`\nWhen set to `true` force value to be valid uuid.\n```js\nnew Schema({\n  oid: {\n    type: String,\n    uuid: true\n  }\n});\n```\n\n### `creditcard: Boolean`\nWhen set to `true` force value to be valid credit card.\n```js\nnew Schema({\n  card: {\n    type: String,\n    creditcard: true\n  }\n});\n```\n\n### `base64: Boolean`\nWhen set to `true` force value to be valid base64 content.\n```js\nnew Schema({\n  url: {\n    type: String,\n    base64: true\n  }\n});\n```\n\n### `datauri: Boolean`\nWhen set to `true` force value to be valid data uri.\n```js\nnew Schema({\n  url: {\n    type: String,\n    datauri: true\n  }\n});\n```\n\n### `phone: Object|Boolean`\nWhen `set` it force value to be valid phone number.\n```js\nnew Schema({\n  phoneNumber: {\n    type: String,\n    phone: true\n  }\n});\n\nnew Schema({\n  phoneNumber: {\n    type: String,\n    phone: {\n      countries: ['TZ', 'US'],\n      e164: true\n    }\n  }\n});\n\nnew Schema({\n  phoneNumber: {\n    type: String,\n    phone: {\n      mobile: true,\n      e164: true\n    }\n  }\n});\n\nnew Schema({\n  phoneNumber: {\n    type: String,\n    phone: {\n      fixedline: true\n    }\n  }\n});\n```\n\n### `mimetype: Boolean`\nWhen set to `true` force value to be mime type value.\n```js\nnew Schema({\n  mime: {\n    type: String,\n    mimetype: true\n  }\n});\n```\n\n### `url: Boolean`\nWhen set to `true` force value to be valid url.\n```js\nnew Schema({\n  address: {\n    type: String,\n    url: true\n  }\n});\n```\n\n### `jwt: Boolean`\nWhen set to `true` force value to be valid json web token.\n```js\nnew Schema({\n  address: {\n    type: String,\n    jwt: true\n  }\n});\n```\n\n### `hexadecimal: Boolean`\nWhen set to `true` force value to be valid hexadecimal value.\n```js\nnew Schema({\n  address: {\n    type: String,\n    hexadecimal: true\n  }\n});\n```\n\n### `hexacolor: Boolean`\nWhen set to `true` force value to be valid hexacolor value.\n```js\nnew Schema({\n  address: {\n    type: String,\n    hexacolor: true\n  }\n});\n```\n\n## Number\n\n### `numeric: Boolean`\nWhen set to `true` force value to be numeric.\n```js\nnew Schema({\n  value: {\n    type: Number,\n    numeric: true\n  }\n});\n```\n\n### `integer: Boolean`\nWhen set to `true` force value to be integer.\n```js\nnew Schema({\n  step: {\n    type: Number,\n    integer: true\n  }\n});\n```\n\n### `float: Boolean`\nWhen set to `true` force value to float.\n```js\nnew Schema({\n  price: {\n    type: Number,\n    float: true\n  }\n});\n```\n\n## Array\n\n### `empty: Boolean` \nWhen set to `false` force non empty array value.\n```js\nnew Schema({\n  email: {\n    type: [String],\n    empty: false\n  }\n});\n```\n\n### `compact: Boolean` \nWhen set to `true` will remove falsey values.\n```js\nnew Schema({\n  email: {\n    type: [String],\n    compact: true\n  }\n})\n```\n\n### `duplicate: Boolean|Function` \nWhen set to `false` or `comparator` will remove duplicate values.\n```js\nnew Schema({\n  to: {\n    type: [String],\n    duplicate: false\n  }\n})\n\nor\n\nnew Schema({\n  to: {\n    type: [String],\n    duplicate: (a, b) =\u003e a === b\n  }\n})\n\n```\n\n### `sort: Boolean|String` \nWhen set to `true`, `asc` or `desc` create sorted elements.\n```js\nnew Schema({\n  to: {\n    type: [String],\n    sort: false\n  }\n})\n\nor\n\nnew Schema({\n  to: {\n    type: [String],\n    sort: 'desc'\n  }\n})\n\n```\n\n## Testing\n\n- Clone this repository\n\n- Install all development dependencies\n\n```sh\nnpm install\n```\n\n- Run example\n\n```sh\nnpm run dev\n```\n\n- Then run test\n\n```sh\nnpm test\n```\n\n## Contribute\n\nIt will be nice, if you open an issue first so that we can know what is going on, then, fork this repo and push in your ideas. Do not forget to add a bit of test(s) of what value you adding.\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) CodeTanzania \u0026 Contributors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flykmapipo%2Fmongoose-valid8","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flykmapipo%2Fmongoose-valid8","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flykmapipo%2Fmongoose-valid8/lists"}