jsdoc-75lb
Version:
An API documentation generator for JavaScript.
109 lines (108 loc) • 17.2 kB
JSON
{
"_args": [
[
{
"raw": "tv4@https://github.com/hegemonic/tv4/tarball/own-properties",
"scope": null,
"escapedName": "tv4",
"name": "tv4",
"rawSpec": "https://github.com/hegemonic/tv4/tarball/own-properties",
"spec": "https://github.com/hegemonic/tv4/tarball/own-properties",
"type": "remote"
},
"/Users/lloydb/Documents/jsdoc2md/jsdoc"
]
],
"_from": "https://github.com/hegemonic/tv4/tarball/own-properties",
"_id": "tv4@1.0.15",
"_inCache": true,
"_installable": true,
"_location": "/tv4",
"_phantomChildren": {},
"_requested": {
"raw": "tv4@https://github.com/hegemonic/tv4/tarball/own-properties",
"scope": null,
"escapedName": "tv4",
"name": "tv4",
"rawSpec": "https://github.com/hegemonic/tv4/tarball/own-properties",
"spec": "https://github.com/hegemonic/tv4/tarball/own-properties",
"type": "remote"
},
"_requiredBy": [
"#DEV:/"
],
"_resolved": "https://github.com/hegemonic/tv4/tarball/own-properties",
"_shasum": "081e6823ee51d67aabe5b92ea3a00804902be155",
"_shrinkwrap": null,
"_spec": "tv4@https://github.com/hegemonic/tv4/tarball/own-properties",
"_where": "/Users/lloydb/Documents/jsdoc2md/jsdoc",
"author": {
"name": "Geraint Luff"
},
"bugs": {
"url": "https://github.com/geraintluff/tv4/issues"
},
"dependencies": {},
"description": "A public domain JSON Schema validator for JavaScript",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-cli": "~0.1.9",
"grunt-component": "~0.1.4",
"grunt-concat-sourcemap": "~0.2",
"grunt-contrib-clean": "~0.4.1",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-jshint": "~0.6.2",
"grunt-contrib-uglify": "~0.2.2",
"grunt-markdown": "~0.3.0",
"grunt-mocha": "~0.4",
"grunt-mocha-test": "~0.5.0",
"grunt-push-release": "~0.1.1",
"grunt-regex-replace": "~0.2.5",
"jshint-path-reporter": "~0.1",
"mocha": "~1.11.0",
"mocha-unfunk-reporter": "~0.2",
"proclaim": "1.4",
"source-map-support": "~0.1"
},
"engines": {
"node": ">= 0.8.0"
},
"homepage": "https://github.com/geraintluff/tv4#readme",
"keywords": [
"json-schema",
"schema",
"validator",
"tv4"
],
"license:": [
{
"type": "Public Domain",
"url": "http://geraintluff.github.io/tv4/LICENSE.txt"
},
{
"type": "MIT",
"url": "http://jsonary.com/LICENSE.txt"
}
],
"main": "tv4.js",
"maintainers": [
{
"name": "Geraint Luff",
"email": "luffgd@gmail.com",
"url": "https://github.com/geraintluff/"
}
],
"name": "tv4",
"optionalDependencies": {},
"readme": "# Tiny Validator (for v4 JSON Schema)\n\n[](http://travis-ci.org/geraintluff/tv4) [](https://gemnasium.com/geraintluff/tv4) [](http://badge.fury.io/js/tv4)\n\nUse [json-schema](http://json-schema.org/) [draft v4](http://json-schema.org/latest/json-schema-core.html) to validate simple values and complex objects using a rich [validation vocabulary](http://json-schema.org/latest/json-schema-validation.html) ([examples](http://json-schema.org/examples.html)).\n\nThere is support for `$ref` with JSON Pointer fragment paths (```other-schema.json#/properties/myKey```).\n\n## Usage 1: Simple validation\n\n```javascript\nvar valid = tv4.validate(data, schema);\n```\n\nIf validation returns ```false```, then an explanation of why validation failed can be found in ```tv4.error```.\n\nThe error object will look something like:\n```json\n{\n \"code\": 0,\n \"message\": \"Invalid type: string\",\n \"dataPath\": \"/intKey\",\n \"schemaKey\": \"/properties/intKey/type\"\n}\n```\n\nThe `\"code\"` property will refer to one of the values in `tv4.errorCodes` - in this case, `tv4.errorCodes.INVALID_TYPE`.\n\nTo enable external schema to be referenced, you use:\n```javascript\ntv4.addSchema(url, schema);\n```\n\nIf schemas are referenced (```$ref```) but not known, then validation will return ```true``` and the missing schema(s) will be listed in ```tv4.missing```. For more info see the API documentation below.\n\n## Usage 2: Multi-threaded validation\n\nStoring the error and missing schemas does not work well in multi-threaded environments, so there is an alternative syntax:\n\n```javascript\nvar result = tv4.validateResult(data, schema);\n```\n\nThe result will look something like:\n```json\n{\n \"valid\": false,\n \"error\": {...},\n \"missing\": [...]\n}\n```\n\n## Usage 3: Multiple errors\n\nNormally, `tv4` stops when it encounters the first validation error. However, you can collect an array of validation errors using:\n\n```javascript\nvar result = tv4.validateMultiple(data, schema);\n```\n\nThe result will look something like:\n```json\n{\n \"valid\": false,\n \"errors\": [\n {...},\n ...\n ],\n \"missing\": [...]\n}\n```\n\n## Asynchronous validation\n\nSupport for asynchronous validation (where missing schemas are fetched) can be added by including an extra JavaScript file. Currently, the only version requires jQuery (`tv4.async-jquery.js`), but the code is very short and should be fairly easy to modify for other libraries (such as MooTools).\n\nUsage:\n\n```javascript\ntv4.validate(data, schema, function (isValid, validationError) { ... });\n```\n\n`validationFailure` is simply taken from `tv4.error`.\n\n## Options\n\nYou can use several options to change tv4's behavior when validating objects. Pass in an object to set these options for any of the regular validation methods:\n\n```javascript\ntv4.validate(data, schema, {checkRecursive: true});\nvar result = tv4.validateResult(data, schema, {checkRecursive: true});\nvar multiple = tv4.validateMultiple(data, schema, {checkRecursive: true});\n```\n\nFor backwards compatibility, you can also pass in two booleans to set the `checkRecursive` and `banUnknownProperties` options; this method signature is deprecated:\n\n```javascript\n// Set checkRecursive to false (the default) and banUnknownProperties to true\ntv4.validate(data, schema, false, true);\n```\n\nThe following sections describe the validation options.\n\n### Cyclical JavaScript objects\n\nWhile they don't occur in proper JSON, JavaScript does support self-referencing objects. Any of the above calls support a checkRecursive option. If true, tv4 will handle self-referencing objects properly - this slows down validation slightly, but that's better than a hanging script.\n\nConsider this data, notice how both `a` and `b` refer to each other:\n\n```javascript\nvar a = {};\nvar b = { a: a };\na.b = b;\nvar aSchema = { properties: { b: { $ref: 'bSchema' }}};\nvar bSchema = { properties: { a: { $ref: 'aSchema' }}};\ntv4.addSchema('aSchema', aSchema);\ntv4.addSchema('bSchema', bSchema);\n```\n\nBy default, this causes the validation methods to throw a \"too much recursion\" error.\n\nTo enable support for self-referencing objects, set the checkRecursive option to `true`:\n\n```javascript\ntv4.validate(a, aSchema, {checkRecursive: true});\ntv4.validate(a, schema, asynchronousFunction, {checkRecursive: true});\n\ntv4.validateResult(a, aSchema, {checkRecursive: true});\ntv4.validateMultiple(a, aSchema, {checkRecursive: true});\n```\n\n### Properties not defined in the schema\n\nAn object's schema may include an additionalProperties setting. When additionalProperties is set to `false`, objects will fail validation if they include properties that are not defined in the schema.\n\nYou can enforce this behavior for all object schema by setting tv4's banUnknownProperties option to `true`:\n\n```javascript\ntv4.validate(data, schema, {banUnknownProperties: true});\ntv4.validate(data, schema, asynchronousFunction, {banUnknownProperties: true});\n\ntv4.validateResult(data, schema, {banUnknownProperties: true});\ntv4.validateMultiple(data, schema, {banUnknownProperties: true});\n```\n\n### Inherited properties\n\nBy default, tv4 does not validate an object's inherited properties, which are ignored when you convert an object to JSON. This behavior differs from tv4 1.0.16 and earlier, which always validated inherited properties.\n\nTo validate inherited properties, set tv4's checkInheritedProperties option to `true`:\n\n```javascript\ntv4.validate(data, schema, {checkInheritedProperties: true});\ntv4.validate(data, schema, asynchronousFunction, {checkInheritedProperties: true});\n\ntv4.validateResult(data, schema, {checkInheritedProperties: true});\ntv4.validateMultiple(data, schema, {checkInheritedProperties: true});\n```\n\n### Non-enumerable properties\n\nBy default, tv4 does not validate an object's own non-enumerable properties, which are ignored when you convert an object to JSON. This behavior differs from tv4 1.0.16 and earlier, which always validated an object's own non-enumerable properties.\n\nTo validate an object's own non-enumerable properties, set tv4's checkNonEnumerableProperties option to `true`:\n\n```javascript\ntv4.validate(data, schema, {checkNonEnumerableProperties: true});\ntv4.validate(data, schema, asynchronousFunction, {checkNonEnumerableProperties: true});\n\ntv4.validateResult(data, schema, {checkNonEnumerableProperties: true});\ntv4.validateMultiple(data, schema, {checkNonEnumerableProperties: true});\n```\n\n## API\n\nThere are additional api commands available for more complex use-cases:\n\n##### addSchema(uri, schema)\nPre-register a schema for reference by other schema and synchronous validation.\n\n````js\ntv4.addSchema('http://example.com/schema', { ... });\n````\n\n* `uri` the uri to identify this schema.\n* `schema` the schema object.\n\nSchemas that have their `id` property set can be added directly.\n\n````js\ntv4.addSchema({ ... });\n````\n\n##### getSchema(uri)\n\nReturn a schema from the cache.\n\n* `uri` the uri of the schema (may contain a `#` fragment)\n\n````js\nvar schema = tv4.getSchema('http://example.com/schema');\n````\n\n##### getSchemaMap()\n\nReturn a shallow copy of the schema cache, mapping schema document URIs to schema objects.\n\n````\nvar map = tv4.getSchemaMap();\n\nvar schema = map[uri];\n````\n\n##### getSchemaUris(filter)\n\nReturn an Array with known schema document URIs.\n\n* `filter` optional RegExp to filter URIs\n\n````\nvar arr = tv4.getSchemaUris();\n\n// optional filter using a RegExp\nvar arr = tv4.getSchemaUris(/^https?://example.com/);\n````\n\n##### getMissingUris(filter)\n\nReturn an Array with schema document URIs that are used as `$ref` in known schemas but which currently have no associated schema data.\n\nUse this in combination with `tv4.addSchema(uri, schema)` to preload the cache for complete synchronous validation with.\n\n* `filter` optional RegExp to filter URIs\n\n````\nvar arr = tv4.getMissingUris();\n\n// optional filter using a RegExp\nvar arr = tv4.getMissingUris(/^https?://example.com/);\n````\n\n##### dropSchemas()\n\nDrop all known schema document URIs from the cache.\n\n````\ntv4.dropSchemas();\n````\n\n##### freshApi()\n\nReturn a new tv4 instance with no shared state.\n\n````\nvar otherTV4 = tv4.freshApi();\n````\n\n##### reset()\n\nManually reset validation status from the simple `tv4.validate(data, schema)`. Although tv4 will self reset on each validation there are some implementation scenarios where this is useful.\n\n````\ntv4.reset();\n````\n\n##### language(code)\n\nSelect the language map used for reporting.\n\n* `code` is a language code, like `'en'` or `'en-gb'`\n\n````\ntv4.language('en-gb');\n````\n\n##### addLanguage(code, map)\n\nAdd a new language map for selection by `tv4.language(code)`\n\n* `code` is new language code\n* `map` is an object mapping error IDs or constant names (e.g. `103` or `\"NUMBER_MAXIMUM\"`) to language strings.\n\n````\ntv4.addLanguage('fr', { ... });\n\n// select for use\ntv4.language('fr')\n````\n\n##### addFormat(format, validationFunction)\n\nAdd a custom format validator. (There are no built-in format validators.)\n\n* `format` is a string, corresponding to the `\"format\"` value in schemas.\n* `validationFunction` is a function that either returns:\n * `null` (meaning no error)\n * an error string (explaining the reason for failure)\n\n````\ntv4.addFormat('decimal-digits', function (data, schema) {\n\tif (typeof data === 'string' && !/^[0-9]+$/.test(data)) {\n\t\treturn null;\n\t}\n\treturn \"must be string of decimal digits\";\n});\n````\n\nAlternatively, multiple formats can be added at the same time using an object:\n````\ntv4.addFormat({\n\t'my-format': function () {...},\n\t'other-format': function () {...}\n});\n````\n\n## Demos\n\n### Basic usage\n<div class=\"content inline-demo\" markdown=\"1\" data-demo=\"demo1\">\n<pre class=\"code\" id=\"demo1\">\nvar schema = {\n\t\"items\": {\n\t\t\"type\": \"boolean\"\n\t}\n};\nvar data1 = [true, false];\nvar data2 = [true, 123];\n\nalert(\"data 1: \" + tv4.validate(data1, schema)); // true\nalert(\"data 2: \" + tv4.validate(data2, schema)); // false\nalert(\"data 2 error: \" + JSON.stringify(tv4.error, null, 4));\n</pre>\n</div>\n\n### Use of <code>$ref</code>\n<div class=\"content inline-demo\" markdown=\"1\" data-demo=\"demo2\">\n<pre class=\"code\" id=\"demo2\">\nvar schema = {\n\t\"type\": \"array\",\n\t\"items\": {\"$ref\": \"#\"}\n};\nvar data1 = [[], [[]]];\nvar data2 = [[], [true, []]];\n\nalert(\"data 1: \" + tv4.validate(data1, schema)); // true\nalert(\"data 2: \" + tv4.validate(data2, schema)); // false\n</pre>\n</div>\n\n### Missing schema\n<div class=\"content inline-demo\" markdown=\"1\" data-demo=\"demo3\">\n<pre class=\"code\" id=\"demo3\">\nvar schema = {\n\t\"type\": \"array\",\n\t\"items\": {\"$ref\": \"http://example.com/schema\" }\n};\nvar data = [1, 2, 3];\n\nalert(\"Valid: \" + tv4.validate(data, schema)); // true\nalert(\"Missing schemas: \" + JSON.stringify(tv4.missing));\n</pre>\n</div>\n\n### Referencing remote schema\n<div class=\"content inline-demo\" markdown=\"1\" data-demo=\"demo4\">\n<pre class=\"code\" id=\"demo4\">\ntv4.addSchema(\"http://example.com/schema\", {\n\t\"definitions\": {\n\t\t\"arrayItem\": {\"type\": \"boolean\"}\n\t}\n});\nvar schema = {\n\t\"type\": \"array\",\n\t\"items\": {\"$ref\": \"http://example.com/schema#/definitions/arrayItem\" }\n};\nvar data1 = [true, false, true];\nvar data2 = [1, 2, 3];\n\nalert(\"data 1: \" + tv4.validate(data1, schema)); // true\nalert(\"data 2: \" + tv4.validate(data2, schema)); // false\n</pre>\n</div>\n\n## Supported platforms\n\n* Node.js\n* All modern browsers\n* IE >= 7\n\n## Installation\n\nYou can manually download [`tv4.js`](https://raw.github.com/geraintluff/tv4/master/tv4.js) or the minified [`tv4.min.js`](https://raw.github.com/geraintluff/tv4/master/tv4.min.js) and include it in your html to create the global `tv4` variable.\n\nAlternately use it as a CommonJS module:\n\n````js\nvar tv4 = require('tv4');\n````\n\n#### npm\n\n````\n$ npm install tv4\n````\n\n#### bower\n\n````\n$ bower install tv4\n````\n\n#### component.io\n\n````\n$ component install geraintluff/tv4\n````\n\n## Build and test\n\nYou can rebuild and run the node and browser tests using node.js and [grunt](http://http://gruntjs.com/):\n\nMake sure you have the global grunt cli command:\n````\n$ npm install grunt-cli -g\n````\n\nClone the git repos, open a shell in the root folder and install the development dependencies:\n\n````\n$ npm install\n````\n\nRebuild and run the tests:\n````\n$ grunt\n````\n\nIt will run a build and display one Spec-style report for the node.js and two Dot-style reports for both the plain and minified browser tests (via phantomJS). You can also use your own browser to manually run the suites by opening [`test/index.html`](http://geraintluff.github.io/tv4/test/index.html) and [`test/index-min.html`](http://geraintluff.github.io/tv4/test/index-min.html).\n\n## Contributing\n\nPull-requests for fixes and expansions are welcome. Edit the partial files in `/source` and add your tests in a suitable suite or folder under `/test/tests` and run `grunt` to rebuild and run the test suite. Try to maintain an idiomatic coding style and add tests for any new features. It is recommend to discuss big changes in an Issue.\n\n## Packages using tv4\n\n* [chai-json-schema](http://chaijs.com/plugins/chai-json-schema) is a [Chai Assertion Library](http://chaijs.com) plugin to assert values against json-schema.\n* [grunt-tv4](http://www.github.com/Bartvds/grunt-tv4) is a plugin for [Grunt](http://http://gruntjs.com/) that uses tv4 to bulk validate json files.\n\n## License\n\nThe code is available as \"public domain\", meaning that it is completely free to use, without any restrictions at all. Read the full license [here](http://geraintluff.github.com/tv4/LICENSE.txt).\n\nIt's also available under an [MIT license](http://jsonary.com/LICENSE.txt).\n",
"readmeFilename": "README.md",
"repository": {
"type": "git",
"url": "git+https://github.com/geraintluff/tv4.git"
},
"scripts": {
"prepublish": "grunt prepublish",
"test": "grunt test"
},
"version": "1.0.15"
}