From 1f1455d1f02903120a951dd95fd0d415075c7f5a Mon Sep 17 00:00:00 2001 From: Shlee Date: Thu, 11 Jun 2026 00:48:31 +0930 Subject: [PATCH] Minor refactor foldToASCII in streaming/utils.js (#39355) --- streaming/utils.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/streaming/utils.js b/streaming/utils.js index dd5e82c67c..30b7c2edae 100644 --- a/streaming/utils.js +++ b/streaming/utils.js @@ -30,15 +30,13 @@ export function isTruthy(value) { */ const NON_ASCII_CHARS = 'ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž'; const EQUIVALENT_ASCII_CHARS = 'AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz'; - +const FOLDTOASCII_REGEX = new RegExp(NON_ASCII_CHARS.split('').join('|'), 'g'); /** * @param {string} str * @returns {string} */ export function foldToASCII(str) { - const regex = new RegExp(NON_ASCII_CHARS.split('').join('|'), 'g'); - - return str.replace(regex, function(match) { + return str.replace(FOLDTOASCII_REGEX, function(match) { const index = NON_ASCII_CHARS.indexOf(match); return EQUIVALENT_ASCII_CHARS[index]; });