util: Fix inefficient RegExp construction.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-09-26 12:33:07 -07:00 committed by Tim Abbott
parent 6b92e71453
commit 83f696d217
1 changed files with 3 additions and 2 deletions

View File

@ -215,8 +215,9 @@ export const move_array_elements_to_front = function util_move_array_elements_to
// check by the userAgent string if a user's client is likely mobile. // check by the userAgent string if a user's client is likely mobile.
export function is_mobile(): boolean { export function is_mobile(): boolean {
const regex = "Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini"; return /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(
return new RegExp(regex, "i").test(window.navigator.userAgent); window.navigator.userAgent,
);
} }
export function sorted_ids(ids: number[]): number[] { export function sorted_ids(ids: number[]): number[] {