Created
May 11, 2018 05:49
-
-
Save jokemmy/e6952d2aba089605b7a141723530753e to your computer and use it in GitHub Desktop.
驼峰转换
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 驼峰转连词符 | |
const hyphenateRE = /([a-z\d])([A-Z])/g; | |
export function hyphenate( str ) { | |
return str.replace( hyphenateRE, '$1-$2' ).toLowerCase(); | |
} | |
// 连词符转成驼峰 | |
const camelCaseRE = /-(\w)/g; | |
export function camelCase( str ) { | |
return str.replace( camelCaseRE, ( _, b ) => b.toUpperCase()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment