{ "_args": [ [ { "raw": "joi@^10.0.2", "scope": null, "escapedName": "joi", "name": "joi", "rawSpec": "^10.0.2", "spec": ">=10.0.2 <11.0.0", "type": "range" }, "/home/jdaugherty/work/GT2/GT2-Android/node_modules/xdl" ] ], "_from": "joi@>=10.0.2 <11.0.0", "_id": "joi@10.6.0", "_inCache": true, "_location": "/joi", "_nodeVersion": "6.11.0", "_npmOperationalInternal": { "host": "s3://npm-registry-packages", "tmp": "tmp/joi-10.6.0.tgz_1497548465053_0.7665833418723196" }, "_npmUser": { "name": "marsup", "email": "nicolas@morel.io" }, "_npmVersion": "5.0.3", "_phantomChildren": {}, "_requested": { "raw": "joi@^10.0.2", "scope": null, "escapedName": "joi", "name": "joi", "rawSpec": "^10.0.2", "spec": ">=10.0.2 <11.0.0", "type": "range" }, "_requiredBy": [ "/xdl" ], "_resolved": "https://registry.npmjs.org/joi/-/joi-10.6.0.tgz", "_shasum": "52587f02d52b8b75cdb0c74f0b164a191a0e1fc2", "_shrinkwrap": null, "_spec": "joi@^10.0.2", "_where": "/home/jdaugherty/work/GT2/GT2-Android/node_modules/xdl", "bugs": { "url": "https://github.com/hapijs/joi/issues" }, "dependencies": { "hoek": "4.x.x", "isemail": "2.x.x", "items": "2.x.x", "topo": "2.x.x" }, "description": "Object schema validation", "devDependencies": { "code": "4.x.x", "hapitoc": "1.x.x", "lab": "13.x.x" }, "directories": {}, "dist": { "integrity": "sha512-hBF3LcqyAid+9X/pwg+eXjD2QBZI5eXnBFJYaAkH4SK3mp9QSRiiQnDYlmlz5pccMvnLcJRS4whhDOTCkmsAdQ==", "shasum": "52587f02d52b8b75cdb0c74f0b164a191a0e1fc2", "tarball": "https://registry.npmjs.org/joi/-/joi-10.6.0.tgz" }, "engines": { "node": ">=4.0.0" }, "gitHead": "069bb6c04063cba202544dacf9da3bbe21fa3074", "homepage": "https://github.com/hapijs/joi", "keywords": [ "hapi", "schema", "validation" ], "license": "BSD-3-Clause", "main": "lib/index.js", "maintainers": [ { "name": "hueniverse", "email": "eran@hammer.io" }, { "name": "marsup", "email": "nicolas@morel.io" }, { "name": "nlf", "email": "quitlahok@gmail.com" }, { "name": "wyatt", "email": "wpreul@gmail.com" } ], "name": "joi", "optionalDependencies": {}, "readme": "![joi Logo](https://raw.github.com/hapijs/joi/master/images/joi.png)\n\nObject schema description language and validator for JavaScript objects.\n\n[![npm version](https://badge.fury.io/js/joi.svg)](http://badge.fury.io/js/joi)\n[![Build Status](https://secure.travis-ci.org/hapijs/joi.svg?branch=master)](http://travis-ci.org/hapijs/joi)\n\n[![NSP Status](https://nodesecurity.io/orgs/hapijs/projects/0394bf83-b5bc-410b-878c-e8cf1b92033e/badge)](https://nodesecurity.io/orgs/hapijs/projects/0394bf83-b5bc-410b-878c-e8cf1b92033e)\n[![Known Vulnerabilities](https://snyk.io/test/github/hapijs/joi/badge.svg)](https://snyk.io/test/github/hapijs/joi)\n\n[![Join the chat at https://gitter.im/hapijs/joi](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/hapijs/joi?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n\nLead Maintainer: [Nicolas Morel](https://github.com/marsup)\n\n# Introduction\n\nImagine you run facebook and you want visitors to sign up on the website with real names and not something like `l337_p@nda` in the first name field. How would you define the limitations of what can be inputted and validate it against the set rules?\n\nThis is joi, joi allows you to create *blueprints* or *schemas* for JavaScript objects (an object that stores information) to ensure *validation* of key information.\n\n\n# Example\n\n```javascript\nconst Joi = require('joi');\n\nconst schema = Joi.object().keys({\n username: Joi.string().alphanum().min(3).max(30).required(),\n password: Joi.string().regex(/^[a-zA-Z0-9]{3,30}$/),\n access_token: [Joi.string(), Joi.number()],\n birthyear: Joi.number().integer().min(1900).max(2013),\n email: Joi.string().email()\n}).with('username', 'birthyear').without('password', 'access_token');\n\n// Return result.\nconst result = Joi.validate({ username: 'abc', birthyear: 1994 }, schema);\n// result.error === null -> valid\n\n// You can also pass a callback which will be called synchronously with the validation result.\nJoi.validate({ username: 'abc', birthyear: 1994 }, schema, function (err, value) { }); // err === null -> valid\n\n```\n\nThe above schema defines the following constraints:\n* `username`\n * a required string\n * must contain only alphanumeric characters\n * at least 3 characters long but no more than 30\n * must be accompanied by `birthyear`\n* `password`\n * an optional string\n * must satisfy the custom regex\n * cannot appear together with `access_token`\n* `access_token`\n * an optional, unconstrained string or number\n* `birthyear`\n * an integer between 1900 and 2013\n* `email`\n * a valid email address string\n\n# Usage\n\nUsage is a two steps process. First, a schema is constructed using the provided types and constraints:\n\n```javascript\nconst schema = {\n a: Joi.string()\n};\n```\n\nNote that **joi** schema objects are immutable which means every additional rule added (e.g. `.min(5)`) will return a\nnew schema object.\n\nThen the value is validated against the schema:\n\n```javascript\nconst {error, value} = Joi.validate({ a: 'a string' }, schema);\n\n// or\n\nJoi.validate({ a: 'a string' }, schema, function (err, value) { });\n```\n\nIf the input is valid, then the error will be `null`, otherwise it will be an Error object.\n\nThe schema can be a plain JavaScript object where every key is assigned a **joi** type, or it can be a **joi** type directly:\n\n```javascript\nconst schema = Joi.string().min(10);\n```\n\nIf the schema is a **joi** type, the `schema.validate(value, callback)` can be called directly on the type. When passing a non-type schema object,\nthe module converts it internally to an object() type equivalent to:\n\n```javascript\nconst schema = Joi.object().keys({\n a: Joi.string()\n});\n```\n\nWhen validating a schema:\n\n* Values (or keys in case of objects) are optional by default.\n\n ```javascript\n Joi.validate(undefined, Joi.string()); // validates fine\n ```\n\n To disallow this behavior, you can either set the schema as `required()`, or set `presence` to `\"required\"` when passing `options`:\n\n ```javascript\n Joi.validate(undefined, Joi.string().required());\n // or\n Joi.validate(undefined, Joi.string(), /* options */ { presence: \"required\" });\n ```\n\n* Strings are utf-8 encoded by default.\n* Rules are defined in an additive fashion and evaluated in order after whitelist and blacklist checks.\n\n# API\nSee the [API Reference](https://github.com/hapijs/joi/blob/v10.6.0/API.md).\n\n# Browsers\n\nJoi doesn't directly support browsers, but you could use [joi-browser](https://github.com/jeffbski/joi-browser) for an ES5 build of Joi that works in browsers, or as a source of inspiration for your own builds.\n", "readmeFilename": "README.md", "repository": { "type": "git", "url": "git://github.com/hapijs/joi.git" }, "scripts": { "test": "lab -t 100 -a code -L", "test-cov-html": "lab -r html -o coverage.html -a code", "test-debug": "lab -a code", "toc": "hapitoc", "version": "npm run toc && git add API.md README.md" }, "version": "10.6.0" }