Files
super_ball/thrower_daemon/node_modules/nostr-tools/lib/esm/nip30.js
2025-09-29 07:21:46 -04:00

33 lines
681 B
JavaScript

// nip30.ts
var EMOJI_SHORTCODE_REGEX = /:(\w+):/;
var regex = () => new RegExp(`\\B${EMOJI_SHORTCODE_REGEX.source}\\B`, "g");
function* matchAll(content) {
const matches = content.matchAll(regex());
for (const match of matches) {
try {
const [shortcode, name] = match;
yield {
shortcode,
name,
start: match.index,
end: match.index + shortcode.length
};
} catch (_e) {
}
}
}
function replaceAll(content, replacer) {
return content.replaceAll(regex(), (shortcode, name) => {
return replacer({
shortcode,
name
});
});
}
export {
EMOJI_SHORTCODE_REGEX,
matchAll,
regex,
replaceAll
};