28 lines
623 B
TypeScript
28 lines
623 B
TypeScript
export function cpm(...classes: (string[] | string)[]) {
|
||
const map = new Map<string, string>();
|
||
|
||
function dealClass(cls: string) {
|
||
// 提取前缀和后缀
|
||
const prifix = cls.split("--")[0];
|
||
|
||
// 使用set覆盖(自动新建),而不是push
|
||
map.set(prifix, cls);
|
||
}
|
||
|
||
classes.forEach((item) => {
|
||
// 如果是 string 直接处理
|
||
if (typeof item === "string") {
|
||
dealClass(item);
|
||
} else {
|
||
// 否则肯定是 string[]
|
||
item.forEach((i) => {
|
||
dealClass(i);
|
||
});
|
||
}
|
||
});
|
||
|
||
const resultString = Array.from(map.values()).join(" ");
|
||
|
||
return resultString;
|
||
}
|