1- const React = require ( 'react' )
2- const Emoji = require ( './index' ) ;
3- require ( './default-svg.css' )
1+ import React from 'react'
2+ import * as Emoji from './index'
3+ import './default-svg.css'
44
55function reactReplaceEmojis ( reactChild , options ) {
66 let newReactChild ;
@@ -34,7 +34,7 @@ function reactReplaceEmojis(reactChild, options) {
3434 return newReactChild ;
3535}
3636
37- function replaceEmojis ( string , options ) {
37+ export function replaceEmojis ( string , options ) {
3838 if ( ! string ) return ;
3939 let array = [ string ]
4040
@@ -43,12 +43,15 @@ function replaceEmojis(string, options) {
4343 outline : typeof options ?. outline === 'boolean' ? options . outline : undefined
4444 } ;
4545
46- // matches all emojis matches all attached components matches that is joined (zwj)
47- // \p{Extended_Pictographic}[\u{1f3fb}-\u{1f3ff}\u{1f9b0}-\u{1f9b3}]?(\u200d.)?\ufe0f?(?!\ufe0e)
48- // matches only non-"text style" emojis
46+ /*
47+ * matches all emojis matches all attached components
48+ * \p{Extended_Pictographic}[\u{1f3fb}-\u{1f3ff}\u{1f9b0}-\u{1f9b3}]? un-matches "text style"
49+ * (\u200d\p{Extended_Pictographic}[\u{1f3fb}-\u{1f3ff}\u{1f9b0}-\u{1f9b3}]?)*[\u2640\u2642]?\ufe0f?(?!\ufe0e)/gu
50+ * matches all joined (ZWJ) emojis with all attached components matches attached gender
51+ */
4952
50- const regex = / \p{ Extended_Pictographic} [ \u{1f3fb} - \u{1f3ff} \u{1f9b0} - \u{1f9b3} ] ? ( \u200d . ) ? \ufe0f ? (? ! \ufe0e ) / gu;
51- let m ;
53+ const regex = / \p{ Extended_Pictographic} [ \u{1f3fb} - \u{1f3ff} \u{1f9b0} - \u{1f9b3} ] ? ( \u200d \p { Extended_Pictographic } [ \u{1f3fb} - \u{1f3ff} \u{1f9b0} - \u{1f9b3} ] ? ) * [ \u2640 \u2642 ] ? \ufe0f ? (? ! \ufe0e ) / gu;
54+ let m , j = 0 ;
5255
5356 while ( ( m = regex . exec ( string ) ) !== null ) {
5457 // This is necessary to avoid infinite loops with zero-width matches
@@ -71,6 +74,8 @@ function replaceEmojis(string, options) {
7174 }
7275
7376 let emojiSvg = Emoji [ emojiName ] ;
77+ options . key = j
78+ j ++
7479 if ( emojiSvg ) {
7580 // gets last string ['String with {Emoji} and {Emoji} in it'] -> 'String with {Emoji} and {Emoji} in it'
7681 let workingString = array . pop ( )
@@ -92,10 +97,4 @@ function replaceEmojis(string, options) {
9297 return array ;
9398}
9499
95- reactReplaceEmojis . replaceEmojis = replaceEmojis
96- for ( const key in Emoji ) {
97- if ( ! Emoji . hasOwnProperty ( key ) ) continue
98- reactReplaceEmojis [ key ] = Emoji [ key ]
99- }
100-
101- module . exports = reactReplaceEmojis
100+ export * from './index' ;
0 commit comments