Created
December 16, 2016 14:52
-
-
Save omarkdev/b88401d1984c647eba0cd767b4b127de to your computer and use it in GitHub Desktop.
VueJS filter camel case
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
/** | |
* Converts a string to camel case. | |
* Example: fucking_string => fuckingString | |
* | |
* @param {String} str the string to convert | |
* @return {String} | |
*/ | |
Vue.filter('camelCase', function (str) { | |
return str.toLowerCase() | |
.replace( /[-_]+/g, ' ') | |
.replace( /[^\w\s]/g, '') | |
.replace( / (.)/g, function($1) { return $1.toUpperCase(); }) | |
.replace( / /g, '' ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment