jprichardson / node-jsonfile

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

allow change JSON like module (ex: JSON5) #102

Closed bluelovers closed 4 years ago

bluelovers commented 6 years ago

allow change JSON like module (ex: JSON5)

jprichardson commented 6 years ago

Hmm, this is an interesting concept worth considering... I like how it'd allow anyone to inject anything they want... however, maybe it should be passed via the method itself to prevent any bugs due to global overwriting.

Thoughts @RyanZim?

RyanZim commented 6 years ago

Yes, should most certainly be passed into the method. I hate global overwriting.

However, that's gonna be painful; I'm honestly thinking perhaps we should transform this to a class-based pattern. The existing API would stay the same, but you could also do:

const jsonfile = new (require('jsonfile').JSONFile)({
  JSON: require('json5'),
  spaces: 4
})
jsonfile.writeFileSync('file', data)
RyanZim commented 4 years ago

Closing since this is a ghost town since 2017.