Improve regex efficiency when trimming long ua string

https://blog.stevenlevithan.com/archives/faster-trim-javascript
This commit is contained in:
Faisal Salman 2021-09-17 23:24:42 +07:00
parent 20a428c351
commit 336ce2b950

View File

@ -91,7 +91,7 @@
},
trim = function (str, len) {
if (typeof(str) === STR_TYPE) {
str = str.replace(/^\s+|\s+$/g, EMPTY);
str = str.replace(/^\s\s*/, EMPTY).replace(/\s\s*$/, EMPTY);
return typeof(len) === UNDEF_TYPE ? str : str.substring(0, UA_MAX_LENGTH);
}
};