Comparing version 2.4.0 to 3.0.0
@@ -0,1 +1,6 @@ | ||
3.0.0 / 2017-04-25 | ||
------------------ | ||
- Changed behavior of `throws` option for `readFileSync`; now does not throw filesystem errors when `throws` is `false` | ||
2.4.0 / 2016-09-15 | ||
@@ -2,0 +7,0 @@ ------------------ |
@@ -66,6 +66,5 @@ var _fs | ||
var content = fs.readFileSync(file, options) | ||
content = stripBom(content) | ||
try { | ||
var content = fs.readFileSync(file, options) | ||
content = stripBom(content) | ||
return JSON.parse(content, options.reviver) | ||
@@ -72,0 +71,0 @@ } catch (err) { |
{ | ||
"name": "jsonfile", | ||
"version": "2.4.0", | ||
"version": "3.0.0", | ||
"description": "Easily read/write JSON files.", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -47,5 +47,4 @@ Node.js - jsonfile | ||
`options` (`object`, default `undefined`): 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). | ||
- `throws` (`boolean`, default: `true`). If `JSON.parse` throws an error, throw the error. | ||
If `false`, returns `null` for the object. | ||
`options` (`object`, default `undefined`): 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). | ||
- `throws` (`boolean`, default: `true`). If an error is encountered reading or parsing the file, throw the error. If `false`, returns `null` for the object. | ||
@@ -89,3 +88,17 @@ ```js | ||
**appending to an existing JSON file:** | ||
You can use `fs.writeFile` option `{flag: 'a'}` to achieve this. | ||
```js | ||
var jsonfile = require('jsonfile') | ||
var file = '/tmp/mayAlreadyExistedData.json' | ||
var obj = {name: 'JP'} | ||
jsonfile.writeFile(file, obj, {flag: 'a'}, function (err) { | ||
console.error(err) | ||
}) | ||
``` | ||
### writeFileSync(filename, obj, [options]) | ||
@@ -115,4 +128,15 @@ | ||
**appending to an existing JSON file:** | ||
You can use `fs.writeFileSync` option `{flag: 'a'}` to achieve this. | ||
```js | ||
var jsonfile = require('jsonfile') | ||
var file = '/tmp/mayAlreadyExistedData.json' | ||
var obj = {name: 'JP'} | ||
jsonfile.writeFileSync(file, obj, {flag: 'a'}) | ||
``` | ||
### spaces | ||
@@ -119,0 +143,0 @@ |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
17116
187
6
1