{ "name": "grunt-tv4", "description": "Validate values against json-schema v4", "version": "0.4.0", "homepage": "https://github.com/Bartvds/grunt-tv4", "author": { "name": "Bart van der Schoor", "url": "https://github.com/Bartvds" }, "repository": { "type": "git", "url": "https://github.com/Bartvds/grunt-tv4" }, "bugs": { "url": "https://github.com/Bartvds/grunt-tv4/issues" }, "licenses": [ { "type": "MIT", "url": "https://github.com/Bartvds/grunt-tv4/blob/master/LICENSE-MIT" } ], "keywords": [ "gruntplugin", "validate", "validator", "json", "schema", "json-schema", "tv4" ], "main": "Gruntfile.js", "engines": { "node": ">= 0.10.0" }, "scripts": { "test": "grunt test" }, "dependencies": { "jsonpointer.js": "0.3.0", "request": "2.25.0", "tv4": "~1.0.14", "ministyle": "~0.1.0", "miniwrite": "~0.1.0", "tv4-reporter": "~0.0.3" }, "devDependencies": { "grunt-cli": "~0.1", "grunt": "~0.4.1", "grunt-contrib-connect": "~0.3.0", "grunt-continue": "0.0.1", "grunt-contrib-jshint": "~0.7.2", "jshint-path-reporter": "~0.1.3", "package.json-schema": "~0.1.2", "request": "^2.25.0" }, "peerDependencies": { "grunt": "~0.4.1" }, "readme": "# grunt-tv4\r\n\r\n[![Build Status](https://secure.travis-ci.org/Bartvds/grunt-tv4.png?branch=master)](http://travis-ci.org/Bartvds/grunt-tv4) [![Dependency Status](https://gemnasium.com/Bartvds/grunt-tv4.png)](https://gemnasium.com/Bartvds/grunt-tv4) [![NPM version](https://badge.fury.io/js/grunt-tv4.png)](http://badge.fury.io/js/grunt-tv4)\r\n\r\n> Use grunt and [Tiny Validator tv4](https://github.com/geraintluff/tv4) to validate values against [json-schema](http://json-schema.org/) draft v4\r\n\r\n## Getting Started\r\n\r\nThis plugin requires Grunt `~0.4.1`\r\n\r\nIf you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:\r\n\r\n```shell\r\n$ npm install grunt-tv4 --save-dev\r\n```\r\n\r\nOnce the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:\r\n\r\n```js\r\ngrunt.loadNpmTasks('grunt-tv4');\r\n```\r\n\r\n## The \"tv4\" task\r\n\r\n### Notes\r\n\r\n* Uses [Tiny Validator tv4 ](https://github.com/geraintluff/tv4) so schemas must conform to [json-schema draft v4](http://json-schema.org/documentation.html).\r\n* Supports automatically resolution and loading remote references by http via `$ref`. \r\n* To use `$ref` see the [json-schema](http://json-schema.org/) documentation or [this help](http://spacetelescope.github.io/understanding-json-schema/structuring.html). \r\n* For general help with json-schema see this excelent [guide](http://spacetelescope.github.io/understanding-json-schema/) and usable [reference](http://spacetelescope.github.io/understanding-json-schema/reference/index.html).\r\n* Errors formatted by the [tv4-reporter](https://github.com/Bartvds/tv4-reporter) library.\r\n\r\n### API change \r\n\r\nAs of version `v0.2.0` the API was changed to follow the Grunt options- and file-selection conventions. The old pattern (which abused the destination-specifier) is no longer supported. The readme for the previous API can be found [here](https://github.com/Bartvds/grunt-tv4/tree/71ef1726945d05efd5daca29f26cbf4ab09c858e).\r\n\r\nThe root schema must now to be specified as `options.root`.\r\n\r\n### Example\r\n\r\n* Demo of version `v0.3.0` output on [travis-ci](https://travis-ci.org/Bartvds/grunt-tv4/jobs/14468920)\r\n\r\n### Basic usage\r\n\r\nValidate from .json files:\r\n\r\n```js\r\ngrunt.initConfig({\r\n\ttv4: {\r\n\t\toptions: {\r\n\t\t root: grunt.file.readJSON('schema/main.json')\r\n\t\t}\r\n\t\tmyTarget: {\r\n\t\t\tsrc: ['data/*.json']\r\n\t\t}\r\n\t}\r\n})\r\n```\r\n\r\nValdiate values:\r\n\r\n```js\r\ngrunt.initConfig({\r\n\ttv4: {\r\n\t\tmyTarget: {\r\n\t\t\toptions: {\r\n\t\t\t\troot: {\r\n\t\t\t\t\ttype: 'object',\r\n\t\t\t\t\tproperties: { ... }\r\n\t\t\t\t}\r\n\t\t\t},\r\n\t\t\tvalues: [\r\n\t\t\t\t{ ... },\r\n\t\t\t\t{ ... }\r\n\t\t\t]\r\n\t\t}\r\n\t}\r\n})\r\n````\r\n\r\n### Advanced usage\r\n\r\n```js\r\ngrunt.initConfig({\r\n\ttv4: {\r\n\t\toptions: {\r\n\t\t\t// specify the main schema, one of:\r\n // - path to json\r\n // - http-url\r\n // - schema object\r\n // - callback that returns one of the above\r\n\t\t\troot: grunt.file.readJSON('schema/main.json'),\r\n\r\n\t\t\t// show multiple errors per file (off by default)\r\n\t\t\tmulti: true,\r\n\r\n\t\t\t// create a new tv4 instance for every target (off by default)\r\n\t\t\tfresh: true,\r\n\r\n\t\t\t// add schemas in bulk (each required to have an 'id' property) (can be a callback)\r\n\t\t\tadd: [\r\n\t\t\t\t grunt.file.readJSON('schema/apple.json'),\r\n\t\t\t\t grunt.file.readJSON('schema/pear.json')\r\n\t\t\t],\r\n\r\n\t\t\t// set schemas by URI (can be a callback)\r\n\t\t\tschemas: {\r\n\t\t\t\t'http://example.com/schema/apple': grunt.file.readJSON('schema/apple.json'),\r\n\t\t\t\t'http://example.com/schema/pear': grunt.file.readJSON('schema/pear.json')\r\n\t\t\t},\r\n\r\n\t\t\t// map of custom formats passed to tv4.addFormat()\r\n\t\t\tformats: {\r\n\t\t\t\tdate: function (data, schema) {\r\n\t\t\t\t\tif (typeof data !== 'string' || !dateRegex.test(data)) {\r\n\t\t\t\t\t\treturn 'value must be string of the form: YYYY-MM-DD';\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn null;\r\n\t\t\t\t}\r\n\t\t\t},\r\n\r\n\t\t\t// passed to tv4.validate()\r\n\t\t\tcheckRecursive: false\r\n\t\t\t// passed to tv4.validate()\r\n\t\t\tbanUnknownProperties: false\r\n\t\t\t// passed tv4.language()\r\n\t\t\tlanguage: 'de'\r\n\t\t\t// passed tv4.addLanguage()\r\n\t\t\tlanguages: {\r\n\t\t\t\t'de': { ... }\r\n\t\t\t}\r\n\t\t},\r\n\t\t// load json from disk\r\n\t\tmyFiles: {\r\n\t\t\tsrc: ['data/*.json', 'data/fruit/**/*.json']\r\n\t\t},\r\n\r\n\t\tmyValues: {\r\n\t\t\t// validate values\r\n\t\t\tvalues: [\r\n\t\t\t\tgrunt.file.readJSON('data/apple.json'),\r\n\t\t\t\tgrunt.file.readJSON('data/pear.json')\r\n\t\t\t],\r\n\t\t},\r\n\r\n\t\tmyValueMap: {\r\n\t\t\t// alternately pass as object and the keys will be used as labels in the reports\r\n\t\t\tvalues: {\r\n\t\t\t\t'apple': grunt.file.readJSON('data/apple.json'),\r\n\t\t\t\t'pear': grunt.file.readJSON('data/pear.json')\r\n\t\t\t},\r\n\t\t},\r\n\r\n\t\tmyCallback: {\r\n\t\t\t// alternately pass a function() to return a collection of values (array or object)\r\n\t\t\tvalues: function() {\r\n\t\t\t\treturn {\r\n\t\t\t\t\t'apple': grunt.file.readJSON('data/apple.json'),\r\n\t\t\t\t\t'pear': grunt.file.readJSON('data/pear.json')\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n})\r\n```\r\n\r\n## History\r\n\r\n* 0.4.0 - Updated some depedencies. `root`, `add` and `schemas` can be a callback function (for lazy init).\r\n* 0.3.0 - Big internal rewrite:\r\n\t* Added `.values` option. \r\n\t* Extracted reporting to [tv4-reporter](https://github.com/Bartvds/tv4-reporter), [miniwrite](https://github.com/Bartvds/miniwrite) and [ministyle](https://github.com/Bartvds/ministyle).\r\n\t* Moved loader logic to own stand-alone module (for later extraction)\r\n\t* Extracted test-running logic to own module (for later extraction)\r\n* 0.2.1 - Added support to report subErrors (for anyOf/oneOf)\r\n* 0.2.0 - Updated to follow the Grunt conventions.\r\n* 0.1.4 - Updated `tv4` to version `1.0.11` \r\n * Added support for `tv4.addFormat()` / `languages` / `checkRecursive` / `banUnknownProperties`.\r\n* 0.1.3 - Support for loading remote references (JSON Schema's `$ref`).\r\n* 0.1.1 - Bugfixes and improved reporting\r\n* 0.1.0 - First release with synchronous validation\r\n\r\n\r\n## Contributing\r\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).\r\n\r\n\r\n[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/Bartvds/grunt-tv4/trend.png)](https://bitdeli.com/free \"Bitdeli Badge\")\r\n\r\n", "readmeFilename": "README.md", "_id": "grunt-tv4@0.4.0", "dist": { "shasum": "2b6e01be443cffeb8654e47bf2fa64f7c65fdd0b" }, "_from": "grunt-tv4@", "_resolved": "https://registry.npmjs.org/grunt-tv4/-/grunt-tv4-0.4.0.tgz" }