js常用工具函数之连字符-与驼峰转换方法
- 1. 连字符-转驼峰
- 2. 驼峰转连字符-
查看vue2源码:
srcsharedutil.js
1. 连字符-转驼峰
const camelizeRE = /-(w)/g
export const camelize = (str: string): string => {
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
}
2. 驼峰转连字符-
const hyphenateRE = /B([A-Z])/g
export const hyphenate = (str: string): string => {
return str.replace(hyphenateRE, '-$1').toLowerCase()
}
最后
以上就是典雅高跟鞋最近收集整理的关于js常用工具函数之连字符-与驼峰转换方法的全部内容,更多相关js常用工具函数之连字符-与驼峰转换方法内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复