jprichardson / node-jsonfile

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

Is there any reason for adding a final EOL #135

Closed sinikami closed 4 years ago

sinikami commented 4 years ago
function stringify (obj, options = {}) {
  const EOL = options.EOL || '\n'

  const str = JSON.stringify(obj, options ? options.replacer : null, options.spaces)

  return str.replace(/\n/g, EOL) + EOL
}

Add a new EOL makes it different with origin source.

I saved hash in JSON.stringify(...), but it is different with hashing from file because of a final EOL was added.

RyanZim commented 4 years ago

Ending files with a newline is a strong Unix/git convention, and I don't think we should deviate from it.