{ "name": "bower-json", "version": "0.4.0", "description": "Read bower.json files with semantics, normalisation, defaults and validation.", "author": { "name": "Twitter" }, "licenses": [ { "type": "MIT", "url": "https://github.com/bower/json/blob/master/LICENSE" } ], "repository": { "type": "git", "url": "git://github.com/bower/json.git" }, "main": "lib/json", "engines": { "node": ">=0.8.0" }, "dependencies": { "deep-extend": "~0.2.5", "graceful-fs": "~2.0.0", "intersect": "~0.0.3" }, "devDependencies": { "expect.js": "~0.2.0", "mocha": "~1.12.0", "grunt": "~0.4.1", "grunt-contrib-watch": "~0.4.4", "grunt-contrib-jshint": "~0.6.0", "grunt-simple-mocha": "~0.4.0" }, "scripts": { "test": "grunt test" }, "readme": "# bower-json [![Build Status](https://secure.travis-ci.org/bower/json.png?branch=master)](http://travis-ci.org/bower/json)\n\nRead `bower.json` files with semantics, normalisation, defaults and validation.\n\n\n## Usage\n\n#### .read(file, options, callback)\n\nReads `file` and applies normalisation, defaults and validation according to the `bower.json` spec. \nIf the passed `file` does not exist, the callback is called with `error.code` equal to `ENOENT`. \nIf the passed `file` contents are not valid JSON, the callback is called with `error.code` equal to `EMALFORMED`. \nIf the `json` does not comply with the `bower.json` spec, the callback is called with `error.code` equal to `EINVALID`.\n\nIf `file` is a directory, `find()` will be used to search for the json file. \nThe `options` argument is optional and can be omitted. These options will be passed to `parse` method.\n\n\n```js\nvar bowerJson = require('bower-json');\n\n// Can also be used by simply calling bowerJson()\nbowerJson.read('/path/to/bower.json', function (err, json) {\n if (err) {\n console.error('There was an error reading the file');\n console.error(err.message);\n return;\n }\n\n console.log('JSON: ', json);\n});\n```\n\n\n#### .parse(json, options)\n\nParses an object. Useful when you want to apply normalisation and validation directly to an object. \nIf the `json` does not comply with the `bower.json` spec, an error is thrown with `error.code` equal to `EINVALID`.\n\nThe `options` arguments is optional and can be omitted. Available options:\n\n- validate: Apply validation, defaults to `true`\n- normalize: Apply normalisation, defaults to `false`\n- clone: clone, use and return the passed in `json` object instead of using it directly, defaults to `false`\n\n\n```js\nvar bowerJson = require('bower-json');\n\nvar json = {\n name: 'my-package',\n version: '0.0.1'\n};\n\ntry {\n bowerJson.parse(json);\n} catch (err) {\n console.error('There was an error parsing the object');\n console.error(err.message);\n}\n```\n\n\n#### .validate(json)\n\nValidates the passed `json` object. \nThrows an error with `error.code` equal to `EINVALID` if it does not comply with the spec.\n\n\n```js\nvar bowerJson = require('bower-json');\n\nvar json = {\n name: 'my-package',\n version: '0.0.1'\n};\n\ntry {\n bowerJson.validate(json);\n} catch (err) {\n console.error('There was an error validating the object');\n console.error(err.message);\n}\n```\n\n\n#### .normalize(json)\n\n```js\nvar bowerJson = require('bower-json');\n\nvar json = {\n name: 'my-package',\n version: '0.0.1',\n main: 'foo.js,bar.js'\n};\n\nbowerJson.nornalize(json);\njson.main // ['foo.js', 'bar.js']\n```\n\n\n#### .find(folder, callback)\n\nFinds the `json` filename inside a folder. \nChecks if a `bower.json` exists, falling back to `component.json` (deprecated) and `.bower.json`. \nIf no file was found, the callback is called with a `error.code` of `ENOENT`.\n\n```js\nvar bowerJson = require('bower-json');\n\nbowerJson.find('/path/to/folder', function (err, filename) {\n if (err) {\n console.error('There is no json file in the folder');\n return;\n }\n\n console.log('Filename: ', filename);\n\n // Now that we got the filename, we can read its contents\n bowerJson.read(filename, function (err, json) {\n if (err) {\n console.error('There was an error reading the file');\n console.error(err.message);\n return;\n }\n\n console.log('JSON: ', json);\n });\n});\n```\n\n\n## License\n\nReleased under the [MIT License](http://www.opensource.org/licenses/mit-license.php).\n", "readmeFilename": "README.md", "bugs": { "url": "https://github.com/bower/json/issues" }, "homepage": "https://github.com/bower/json#readme", "_id": "bower-json@0.4.0", "_shasum": "a99c3ccf416ef0590ed0ded252c760f1c6d93766", "_resolved": "https://registry.npmjs.org/bower-json/-/bower-json-0.4.0.tgz", "_from": "bower-json@>=0.4.0 <0.5.0" }