mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-11-15 22:52:16 +03:00
Improve regex efficiency when trimming long ua string
https://blog.stevenlevithan.com/archives/faster-trim-javascript
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user