feature: vor und nachteile

This commit is contained in:
Hikyu
2026-05-31 13:54:31 +02:00
parent 552a947a1c
commit e3dad17446
23270 changed files with 3024794 additions and 200 deletions
+26
View File
@@ -0,0 +1,26 @@
import { getEmojiMatchesInText, sortEmojiMatchesInText } from "./find.js";
/**
* Find and replace emojis in text
*
* Returns null if nothing was replaced
*/
function findAndReplaceEmojisInText(regexp, content, callback) {
const matches = getEmojiMatchesInText(regexp, content);
if (!matches.length) return null;
const sortedMatches = sortEmojiMatchesInText(content, matches);
let result = "";
let replaced = false;
for (let i = 0; i < sortedMatches.length; i++) {
const item = sortedMatches[i];
result += item.prev;
const replacement = callback({ ...item.match }, result);
if (replacement === void 0) result += item.match.match;
else {
result += replacement;
replaced = true;
}
}
result += sortedMatches[sortedMatches.length - 1].next;
return replaced ? result : null;
}
export { findAndReplaceEmojisInText };