writejson

2018-10-23 admin

writejson是什么

什么是writejson,Write stringified object to file

writejson使用教程帮助文档

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');
writejson('data.json', {hello: 'world'}, (error) => {
    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
};
writejson('data.json', {hello: 'world'}, options, (error) => {
    if (error)
        console.error(error.message);
});

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

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-43456.html

文章标题:writejson

回到顶部