utils.ts 349 B

1234567891011
  1. export function trimTopic(topic: string) {
  2. const s = topic.split("").slice(0, 20);
  3. let lastChar = s.at(-1); // 获取 s 的最后一个字符
  4. let pattern = /[,。!?、]/; // 定义匹配中文标点符号的正则表达式
  5. while (lastChar && pattern.test(lastChar!)) {
  6. s.pop();
  7. lastChar = s.at(-1);
  8. }
  9. return s.join("");
  10. }