-
Notifications
You must be signed in to change notification settings - Fork 360
Expand file tree
/
Copy pathlibs.ts
More file actions
30 lines (24 loc) · 796 Bytes
/
libs.ts
File metadata and controls
30 lines (24 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import {
CHAT_COMPONENT_MAP,
MOBILE_COMPONENT_MAP,
NON_PASCAL_CASE_NAMES,
WEB_COMPONENT_MAP,
} from '../../../js/common/components';
import type { Platform } from './types';
export const convert2PascalCase = (name: string) =>
name
.split('-')
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
.join('');
export const COMPONENT_MAPS = {
web: WEB_COMPONENT_MAP,
mobile: MOBILE_COMPONENT_MAP,
chat: CHAT_COMPONENT_MAP,
};
export const mapToParentName = (name: string, platform: Platform) => {
const targetMap = COMPONENT_MAPS[platform];
const found = Object.entries(targetMap).find(([_, values]) => values.includes(name));
// 返回父组件名
if (found) return NON_PASCAL_CASE_NAMES[found[0]] || convert2PascalCase(found[0]);
return null;
};