Skip to content

Instantly share code, notes, and snippets.

@yeyuguo
Created December 16, 2020 08:29
Show Gist options
  • Save yeyuguo/440f78268a4b80f01348174ac2c95d4e to your computer and use it in GitHub Desktop.
Save yeyuguo/440f78268a4b80f01348174ac2c95d4e to your computer and use it in GitHub Desktop.
驼峰命名转成 xx-xx 命名【kebabCase】
function kebabCase(str) {
const hyphenateRE = /([^-])([A-Z])/g;
return str
.replace(hyphenateRE, '$1-$2')
.replace(hyphenateRE, '$1-$2')
.toLowerCase();
}
@yeyuguo
Copy link
Author

yeyuguo commented Dec 16, 2020

kebabCase('testABCName') // "test-a-b-c-name"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment