diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
commit | bbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch) | |
tree | c58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/jsonfile/README.md | |
parent | 003fb34971cf63466184351b4db5f7c67df4f444 (diff) | |
download | wallet-core-bbff7403fbf46f9ad92240ac213df8d30ef31b64.tar.xz |
update packages
Diffstat (limited to 'node_modules/jsonfile/README.md')
-rw-r--r-- | node_modules/jsonfile/README.md | 62 |
1 files changed, 22 insertions, 40 deletions
diff --git a/node_modules/jsonfile/README.md b/node_modules/jsonfile/README.md index 1f214df9b..721685c92 100644 --- a/node_modules/jsonfile/README.md +++ b/node_modules/jsonfile/README.md @@ -57,7 +57,7 @@ console.dir(jsonfile.readFileSync(file)) ### writeFile(filename, obj, [options], callback) -`options`: Pass in any `fs.writeFile` 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`. +`options`: Pass in any `fs.writeFile` 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. ```js @@ -84,6 +84,19 @@ jsonfile.writeFile(file, obj, {spaces: 2}, function(err) { }) ``` +**overriding EOL:** + +```js +var jsonfile = require('jsonfile') + +var file = '/tmp/data.json' +var obj = {name: 'JP'} + +jsonfile.writeFile(file, obj, {spaces: 2, EOL: '\r\n'}, function(err) { + console.error(err) +}) +``` + **appending to an existing JSON file:** You can use `fs.writeFile` option `{flag: 'a'}` to achieve this. @@ -101,7 +114,7 @@ jsonfile.writeFile(file, obj, {flag: 'a'}, function (err) { ### writeFileSync(filename, obj, [options]) -`options`: Pass in any `fs.writeFileSync` 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`. +`options`: Pass in any `fs.writeFileSync` 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. ```js var jsonfile = require('jsonfile') @@ -123,61 +136,30 @@ var obj = {name: 'JP'} jsonfile.writeFileSync(file, obj, {spaces: 2}) ``` -**appending to an existing JSON file:** - -You can use `fs.writeFileSync` option `{flag: 'a'}` to achieve this. +**overriding EOL:** ```js var jsonfile = require('jsonfile') -var file = '/tmp/mayAlreadyExistedData.json' +var file = '/tmp/data.json' var obj = {name: 'JP'} -jsonfile.writeFileSync(file, obj, {flag: 'a'}) +jsonfile.writeFileSync(file, obj, {spaces: 2, EOL: '\r\n'}) ``` -### spaces - -Global configuration to set spaces to indent JSON files. +**appending to an existing JSON file:** -**default:** `null` +You can use `fs.writeFileSync` option `{flag: 'a'}` to achieve this. ```js var jsonfile = require('jsonfile') -jsonfile.spaces = 4 - -var file = '/tmp/data.json' +var file = '/tmp/mayAlreadyExistedData.json' var obj = {name: 'JP'} -// json file has four space indenting now -jsonfile.writeFile(file, obj, function (err) { - console.error(err) -}) -``` - -Note, it's bound to `this.spaces`. So, if you do this: - -```js -var myObj = {} -myObj.writeJsonSync = jsonfile.writeFileSync -// => this.spaces = null -``` - -Could do the following: - -```js -var jsonfile = require('jsonfile') -jsonfile.spaces = 4 -jsonfile.writeFileSync(file, obj) // will have 4 spaces indentation - -var myCrazyObj = {spaces: 32} -myCrazyObj.writeJsonSync = jsonfile.writeFileSync -myCrazyObj.writeJsonSync(file, obj) // will have 32 space indentation -myCrazyObj.writeJsonSync(file, obj, {spaces: 2}) // will have only 2 +jsonfile.writeFileSync(file, obj, {flag: 'a'}) ``` - License ------- |