refactor(core): use native String.prototype.trim if available
This commit is contained in:
committed by
Brian Ford
parent
751c77f87b
commit
7b7be341b6
+14
-3
@@ -442,9 +442,20 @@ function isBoolean(value) {
|
||||
}
|
||||
|
||||
|
||||
function trim(value) {
|
||||
return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value;
|
||||
}
|
||||
var trim = (function() {
|
||||
// native trim is way faster: http://jsperf.com/angular-trim-test
|
||||
// but IE doesn't have it... :-(
|
||||
// TODO: we should move this into IE/ES5 polyfill
|
||||
if (!String.prototype.trim) {
|
||||
return function(value) {
|
||||
return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value;
|
||||
};
|
||||
}
|
||||
return function(value) {
|
||||
return isString(value) ? value.trim() : value;
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
|
||||
Reference in New Issue
Block a user