{"id":23134375,"url":"https://github.com/vmlweb/the-vladiator","last_synced_at":"2025-04-04T08:20:49.707Z","repository":{"id":58235833,"uuid":"61830507","full_name":"Vmlweb/The-Vladiator","owner":"Vmlweb","description":"Javascript validation and assertion library.","archived":false,"fork":false,"pushed_at":"2018-08-18T18:03:06.000Z","size":81,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-03T02:48:31.944Z","etag":null,"topics":["assertion","chain","validate","verbose"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/the-vladiator","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/Vmlweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-23T19:18:45.000Z","updated_at":"2024-08-12T17:22:39.000Z","dependencies_parsed_at":"2022-08-31T09:22:53.287Z","dependency_job_id":null,"html_url":"https://github.com/Vmlweb/The-Vladiator","commit_stats":null,"previous_names":["vmlweb/vladiator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vmlweb%2FThe-Vladiator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vmlweb%2FThe-Vladiator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vmlweb%2FThe-Vladiator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vmlweb%2FThe-Vladiator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vmlweb","download_url":"https://codeload.github.com/Vmlweb/The-Vladiator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247142419,"owners_count":20890724,"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":["assertion","chain","validate","verbose"],"created_at":"2024-12-17T12:10:17.876Z","updated_at":"2025-04-04T08:20:49.678Z","avatar_url":"https://github.com/Vmlweb.png","language":"JavaScript","readme":"# The Vladiator\n\n[![Build Status](http://bamboo.vmlweb.co.uk:8085/plugins/servlet/wittified/build-status/OPEN-VLAD)](http://bamboo.vmlweb.co.uk:8085/browse/OPEN-VLAD)\n\nJavascript validation and assertion library. Suggestions are welcome.\n\nIncludes Typescript definitions.\n\n## Installation\n\nYou can grab the latest version via NPM or Bower.\n\n```bash\nnpm install --save the-vladiator\nbower install --save the-vladiator\n```\n\nThen either use require through NodeJS.\n\n```javascript\nvar validate = require('the-vladiator');\nvalidate('email@email.com')\n```\n\nOr add as a script to your HTML.\n\n```html\n\u003cscript src=\"vladiator.js\"\u003e\u003c/script\u003e\n```\n```javascript\nvalidate('email@email.com')\n```\n\n## Getting Started\n\nBelow are some basic examples of usage.\n\n```javascript\nvar validate = require('the-vladiator');\n\n//E-mail address\nvalidate('email@email.com').isRequired().isString().isEmail().didPass(); //returns true if passed validation\n\n//Name\nvalidate('John').isRequired().isString().notEmpty().didFail(); //returns true if failed validation\n\n//Positive number\nvalidate(5).isRequired().isNumber().isPositive().throws('Number must be positive'); //throws if failed validation\n```\n\n### Type Checks\n\nYou can test whether your input is a certain type.\n\n```javascript\n.isBool()\n.notBool()\n\n.isTrue()\n.notTrue()\n\n.isFalse()\n.notFalse()\n\n.isNumber()\n.notNumber()\n\n.isString()\n.notString()\n\n.isDate()\n.notDate()\n\n.isArray()\n.notArray()\n\n.isObject()\n.notObject()\n\n//Checks for an array or object\n.isParent()\n.notParent()\n```\n\n### Equality Checks\n\n```javascript\n//Checks for equality using ===\n\n.isEqual(comparison)\n\n.notEqual(comparison)\n\n//Check contents using indexOf\n\n.contains(comparison)\n\n.notContains(comparison)\n```\n\n### Numeric Checks\n\n```javascript\n.isPositive()\n.isNegative()\n\n.higherThan(amount)\n.lowerThan(amount)\n```\n\n### Length Checks\n\n```javascript\n.isEmpty()\n.notEmpty()\n\n.hasLength(length)\n\n.longerThan(length)\n.shorterThan(length)\n```\n\n### Optional Checks\n\n```javascript\n//Ensures that value is defined, not null and not NaN\n.isRequired()\n\n//Skips remaining checks if value is undefined, null or NaN\n.isOptional()\n\n//Ensures the value is defined\n.valueRequired()\n\n//Skips remaining checks if value is undefined\n.valueOptional()\n```\n\n### Object Checks\n\n```javascript\n.missingKey(key)\n.hasKey(key)\n\n.missingValue(value)\n.hasValue(value)\n\n.missingKeyValue(key, value)\n.hasKeyValue(key, value)\n```\n\n### Nested Checks\n\n```javascript\n//The value can be replaced with a nested object one or more levels deeper\n.open('key')\n.open('firstKey.secondKey')\n\n//Iterates checking inside arrays or objects, all subsequent checks will be performed on each\n.extract()\n.extract('key')\n.extract('firstKey.secondKey')\n\n//Iterates checking through all nested levels inside arrays or objects\n.recursive()\n```\n\n### Custom Checks\n\n```javascript\n//Validates whether input is pie\n.is(function(value){\n\treturn value === Math.PI;\n});\n```\n\n### Other Checks\n\n```javascript\n.isEmail(email)\n.notEmail(email)\n\n//Checks for MongoDB ObjectIds\n.isMongoId()\n.notMongoId()\n\n//Checks whether value is an Enum.\n//Arguments are a mongoose model or schema and property name string\n.isMongoEnum(type, field)\n.notMongoEnum(type, field)\n\n//Checks whether value confirms to semver\n.isSemver(version)\n.notSemver(version)\n```\n\n### Other Stuff\n\n```javascript\n//Replaces the currently checking value\n.and(newValue)\n\n//Inverts the following checks result\n.not()\n\n//Changes values case\n.upperCase()\n.lowerCase()\n```\n\n### Advanced Examples\n\nWe can compose some pretty lengthy validation rules as demonstrated below though it's recommended to split them into smaller more readable chunks.\n\n#### Example One\n\n```javascript\nvalidate('myPassword').isString().longerThan(6).shorterThan(20).notContains('password').notEmail().throw('Enter a strong password')\n```\n\n#### Example Two\n\n```javascript\nvar data = {\n\tusernames: [\n\t\t'User1',\n\t\t'User2',\n\t\t'User3',\n\t\t'User4',\n\t\t'User5'\n\t],\n\temails: [\n\t\t'admin1@vmlweb.co.uk',\n\t\t'admin2@vmlweb.co.uk',\n\t\t'admin3@vmlweb.co.uk',\n\t\t'admin4@vmlweb.co.uk',\n\t\t'admin5@vmlweb.co.uk'\n\t]\n};\n\nvalidate(data).hasKey('usernames').hasKey('emails')\n\t.extract('usernames').isString().notEmpty()\n\t.and(data)\n\t.extract('emails').isString().isEmail()\n\t.throw('failed');\n```\n\n#### Example Three\n\n```javascript\nvar database = {\n\tusers: {\n\t\tmetadata: {},\n\t\tids: [\n\t\t\t'507f1f77bcf86cd799439011',\n\t\t\t'507f1f77bcf86cd799439012',\n\t\t\t'507f1f77bcf86cd799439013',\n\t\t\t'507f1f77bcf86cd799439014',\n\t\t\t'507f1f77bcf86cd799439015',\n\t\t\t'507f1f77bcf86cd799439016',\n\t\t\t'507f1f77bcf86cd799439017',\n\t\t\t'507f1f77bcf86cd799439018',\n\t\t\t'507f1f77bcf86cd799439019',\n\t\t\t'507f1f77bcf86cd799439020',\n\t\t\t'507f1f77bcf86cd799439021'\n\t\t]\n\t}\n};\n\nvalidate(database).extract('users.ids').isMongoId().is(function(value){\n\n\t//Check whether exists in database\n\tvar exists = true;\n\treturn exists;\n\n}).throw('failed');\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmlweb%2Fthe-vladiator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvmlweb%2Fthe-vladiator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmlweb%2Fthe-vladiator/lists"}