import EmojiConvertor from 'emoji-js-clean' ; import { getLogger } from '../../../shared/logger' ; import emojiRegexRGI from 'emoji-regex/RGI_Emoji' ; const log = getLogger ( 'renderer/emoji' ) ; const instance = new EmojiConvertor ( ) ; instance . init_colons ( ) ; export const emojiRegEx = emojiRegexRGI ( ) ; const colonEmojiCodeRegExp = /:[a-zA-Z0-9-_+]+:(:skin-tone-[2-6]:)?/g ; export function replaceColons ( str ) { return str . replace ( colonEmojiCodeRegExp , m => { const name = m . split ( ':' ) [ 1 ] ; const skintoneString = m . split ( ':' ) [ 3 ] ; const codePoints = instance . map . colons [ name ] ?. split ( '-' ) . map ( ( c ) => parseInt ( c , 16 ) ) ; if ( codePoints ) { if ( skintoneString ) { const skintoneResult = /^skin-tone-([2-6])$/ . exec ( skintoneString ) ; if ( skintoneResult ) { const skintoneNumber = Number ( skintoneResult [ 1 ] ) ; codePoints . push ( 0x1f3fb + ( skintoneNumber - 2 ) ) ; } } return String . fromCodePoint ( ... codePoints ) ; } return m ; } ) ; } export function replaceColonsSafe ( message ) { try { return replaceColons ( message ) ; } catch ( error ) { log . warn ( 'replaceColons failed' , error ) ; return message ; } } export function getSizeClass ( str ) { const conv = str . replace ( /-/g , '' ) . replace ( emojiRegEx , '-' ) ; if ( conv . replace ( /-/g , '' ) . trim ( ) . length > 0 ) { return '' ; } const emojiCount = conv . match ( /-/g ) ?. length || 0 ; if ( emojiCount > 8 ) { return '' ; } else if ( emojiCount > 6 ) { return 'small' ; } else if ( emojiCount > 4 ) { return 'medium' ; } else if ( emojiCount > 2 ) { return 'large' ; } else { return 'jumbo' ; } }