Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

writejson

coderaiser9.7kMIT3.0.0

Write stringified object to file

read, parse, json

readme

writejson License NPM version Dependency Status Build Status Coverage Status

Write stringified object to file.

Install

npm i writejson --save

How to use?

To handle formating optional argument options could be used according to JSON.stringify.

API

writejson(name, object[, options], callback)

Asynchonouse write stringified object.

const writejson = require('writejson');

const [error] = await tryToCatch(writejson, 'data.json', {hello: 'world'});

if (error)
    console.error(error.message);

const options = {
    replacer: ['hello'],    // properties to put in json
    space: 4,               // default space count
    eof: true,              // default new line at end of file
    encoding: 'utf8',       // default
    mode: '0o666',          // default
    flag: 'w',              // default
};

await writejson('data.json', {hello: 'world'}, options);

writejson.sync(name, object[, options])

Synchonouse write stringified object.

try {
    writejson.sync('data.json', {hello: 'world'});
} catch(error) {
    console.log(error.message);
}

writejson.sync.try(name, object[, options])

Synchonouse try to write stringified object.

writejson.sync.try('data.json', {hello: 'world'});

License

MIT

changelog

2020.02.27, v3.0.0

feature:

  • (package) eslint v6.8.0
  • (package) nyc v15.0.0
  • (package) try-to-catch v3.0.0
  • (writejson) callback -> promise
  • (package) try-catch v3.0.0
  • (package) redrun v7.0.0

2018.06.14, v2.0.1

feature:

  • (npmignore) add .*

2018.06.14, v2.0.0

feature:

  • (writejson) add support of writeFile options
  • (writejson) es2015-ify
  • (package) nyc v12.0.2
  • (package) redrun v6.0.0

2018.02.09, v1.1.2

feature:

  • (package) try-catch v2.0.0
  • (package) coveralls v3.0.0
  • (package) nyc v11.0.2
  • (package) nyc v10.0.0
  • (package) nyc v9.0.1
  • (package) nyc v8.1.0
  • (package) redrun v5.0.0
  • (package) nyc v7.0.0
  • (package) redrun v4.0.0
  • (package) npm-run-all -> redrun
  • (package) add jscs v3.0.3
  • (package) nyc v6.1.1
  • (writejson) add coveralls

2015.12.18, v1.1.1

feature:

  • (writejson) rm extra tryCatch
  • (package) add coverage

2015.12.16, v1.1.0

feature:

  • (writejson) add options

2015.12.15, v1.0.1

feature:

  • (writejson) add jshint, jscs