Socket
Socket
Sign inDemoInstall

jsonfile

Package Overview
Dependencies
2
Maintainers
2
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.0.1 to 6.1.0

6

CHANGELOG.md

@@ -0,1 +1,7 @@

6.1.0 / 2020-10-31
------------------
- Add `finalEOL` option to disable writing final EOL ([#115](https://github.com/jprichardson/node-jsonfile/issues/115), [#137](https://github.com/jprichardson/node-jsonfile/pull/137))
- Update dependency ([#138](https://github.com/jprichardson/node-jsonfile/pull/138))
6.0.1 / 2020-03-07

@@ -2,0 +8,0 @@ ------------------

8

package.json
{
"name": "jsonfile",
"version": "6.0.1",
"version": "6.1.0",
"description": "Easily read/write JSON files.",

@@ -20,3 +20,3 @@ "repository": {

"dependencies": {
"universalify": "^1.0.0"
"universalify": "^2.0.0"
},

@@ -27,5 +27,5 @@ "optionalDependencies": {

"devDependencies": {
"mocha": "^5.2.0",
"mocha": "^8.2.0",
"rimraf": "^2.4.0",
"standard": "^12.0.1"
"standard": "^16.0.1"
},

@@ -32,0 +32,0 @@ "main": "index.js",

@@ -80,3 +80,3 @@ Node.js - jsonfile

`options`: Pass in any [`fs.writeFile`](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback) options or set `replacer` for a [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). Can also pass in `spaces` and override `EOL` string.
`options`: Pass in any [`fs.writeFile`](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback) options or set `replacer` for a [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). Can also pass in `spaces`, or override `EOL` string or set `finalEOL` flag as `false` to not save the file with `EOL` at the end.

@@ -136,2 +136,16 @@

**disabling the EOL at the end of file:**
```js
const jsonfile = require('jsonfile')
const file = '/tmp/data.json'
const obj = { name: 'JP' }
jsonfile.writeFile(file, obj, { spaces: 2, finalEOL: false }, function (err) {
if (err) console.log(err)
})
```
**appending to an existing JSON file:**

@@ -156,3 +170,3 @@

`options`: Pass in any [`fs.writeFileSync`](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options) options or set `replacer` for a [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). Can also pass in `spaces` and override `EOL` string.
`options`: Pass in any [`fs.writeFileSync`](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options) options or set `replacer` for a [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). Can also pass in `spaces`, or override `EOL` string or set `finalEOL` flag as `false` to not save the file with `EOL` at the end.

@@ -190,2 +204,13 @@ ```js

**disabling the EOL at the end of file:**
```js
const jsonfile = require('jsonfile')
const file = '/tmp/data.json'
const obj = { name: 'JP' }
jsonfile.writeFileSync(file, obj, { spaces: 2, finalEOL: false })
```
**appending to an existing JSON file:**

@@ -192,0 +217,0 @@

@@ -1,7 +0,6 @@

function stringify (obj, options = {}) {
const EOL = options.EOL || '\n'
function stringify (obj, { EOL = '\n', finalEOL = true, replacer = null, spaces } = {}) {
const EOF = finalEOL ? EOL : ''
const str = JSON.stringify(obj, replacer, spaces)
const str = JSON.stringify(obj, options ? options.replacer : null, options.spaces)
return str.replace(/\n/g, EOL) + EOL
return str.replace(/\n/g, EOL) + EOF
}

@@ -8,0 +7,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc