writejson
Write stringified object to file
Last updated 10 years ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install writejson 
SYNC missed versions from official npm registry.

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

Current Tags

  • 3.0.0                                ...           latest (6 years ago)

8 Versions

  • 3.0.0                                ...           6 years ago
  • 2.0.1                                ...           8 years ago
  • 2.0.0                                ...           8 years ago
  • 1.1.2                                ...           8 years ago
  • 1.1.1                                ...           10 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (1)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |