Last active
August 29, 2015 14:11
-
-
Save paulRbr/62ac5a8c6c728473e4e0 to your computer and use it in GitHub Desktop.
Angular filter to change underscore values (- or _ seperated) to camelcase
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
'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