UNPKG

vusion-api

Version:
25 lines (20 loc) 740 B
/** * 该模块在 Node.js 端和浏览器端均可运行 */ /** * 中划线格式 -转-> 驼峰格式 * @param name 原名称 * @return 转换后的名称 */ export const kebab2Camel = (name: string) => name.replace(/(?:^|-)([a-zA-Z0-9])/g, (m, $1) => $1.toUpperCase()); /** * 驼峰格式 -转-> 中划线格式 * @param name 原名称 * @return 转换后的名称 */ export const Camel2kebab = (name: string) => name.replace(/([A-Z]|[0-9]+)/g, (m, $1, offset) => (offset ? '-' : '') + $1.toLowerCase()); export function uniqueInMap(key: string, map: Map<string, any> | Set<string>, start: number = 1) { while (map.has(key)) key = key.replace(/\d*$/, (m) => String(m === '' ? start : +m + 1)); return key; }