simple-stringify
Simple way stringify json for log.
Installation
$ npm install simple-stringify
API
const stringify = require('simple-stringify');
const data = {
no: 123,
mobile: null,
addresss: undefined,
disabled: false,
name: 'tree.xie',
keywords: [
'koa',
'framework',
'albi',
],
infos: {
url : 'https://github.com/vicanso/albi/issues',
email: 'vicansocanbico@gmail.com'
},
};
stringify.json(data);
divider
The divider for stringify, default is ' '.
const stringify = require('simple-stringify');
stringify.divider = ',';
isSecret
Determine if it is confidential by key. If return true, the value will be ***.
const stringify = require('simple-stringify');
stringify.isSecret = key => key === 'password';
stringify.json({
password: '123456',
});
json
Stringify json data
level
format level, default is stringify.maxLevel
const stringify = require('simple-stringify');
const data = {
no: 123,
mobile: null,
addresss: undefined,
disabled: false,
name: 'tree.xie',
keywords: [
'koa',
'framework',
'albi',
],
infos: {
url : 'https://github.com/vicanso/albi/issues',
email: 'vicansocanbico@gmail.com'
},
};
stringify.json(data);
stringify.json(data, 2);
maxLevel
Set stringify max level, default is 1
const stringify = require('simple-stringify');
stringify.maxLevel = 2;
const data = {
no: 123,
mobile: null,
addresss: undefined,
disabled: false,
name: 'tree.xie',
keywords: [
'koa',
'framework',
'albi',
],
infos: {
url : 'https://github.com/vicanso/albi/issues',
email: 'vicansocanbico@gmail.com'
},
};
stringify.json(data);
Benchmarks
JSON.stringify 1000000 times, use:2438ms
simple-stringify json 1000000 times, use:1684ms
License
MIT