writejson

Write stringified object to file

MIT 8 个版本
安装
npm install writejson
yarn add writejson
pnpm add writejson
bun add writejson
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

版本列表
3.0.0 2020-02-27
2.0.1 2018-06-14
2.0.0 2018-06-14
1.1.2 2018-02-09
1.1.1 2015-12-18
1.1.0 2015-12-16
1.0.1 2015-12-15
1.0.0 2015-12-15