Skip to content

Instantly share code, notes, and snippets.

@jokemmy
Created May 11, 2018 05:49
Show Gist options
  • Save jokemmy/e6952d2aba089605b7a141723530753e to your computer and use it in GitHub Desktop.
Save jokemmy/e6952d2aba089605b7a141723530753e to your computer and use it in GitHub Desktop.
驼峰转换
// 驼峰转连词符
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