Skip to content

Commit bc0a612

Browse files
committed
readme: add throws to readJson()
1 parent 61376ce commit bc0a612

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ API
2828

2929
### readFile(filename, [options], callback)
3030

31-
`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).
31+
`options` (`object`, default `undefined`): 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).
32+
- `throws` (`boolean`, default: `true`). If `JSON.parse` throws an error, pass this error to the callback.
33+
If `false`, returns `null` for the object.
3234

3335

3436
```js
@@ -42,8 +44,9 @@ jsonfile.readFile(file, function(err, obj) {
4244

4345
### readFileSync(filename, [options])
4446

45-
`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
46-
to throw on invalid JSON. Will return `null` instead. Defaults to `true`.
47+
`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).
48+
- `throws` (`boolean`, default: `true`). If `JSON.parse` throws an error, throw the error.
49+
If `false`, returns `null` for the object.
4750

4851
```js
4952
var jsonfile = require('jsonfile')

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ function readFile (file, options, callback) {
1010
options = {encoding: options}
1111
}
1212

13-
if (options == null) {
14-
options = {}
15-
}
13+
options = options || {}
1614

1715
var shouldThrow = true
16+
// DO NOT USE 'passParsingErrors' THE NAME WILL CHANGE!!!, use 'throws' instead
1817
if ('passParsingErrors' in options) {
1918
shouldThrow = options.passParsingErrors
2019
} else if ('throws' in options) {
@@ -47,6 +46,7 @@ function readFileSync (file, options) {
4746
}
4847

4948
var shouldThrow = true
49+
// DO NOT USE 'passParsingErrors' THE NAME WILL CHANGE!!!, use 'throws' instead
5050
if ('passParsingErrors' in options) {
5151
shouldThrow = options.passParsingErrors
5252
} else if ('throws' in options) {

0 commit comments

Comments
 (0)