Skip to content

Commit c2753d5

Browse files
bbbrrriiiaaannnRyanZim
authored andcommitted
Add index to API + slight cleanup (#116)
This adds anchor links to API functions for easiest possible browsing of the package. This also adds horizontal rules between function descriptions for easier visual parsing; and links `fs` references to Nodejs.org documentation.
1 parent 5f647af commit c2753d5

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,16 @@ Installation
2626
API
2727
---
2828

29+
* [`readFile(filename, [options], callback)`](#readfilefilename-options-callback)
30+
* [`readFileSync(filename, [options])`](#readfilesyncfilename-options)
31+
* [`writeFile(filename, obj, [options], callback)`](#writefilefilename-obj-options-callback)
32+
* [`writeFileSync(filename, obj, [options])`](#writefilesyncfilename-obj-options)
33+
34+
----
35+
2936
### readFile(filename, [options], callback)
3037

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).
38+
`options` (`object`, default `undefined`): Pass in any [`fs.readFile`](https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback) options or set `reviver` for a [JSON reviver](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
3239
- `throws` (`boolean`, default: `true`). If `JSON.parse` throws an error, pass this error to the callback.
3340
If `false`, returns `null` for the object.
3441

@@ -52,9 +59,11 @@ jsonfile.readFile(file)
5259
.catch(error => console.error(error))
5360
```
5461

62+
----
63+
5564
### readFileSync(filename, [options])
5665

57-
`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).
66+
`options` (`object`, default `undefined`): Pass in any [`fs.readFileSync`](https://nodejs.org/api/fs.html#fs_fs_readfilesync_path_options) options or set `reviver` for a [JSON reviver](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
5867
- `throws` (`boolean`, default: `true`). If an error is encountered reading or parsing the file, throw the error. If `false`, returns `null` for the object.
5968

6069
```js
@@ -64,10 +73,11 @@ const file = '/tmp/data.json'
6473
console.dir(jsonfile.readFileSync(file))
6574
```
6675

76+
----
6777

6878
### writeFile(filename, obj, [options], callback)
6979

70-
`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` and override `EOL` string.
80+
`options`: Pass in any [`fs.writeFile`](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback) 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` and override `EOL` string.
7181

7282

7383
```js
@@ -137,9 +147,11 @@ jsonfile.writeFile(file, obj, { flag: 'a' }, function (err) {
137147
})
138148
```
139149

150+
----
151+
140152
### writeFileSync(filename, obj, [options])
141153

142-
`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` and override `EOL` string.
154+
`options`: Pass in any [`fs.writeFileSync`](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options) 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` and override `EOL` string.
143155

144156
```js
145157
const jsonfile = require('jsonfile')

0 commit comments

Comments
 (0)