Skip to content

Instantly share code, notes, and snippets.

@paulRbr
Last active August 29, 2015 14:11
Show Gist options
  • Save paulRbr/62ac5a8c6c728473e4e0 to your computer and use it in GitHub Desktop.
Save paulRbr/62ac5a8c6c728473e4e0 to your computer and use it in GitHub Desktop.
Angular filter to change underscore values (- or _ seperated) to camelcase
'use strict';
angular.module('app')
.filter('u2camel', function($scope){
return function(msg) {
if (!angular.isString(msg)) {
return '';
} else {
msg = msg.replace(/(\_[a-z])/g, function($1){return $1.toUpperCase().replace('_','');});
msg = msg.replace(/(\-[a-z])/g, function($1){return $1.toUpperCase().replace('-','');});
return msg;
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment