UNPKG

motion

Version:

motion - moving development forward

67 lines (66 loc) 5.4 kB
{ "_args": [ [ "jsonfile@https://registry.npmjs.org/jsonfile/-/jsonfile-2.2.3.tgz", "/Users/nw/flint/packages/flint" ] ], "_from": "jsonfile@>=2.1.0 <3.0.0", "_id": "jsonfile@2.2.3", "_inCache": true, "_location": "/jsonfile", "_phantomChildren": {}, "_requested": { "name": "jsonfile", "raw": "jsonfile@https://registry.npmjs.org/jsonfile/-/jsonfile-2.2.3.tgz", "rawSpec": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.2.3.tgz", "scope": null, "spec": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.2.3.tgz", "type": "remote" }, "_requiredBy": [ "/fs-extra" ], "_resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.2.3.tgz", "_shasum": "e252b99a6af901d3ec41f332589c90509a7bc605", "_shrinkwrap": null, "_spec": "jsonfile@https://registry.npmjs.org/jsonfile/-/jsonfile-2.2.3.tgz", "_where": "/Users/nw/flint/packages/flint", "author": { "email": "jprichardson@gmail.com", "name": "JP Richardson" }, "bugs": { "url": "https://github.com/jprichardson/node-jsonfile/issues" }, "dependencies": {}, "description": "Easily read/write JSON files.", "devDependencies": { "mocha": "2.x", "rimraf": "^2.4.0", "standard": "4.x" }, "homepage": "https://github.com/jprichardson/node-jsonfile#readme", "keywords": [ "file", "fs", "fs-extra", "json", "read", "write" ], "license": "MIT", "main": "index.js", "name": "jsonfile", "optionalDependencies": {}, "readme": "Node.js - jsonfile\n================\n\nEasily read/write JSON files.\n\n[![build status](https://secure.travis-ci.org/jprichardson/node-jsonfile.svg)](http://travis-ci.org/jprichardson/node-jsonfile)\n\n\nWhy?\n----\n\nWriting `JSON.stringify()` and then `fs.writeFile()` and `JSON.parse()` with `fs.readFile()` enclosed in `try/catch` blocks became annoying.\n\n\n\nInstallation\n------------\n\n npm install jsonfile --save\n\n\n\nAPI\n---\n\n### readFile(filename, [options], callback)\n\n`options`: Pass in any `fs.readFile` options or set `reviver` for a [JSON reviver](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).\n\n\n```js\nvar jsonfile = require('jsonfile')\nvar util = require('util')\n\nvar file = '/tmp/data.json'\njsonfile.readFile(file, function(err, obj) {\n console.dir(obj)\n})\n```\n\n\n### readFileSync(filename, [options])\n\n`options`: Pass in any `fs.readFileSync` options or set `reviver` for a [JSON reviver](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse). Also `throws` set to `false` if you don't ever want this method\nto throw on invalid JSON. Will return `null` instead. Defaults to `true`.\n\n```js\nvar jsonfile = require('jsonfile')\nvar util = require('util')\n\nvar file = '/tmp/data.json'\n\nconsole.dir(jsonfile.readFileSync(file))\n```\n\n\n### writeFile(filename, [options], callback)\n\n`options`: Pass in any `fs.writeFile` options or set `replacer` for a [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). Can also pass in `spaces`.\n\n\n```js\nvar jsonfile = require('jsonfile')\n\nvar file = '/tmp/data.json'\nvar obj = {name: 'JP'}\n\njsonfile.writeFile(file, obj, function (err) {\n console.error(err)\n})\n```\n\n**formatting with spaces:**\n\n```js\nvar jsonfile = require('jsonfile')\n\nvar file = '/tmp/data.json'\nvar obj = {name: 'JP'}\n\njsonfile.writeFile(file, obj, {spaces: 2}, function(err) {\n console.error(err)\n})\n```\n\n\n### writeFileSync(filename, [options])\n\n`options`: Pass in any `fs.writeFileSync` options or set `replacer` for a [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). Can also pass in `spaces`.\n\n```js\nvar jsonfile = require('jsonfile')\n\nvar file = '/tmp/data.json'\nvar obj = {name: 'JP'}\n\njsonfile.writeFileSync(file, obj)\n```\n\n**formatting with spaces:**\n\n```js\nvar jsonfile = require('jsonfile')\n\nvar file = '/tmp/data.json'\nvar obj = {name: 'JP'}\n\njsonfile.writeFileSync(file, obj, {spaces: 2})\n```\n\n\n\n### spaces\n\nGlobal configuration to set spaces to indent JSON files.\n\n**default:** `null`\n\n```js\nvar jsonfile = require('jsonfile')\n\njsonfile.spaces = 4;\n\nvar file = '/tmp/data.json'\nvar obj = {name: 'JP'}\n\n// json file has four space indenting now\njsonfile.writeFile(file, obj, function (err) {\n console.error(err)\n})\n```\n\nNote, it's bound to `this.spaces`. So, if you do this:\n\n```js\nvar myObj = {}\nmyObj.writeJsonSync = jsonfile.writeFileSync\n// => this.spaces = null\n```\n\nCould do the following:\n\n```js\nvar jsonfile = require('jsonfile')\njsonfile.spaces = 4\njsonfile.writeFileSync(file, obj) // will have 4 spaces indentation\n\nvar myCrazyObj = {spaces: 32}\nmyCrazyObj.writeJsonSync = jsonfile.writeFileSync\nmyCrazyObj.writeJsonSync(file, obj) // will have 32 space indentation\nmyCrazyObj.writeJsonSync(file, obj, {spaces: 2}) // will have only 2\n```\n\n\nLicense\n-------\n\n(MIT License)\n\nCopyright 2012-2015, JP Richardson <jprichardson@gmail.com>\n\n\n\n\n\n", "readmeFilename": "README.md", "repository": { "type": "git", "url": "git+ssh://git@github.com/jprichardson/node-jsonfile.git" }, "scripts": { "test": "standard && mocha" }, "version": "2.2.3" }