humpToUnderline
This commit is contained in:
14
src/js/humpToUnderline.ts
Normal file
14
src/js/humpToUnderline.ts
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* 驼峰命名改为下划线命名,数字不重新起一个下划线
|
||||
* @param str 需转换的字符串
|
||||
* @returns 转换的结果
|
||||
*/
|
||||
export const humpToUnderline = (str: string) => {
|
||||
let temp = str.replace(/[A-Z]/g, (match) => {
|
||||
return `_${match.toLowerCase()}`;
|
||||
});
|
||||
if (temp.slice(0, 1) === "_") {
|
||||
temp = temp.slice(1);
|
||||
}
|
||||
return temp;
|
||||
};
|
Reference in New Issue
Block a user