Skip to content

Commit 1672d07

Browse files
committed
emoji-replacement for all concatinations
also upgrade main.js to es6 for default export
1 parent bfeb541 commit 1672d07

3 files changed

Lines changed: 18 additions & 19 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ const App = () => {
155155
export default App;
156156
```
157157

158-
> **Fun fact:** Importing all 3914 emojis at once is actually just as fast as the other methods because all emojis are dynamically loaded:
158+
> **Fun fact:** Importing all 3678 emojis at once is actually just as fast as the other methods because all emojis are dynamically loaded:
159159
160160
```jsx
161161
import React from 'react';

build/main.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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

55
function 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';

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "react-openmoji",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"description": "openmoji for react",
55
"main": "lib/main.js",
66
"scripts": {
7-
"postinstall": "node build/build.js && npx babel --presets @babel/preset-react src --out-dir lib --copy-files && node build/correct-dom-properties.js"
7+
"postinstall": "node build/build.js && npx babel --presets @babel/preset-react src --out-dir lib --copy-files && node build/correct-dom-properties.js && rm -rf src"
88
},
99
"author": "drinking-code",
1010
"license": "CC-BY-SA-4.0",

0 commit comments

Comments
 (0)