mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 16:08:47 +03:00
Improve regex efficiency when trimming long ua string
https://blog.stevenlevithan.com/archives/faster-trim-javascript
This commit is contained in:
parent
20a428c351
commit
336ce2b950
@ -91,7 +91,7 @@
|
|||||||
},
|
},
|
||||||
trim = function (str, len) {
|
trim = function (str, len) {
|
||||||
if (typeof(str) === STR_TYPE) {
|
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);
|
return typeof(len) === UNDEF_TYPE ? str : str.substring(0, UA_MAX_LENGTH);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user