Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sorindorobantu/3ea1347ee3af760e33e2a8adea6c578c to your computer and use it in GitHub Desktop.
Save sorindorobantu/3ea1347ee3af760e33e2a8adea6c578c 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