Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
refactor(core): use native String.prototype.trim if available
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Müller authored and IgorMinar committed Jul 3, 2013
1 parent 5349b20 commit 22b9b47
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 22b9b47

Please sign in to comment.