Skip to content

Instantly share code, notes, and snippets.

@omarkdev
Created December 16, 2016 14:52
Show Gist options
  • Save omarkdev/b88401d1984c647eba0cd767b4b127de to your computer and use it in GitHub Desktop.
Save omarkdev/b88401d1984c647eba0cd767b4b127de to your computer and use it in GitHub Desktop.
VueJS filter camel case
/**
* 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