Skip to content

Instantly share code, notes, and snippets.

@Kichrum
Created April 2, 2015 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kichrum/ea0c3f51390541d06b7a to your computer and use it in GitHub Desktop.
Save Kichrum/ea0c3f51390541d06b7a to your computer and use it in GitHub Desktop.
Angular filter to replace camelCase string with Capitalized String
(function(angular) {
// 'camelCaseName' | camelCaseToCapitalized => 'Camel Case Name'
var camelCaseToCapitalizedFilter = function() {
return function(string) {
return string
.replace(/([A-Z])/g, ' $1')
.replace(/^./, function(str) {
return str.toUpperCase();
});
};
};
angular.module('camelCaseToCapitalizedFilter', [])
.filter('camelCaseToCapitalized', camelCaseToCapitalizedFilter);
})(angular);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment