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

Add updateFile and updateFileSync methods #18

Closed
piranna opened this issue Dec 9, 2014 · 2 comments
Closed

Add updateFile and updateFileSync methods #18

piranna opened this issue Dec 9, 2014 · 2 comments

Comments

@piranna
Copy link

piranna commented Dec 9, 2014

Instead of needing to call readFile, modify the Json, and later call writeFile, add an updateFile method that accept a literal object and use it's attributes and hierarchy to update the content of the Json file. To remove entries, they can be set to undefined, so JSON.stringify() will ignore them later.

@jprichardson
Copy link
Owner

This is way out of scope for this library.

Ultimately, in a updateFile() method, you'd still need to call fs.writeFile(). There are so many json/object diff libraries out there, that you could easily create your own updateFile() and updateFileSync() methods in conjunction with this library.

@piranna
Copy link
Author

piranna commented Dec 9, 2014

I'm not sure if it doesn't falls in the scope of the library (I think it does). In any case, I've crafted my own updateFile function by using the merge:

function updateFile(file, obj, callback)
{
  jsonfile.readFile(file, function(error, orig)
  {
    if(error) return callback(error)

    jsonfile.writeFile(file, recursive(orig, obj), callback)
  })
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants