mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
refactor(core): use native String.prototype.trim if available
This commit is contained in:
parent
5349b20097
commit
22b9b47576
1 changed files with 14 additions and 3 deletions
|
|
@ -436,9 +436,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
|
||||
|
|
|
|||
Loading…
Reference in a new issue