1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2024-12-27 01:05:21 +01:00
Whalebird-desktop-client-ma.../renderer/utils/emojify.ts

22 lines
690 B
TypeScript
Raw Normal View History

2023-11-03 12:37:40 +01:00
import { Entity } from 'megalodon'
const emojify = (str: string | any, customEmoji: Array<Entity.Emoji> = []): string | null => {
if (typeof str !== 'string') {
const message = `Provided string is not a string: ${str}`
console.error(message)
return null
}
let result = str
customEmoji.map(emoji => {
const reg = new RegExp(`:${emoji.shortcode}:`, 'g')
const match = result.match(reg)
if (!match) return emoji
const replaceTag = `<img draggable="false" class="emojione" alt="${emoji.shortcode}" title="${emoji.shortcode}" src="${emoji.url}" />`
result = result.replace(reg, replaceTag)
return emoji
})
return result
}
export default emojify