Skip to content

Instantly share code, notes, and snippets.

@LeeeeeeM
Created November 21, 2018 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeeeeeeM/0ca683475610258924d87dba24e9c6dd to your computer and use it in GitHub Desktop.
Save LeeeeeeM/0ca683475610258924d87dba24e9c6dd to your computer and use it in GitHub Desktop.
data-set正则测试表达
function $dataAttr (nameWithData) {
const originAttr = nameWithData.replace(/[A-Z]/g, $0 => '-' + $0.toLowerCase())
return originAttr.replace(/^data-/, '').replace(/-([a-z])/g, ($0, $1) => $1.toUpperCase())
}
// nameWithData ----> dataSetName
// originAttr ----> data-set-name
// return ----> setName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment