typescript-util
Version:
JS/TS 的简单工具
51 lines • 1.39 kB
JavaScript
;
// noinspection JSUnusedGlobalSymbols
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConstantValueMapping = void 0;
const ObjectTool_1 = require("../tool/ObjectTool");
/**
* 常量值映射
*/
class ConstantValueMapping {
/**
* 原常量值, 保留
*/
constant;
/**
* 选项数组数据
*/
dicArr;
/**
* 展示用数据
* @see toDisplay
*/
display;
/**
*/
constructor(constantValue = {}) {
this.constant = constantValue;
this.dicArr = ObjectTool_1.ObjectTool.toArray(constantValue)
.map(({ key, value }) => ({ label: key, value }));
this.display = ObjectTool_1.ObjectTool.keyValueReverse(constantValue);
}
/**
* {@link #display} 的替代品, 设置默认值
*/
toDisplay(value, defaultValue = '') {
return this.display[value] ?? defaultValue;
}
/**
* 选项数组, 排除指定的值
*/
optionArrayExclude(...excludeValue) {
return this.dicArr.filter(i => !excludeValue.includes(i.value));
}
/**
* 选项数组 仅包含指定的值
*/
optionArrayInclude(...includeValue) {
return this.dicArr.filter(i => includeValue.includes(i.value));
}
}
exports.ConstantValueMapping = ConstantValueMapping;
//# sourceMappingURL=ConstantValueMapping.js.map