Add option to use twemojis instead of emojis (#121)
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
import puppeteer from "puppeteer"
|
||||
import imgb64 from "image-to-base64"
|
||||
import git from "simple-git"
|
||||
import twemojis from "twemoji-parser"
|
||||
|
||||
export {fs, os, paths, url, util, processes, axios, puppeteer, imgb64, git}
|
||||
|
||||
@@ -168,6 +169,20 @@
|
||||
return {resized, mime}
|
||||
}
|
||||
|
||||
/**Render twemojis */
|
||||
export async function svgemojis(svg) {
|
||||
//Load emojis
|
||||
const emojis = new Map()
|
||||
for (const {text:emoji, url} of twemojis.parse(svg)) {
|
||||
if (!emojis.has(emoji))
|
||||
emojis.set(emoji, (await axios.get(url)).data.replace(/^<svg /, '<svg class="twemoji" '))
|
||||
}
|
||||
//Apply replacements
|
||||
for (const [emoji, twemoji] of emojis)
|
||||
svg = svg.replace(new RegExp(emoji, "g"), twemoji)
|
||||
return svg
|
||||
}
|
||||
|
||||
/**Wait */
|
||||
export async function wait(seconds) {
|
||||
await new Promise(solve => setTimeout(solve, seconds*1000)) //eslint-disable-line no-promise-executor-return
|
||||
|
||||
Reference in New Issue
Block a user