Created
November 21, 2018 09:38
-
-
Save LeeeeeeM/0ca683475610258924d87dba24e9c6dd to your computer and use it in GitHub Desktop.
data-set正则测试表达
This file contains 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
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