Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding promise support using universalify #109

Merged
merged 7 commits into from
Sep 8, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ jsonfile.readFile(file, function(err, obj) {
console.dir(obj)
})
```
### readFile(filename, [options]) : Promise
kartik2406 marked this conversation as resolved.
Show resolved Hide resolved
A promisified version of readFile.

```js
var jsonfile = require('jsonfile')
var file = '/tmp/data.json'
jsonfile.readFile(file)
.then(obj => console.dir(obj)))
.catch(error => console.log(error));
```

### readFileSync(filename, [options])

Expand Down Expand Up @@ -71,6 +80,25 @@ jsonfile.writeFile(file, obj, function (err) {
})
```


### writeFile(filename, obj, [options]) : Promise

A promisified version of readFile.

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

var file = '/tmp/data.json'
var obj = {name: 'JP'}

jsonfile.writeFile(file, obj)
.then(res => {
console.log("Write complete");
})
.catch(error => console.log(error));
```


**formatting with spaces:**

```js
Expand Down