jprichardson / node-jsonfile

Easily read/write JSON files.
MIT License
1.2k stars 321 forks source link

readFile & readFileSync can possible have strip-comments as an option? #32

Closed kevbook closed 8 years ago

kevbook commented 9 years ago

Check out https://github.com/sindresorhus/strip-json-comments

jprichardson commented 9 years ago

I would accept a PR to perform a preprocess option. e.g. something like:

function preprocess (text, done) {
  // do something
  var newText = ...
  done(newText)
}

fs.readFile('/some/file.json', { preprocess: preprocess }, callback)

Then if preprocess.length is 2 (it has done) it's async, if it's 1, it's expected to be sync.

onury commented 7 years ago

@jprichardson stripping comments is a fundamental feature for JSON operations. preprocess option does not make too much sense. What would you pre-process a JSON file for? except for stripping out comments. A stripComments:boolean option instead would save devs from installing/using an extra module.

Actually this feature is the only thing missing in the (excellent) fs-extra module.

jprichardson commented 7 years ago

stripping comments is a fundamental feature for JSON operations.

How do you figure? Comments aren't part of the JSON standard.

does not make too much sense. What would you pre-process a JSON file for?

Strip comments? 😛 Change encoding. Do some sort of processing that JSON.parse reviver can't handle.

onury commented 7 years ago

:) I didn't mean it's in the standard. But check how devs need and use it.

z3dtech commented 6 years ago

https://www.npmjs.com/package/jsonfile-commentless