Created
April 2, 2015 10:31
-
-
Save Kichrum/ea0c3f51390541d06b7a to your computer and use it in GitHub Desktop.
Angular filter to replace camelCase string with Capitalized String
This file contains hidden or 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
(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