添加更统一的字典配置方法
特性
- 统一配置字典
未来可能的特性
- 支持指定输入输出选项
步骤说明
- 配置公司私有镜像
- 安装
- 参考使用环境说明
配置公司私有镜像
npm set registry http://192.168.1.79:4873
or
yarn config set registry http://192.168.1.79:4873
安装
npm i myfams-mapstatus-module
or
yarn add myfams-mapstatus-module
webpack 环境下、vuejs单文件组件下使用
import mapStatusFactory from 'myfams-mapstatus-module';
// 后端的数据模型
const backend = [{
"status": 1, // 可能的 0/1/2, 0需要转换为准备,1需要转换为进行,2需要转换为结束
"name": "张三"
},
{
"status": 2, // 可能的 0/1/2, 0需要转换为准备,1需要转换为进行,2需要转换为结束
"name": "李四"
}]
const config = {
statusMap: { // 配置对象必须是 字段名 + Map
0: '准备',
1: '进行',
2: '结束'
}
}
const mapStatus = mapStatusFactory(config)
backend.forEach(o => {
o.status = mapStatus(o)
})
console.log(backend)
// 输出
// [{
// "status": "进行",
// "name": "张三"
// },
// {
// "status": "结束",
// "name": "李四"
// }]
nodejs环境下使用
const mapStatusFactory = require('myfams-mapstatus-module');
// 后端的数据模型
const backend = [{
"status": 1, // 可能的 0/1/2, 0需要转换为准备,1需要转换为进行,2需要转换为结束
"name": "张三"
},
{
"status": 2, // 可能的 0/1/2, 0需要转换为准备,1需要转换为进行,2需要转换为结束
"name": "李四"
}]
const config = {
statusMap: { // 配置对象必须是 字段名 + Map
0: '准备',
1: '进行',
2: '结束'
}
}
const mapStatus = mapStatusFactory(config)
backend.forEach(o => {
o.status = mapStatus(o)
})
console.log(backend)
// 输出
// [{
// "status": "进行",
// "name": "张三"
// },
// {
// "status": "结束",
// "name": "李四"
// }]