typescript-util
Version:
JS/TS 的简单工具
47 lines • 1.2 kB
JavaScript
// noinspection JSUnusedGlobalSymbols
import { ObjectTool } from '../tool/ObjectTool';
/**
* 常量值映射
*/
export class ConstantValueMapping {
/**
* 原常量值, 保留
*/
constant;
/**
* 选项数组数据
*/
dicArr;
/**
* 展示用数据
* @see toDisplay
*/
display;
/**
*/
constructor(constantValue = {}) {
this.constant = constantValue;
this.dicArr = ObjectTool.toArray(constantValue)
.map(({ key, value }) => ({ label: key, value }));
this.display = 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));
}
}
//# sourceMappingURL=ConstantValueMapping.js.map