humpToUnderline

This commit is contained in:
mol
2024-06-17 13:38:24 +08:00
parent 5d17f3f4b9
commit 534fc73a00

14
src/js/humpToUnderline.ts Normal file
View 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;
};