mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'staging' into smol-tag-improvements
This commit is contained in:
@ -495,14 +495,16 @@ export function trimToEndSentence(input, include_newline = false) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const isEmoji = x => /(\p{Emoji_Presentation}|\p{Extended_Pictographic})/gu.test(x);
|
||||
const punctuation = new Set(['.', '!', '?', '*', '"', ')', '}', '`', ']', '$', '。', '!', '?', '”', ')', '】', '’', '」', '_']); // extend this as you see fit
|
||||
let last = -1;
|
||||
|
||||
for (let i = input.length - 1; i >= 0; i--) {
|
||||
const char = input[i];
|
||||
const characters = Array.from(input);
|
||||
for (let i = characters.length - 1; i >= 0; i--) {
|
||||
const char = characters[i];
|
||||
|
||||
if (punctuation.has(char)) {
|
||||
if (i > 0 && /[\s\n]/.test(input[i - 1])) {
|
||||
if (punctuation.has(char) || isEmoji(char)) {
|
||||
if (i > 0 && /[\s\n]/.test(characters[i - 1])) {
|
||||
last = i - 1;
|
||||
} else {
|
||||
last = i;
|
||||
@ -520,7 +522,7 @@ export function trimToEndSentence(input, include_newline = false) {
|
||||
return input.trimEnd();
|
||||
}
|
||||
|
||||
return input.substring(0, last + 1).trimEnd();
|
||||
return characters.slice(0, last + 1).join('').trimEnd();
|
||||
}
|
||||
|
||||
export function trimToStartSentence(input) {
|
||||
@ -1275,6 +1277,9 @@ export async function waitUntilCondition(condition, timeout = 1000, interval = 1
|
||||
* uuidv4(); // '3e2fd9e1-0a7a-4f6d-9aaf-8a7a4babe7eb'
|
||||
*/
|
||||
export function uuidv4() {
|
||||
if ('randomUUID' in crypto) {
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||
const r = Math.random() * 16 | 0;
|
||||
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
|
Reference in New Issue
Block a user