You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
640 B
24 lines
640 B
7 months ago
|
export const stringUtil = {
|
||
|
// 首写字母大写
|
||
|
firstToUpper: (str: String) => {
|
||
|
return str.trim().replace(str[0], str[0].toUpperCase());
|
||
|
},
|
||
|
// 首写字母小写
|
||
|
firstToLower: (str: String) => {
|
||
|
return str.trim().replace(str[0], str[0].toLowerCase());
|
||
|
},
|
||
|
|
||
|
// 下划线转换驼峰
|
||
|
toHump: (str: string) => {
|
||
|
return str.replace(/\_(\w)/g, function (all, letter) {
|
||
|
return letter.toUpperCase();
|
||
|
});
|
||
|
},
|
||
|
|
||
|
// 驼峰转换下划线
|
||
|
toLine: (str: string) => {
|
||
|
let newStr = str.replace(/([A-Z])/g, '_$1').toLowerCase();
|
||
|
return newStr.startsWith('_') ? newStr.replace('_', '') : newStr;
|
||
|
},
|
||
|
};
|