Forráskód Böngészése

utils: simplify trimTopic

Also avoid using Array.prototype.at, which does not seem to exist
in the Wexin builtin webview (Android Wexin 8.0.30).
Jun Wu 1 éve
szülő
commit
327ac765df
1 módosított fájl, 1 hozzáadás és 9 törlés
  1. 1 9
      app/utils.ts

+ 1 - 9
app/utils.ts

@@ -2,15 +2,7 @@ import { showToast } from "./components/ui-lib";
 import Locale from "./locales";
 
 export function trimTopic(topic: string) {
-  const s = topic.split("");
-  let lastChar = s.at(-1); // 获取 s 的最后一个字符
-  let pattern = /[,。!?、,.!?]/; // 定义匹配中文和英文标点符号的正则表达式
-  while (lastChar && pattern.test(lastChar!)) {
-    s.pop();
-    lastChar = s.at(-1);
-  }
-
-  return s.join("");
+  return topic.replace(/[,。!?、,.!?]*$/, "");
 }
 
 export function copyToClipboard(text: string) {