Comparing version 0.2.2 to 1.0.0
17
index.js
/*! | ||
* write-json <https://github.com/jonschlinkert/write-json> | ||
* | ||
* Copyright (c) 2014-2015, Jon Schlinkert. | ||
* Licensed under the MIT License. | ||
* Copyright (c) 2014-2015, 2017, Jon Schlinkert. | ||
* Released under the MIT License. | ||
*/ | ||
@@ -16,4 +16,7 @@ | ||
module.exports = function writeJson(dest, obj, cb) { | ||
writeFile(dest, JSON.stringify(obj, null, 2), cb); | ||
module.exports = function writeJson(dest, data, cb) { | ||
var args = [].slice.call(arguments, 1); | ||
cb = args.pop(); | ||
if (args.length === 1) args.push(null, 2); | ||
writeFile(dest, JSON.stringify.apply(JSON, args), cb); | ||
}; | ||
@@ -25,5 +28,7 @@ | ||
module.exports.sync = function writeJsonSync(dest, obj) { | ||
module.exports.sync = function writeJsonSync(dest, data) { | ||
try { | ||
writeFile.sync(dest, JSON.stringify(obj, null, 2)); | ||
var args = [].slice.call(arguments, 1); | ||
if (args.length === 1) args.push(null, 2); | ||
writeFile.sync(dest, JSON.stringify.apply(JSON, args)); | ||
} catch (err) { | ||
@@ -30,0 +35,0 @@ throw err; |
{ | ||
"name": "write-json", | ||
"description": "Write a JSON file to disk, also creates intermediate directories in the destination path if they don't already exist.", | ||
"version": "0.2.2", | ||
"version": "1.0.0", | ||
"homepage": "https://github.com/jonschlinkert/write-json", | ||
@@ -23,7 +23,8 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"dependencies": { | ||
"write": "^0.2.1" | ||
"write": "^0.3.3" | ||
}, | ||
"devDependencies": { | ||
"delete": "^0.2.1", | ||
"mocha": "*" | ||
"delete": "^0.3.2", | ||
"gulp-format-md": "^0.1.12", | ||
"mocha": "^3.2.0" | ||
}, | ||
@@ -45,11 +46,21 @@ "keywords": [ | ||
"delete", | ||
"read-data", | ||
"read-json", | ||
"read-yaml", | ||
"write", | ||
"write-yaml", | ||
"read-yaml", | ||
"read-json", | ||
"read-data" | ||
], | ||
"description": "" | ||
"write-yaml" | ||
] | ||
}, | ||
"toc": false, | ||
"layout": "default", | ||
"tasks": [ | ||
"readme" | ||
], | ||
"plugins": [ | ||
"gulp-format-md" | ||
], | ||
"lint": { | ||
"reflinks": true | ||
} | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# write-json [![NPM version](https://badge.fury.io/js/write-json.svg)](http://badge.fury.io/js/write-json) [![Build Status](https://travis-ci.org/jonschlinkert/write-json.svg)](https://travis-ci.org/jonschlinkert/write-json) | ||
# write-json [![NPM version](https://img.shields.io/npm/v/write-json.svg?style=flat)](https://www.npmjs.com/package/write-json) [![NPM monthly downloads](https://img.shields.io/npm/dm/write-json.svg?style=flat)](https://npmjs.org/package/write-json) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/write-json.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/write-json) | ||
@@ -7,6 +7,6 @@ > Write a JSON file to disk, also creates intermediate directories in the destination path if they don't already exist. | ||
Install with [npm](https://www.npmjs.com/) | ||
Install with [npm](https://www.npmjs.com/): | ||
```sh | ||
$ npm i write-json --save | ||
$ npm install --save write-json | ||
``` | ||
@@ -21,44 +21,70 @@ | ||
writeJson('foo.json', {abc: 'xyz'}, function(err) { | ||
if (err) console.log(err); | ||
// do stuff with err | ||
}); | ||
// sync | ||
writeJson.sync('foo.json', , {abc: 'xyz'}); | ||
writeJson.sync('foo.json', {abc: 'xyz'}); | ||
``` | ||
## Related | ||
## JSON.stringify | ||
* [delete](https://www.npmjs.com/package/delete): Delete files and folders and any intermediate directories if they exist (sync and async). | [homepage](https://github.com/jonschlinkert/delete) | ||
* [read-data](https://www.npmjs.com/package/read-data): Read JSON or YAML files. | [homepage](https://github.com/jonschlinkert/read-data) | ||
* [read-json](https://www.npmjs.com/package/read-json): Reads and parses a JSON file. | [homepage](https://github.com/azer/read-json#readme) | ||
* [read-yaml](https://www.npmjs.com/package/read-yaml): Very thin wrapper around js-yaml for directly reading in YAML files. | [homepage](https://github.com/jonschlinkert/read-yaml) | ||
* [write](https://www.npmjs.com/package/write): Write files to disk, creating intermediate directories if they don't exist. | [homepage](https://github.com/jonschlinkert/write) | ||
* [write-yaml](https://www.npmjs.com/package/write-yaml): Write YAML. Converts JSON to YAML writes it to the specified file. | [homepage](https://github.com/jonschlinkert/write-yaml) | ||
Supports the same arguments as [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) | ||
## Running tests | ||
```js | ||
// async | ||
writeJson('foo.json', {abc: 'xyz'}, null, 2, function(err) { | ||
// do stuff with err | ||
}); | ||
Install dev dependencies: | ||
// sync | ||
writeJson.sync('foo.json', {abc: 'xyz'}, null, 2); | ||
``` | ||
## About | ||
### Related projects | ||
* [delete](https://www.npmjs.com/package/delete): Delete files and folders and any intermediate directories if they exist (sync and async). | [homepage](https://github.com/jonschlinkert/delete "Delete files and folders and any intermediate directories if they exist (sync and async).") | ||
* [read-data](https://www.npmjs.com/package/read-data): Read JSON or YAML files. | [homepage](https://github.com/jonschlinkert/read-data "Read JSON or YAML files.") | ||
* [read-json](https://www.npmjs.com/package/read-json): Reads and parses a JSON file. | [homepage](https://github.com/n-johnson/read-json#readme "Reads and parses a JSON file.") | ||
* [read-yaml](https://www.npmjs.com/package/read-yaml): Very thin wrapper around js-yaml for directly reading in YAML files. | [homepage](https://github.com/jonschlinkert/read-yaml "Very thin wrapper around js-yaml for directly reading in YAML files.") | ||
* [write-yaml](https://www.npmjs.com/package/write-yaml): Write YAML. Converts JSON to YAML writes it to the specified file. | [homepage](https://github.com/jonschlinkert/write-yaml "Write YAML. Converts JSON to YAML writes it to the specified file.") | ||
* [write](https://www.npmjs.com/package/write): Write files to disk, creating intermediate directories if they don't exist. | [homepage](https://github.com/jonschlinkert/write "Write files to disk, creating intermediate directories if they don't exist.") | ||
### Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). | ||
### Building docs | ||
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ | ||
To generate the readme, run the following command: | ||
```sh | ||
$ npm i -d && npm test | ||
$ npm install -g verbose/verb#dev verb-generate-readme && verb | ||
``` | ||
## Contributing | ||
### Running tests | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/write-json/issues/new). | ||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: | ||
## Author | ||
```sh | ||
$ npm install && npm test | ||
``` | ||
### Author | ||
**Jon Schlinkert** | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert) | ||
## License | ||
### License | ||
Copyright © 2015 Jon Schlinkert | ||
Released under the MIT license. | ||
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Released under the [MIT License](LICENSE). | ||
*** | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on November 17, 2015._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.5.0, on April 12, 2017._ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6817
29
0
88
3
+ Addedfs-exists-sync@0.1.0(transitive)
+ Addedwrite@0.3.3(transitive)
- Removedwrite@0.2.1(transitive)
Updatedwrite@^0.3.3