UNPKG

761 BPlain TextView Raw
1import Adjust, { AdjustConstructor } from './adjusts/adjust';
2
3interface AdjustMapType {
4 [type: string]: AdjustConstructor;
5}
6
7const ADJUST_MAP: AdjustMapType = {};
8
9/**
10 * 根据类型获取 Adjust 类
11 * @param type
12 */
13const getAdjust = (type: string): AdjustConstructor => {
14 return ADJUST_MAP[type.toLowerCase()];
15};
16
17/**
18 * 注册自定义 Adjust
19 * @param type
20 * @param ctor
21 */
22const registerAdjust = (type: string, ctor: AdjustConstructor): void => {
23 // 注册的时候,需要校验 type 重名,不区分大小写
24 if (getAdjust(type)) {
25 throw new Error(`Adjust type '${type}' existed.`);
26 }
27 // 存储到 map 中
28 ADJUST_MAP[type.toLowerCase()] = ctor;
29};
30
31export { getAdjust, registerAdjust, Adjust };
32
33export * from './interface';