condition-json
v0.0.7
Published
[![Build Status](https://www.travis-ci.org/YuChenLi923/condition-json.svg?branch=master)](https://www.travis-ci.org/YuChenLi923/condition-json) [![Coverage Status](https://coveralls.io/repos/github/YuChenLi923/condition-json/badge.svg?branch=master)](http
Downloads
10
Maintainers
Readme
condition-json
拓展json功能,使其key支持条件表达式,condition-json会根据条件,生成对应的json格式。
安装
npm i condition-json --save
用法
const cjson = require('condition-json');
const json = {
name: 'yuchen',
'{showAge}': {
age: 22
},
'{showBook}:book': {
name: 'book1'
},
date: function({date}) {
return 'date:' + date;
}
};
cjson(json, {
showAge: true,
showBook: true,
date: '2019-7'
}).then((result) => {
console.log(result);
});
result被转换为:
{
name: 'yuchen',
age: 22,
book: {
name: 'book1'
},
date: '2019-7'
}
API
cjson(json[,scope])
- json <Object>|<JSON>
- scope <Object>