1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2024-12-23 23:47:57 +01:00
Whalebird-desktop-client-ma.../renderer/utils/emojify.ts
2023-11-03 20:37:40 +09:00

22 lines
690 B
TypeScript

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