ES6结合正则处理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| export const hyphen = (str) => { let string = str.replace(/([A-Z])/g, '-$1').toLowerCase() if (string.indexOf('-') === 0) string = string.substr(1) return string }
export const hump = str => { return str.replace(/-\w/g, x => { return x.slice(1).toUpperCase() }) }
|
1 2 3 4 5 6 7 8 9 10 11
| export const hyphen = str => { let string = str.replace(/([A-Z])/g, '-$1').toLowerCase() string.indexOf('-') === 0 && string = string.substr(1) return string }
export const hump = str => str.replace(/-\w/g, x => x.slice(1).toUpperCase())
|