Skip to content

Commit 8ed3f14

Browse files
committed
fixes #11, makes characters from #10 work, update deps
1 parent b570050 commit 8ed3f14

5 files changed

Lines changed: 504 additions & 452 deletions

File tree

build/build.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ if (fs.existsSync(srcPath)) {
3232
}
3333

3434
const OPENMOJI_DIR = '../../openmoji'
35+
// const OPENMOJI_DIR = '../node_modules/openmoji'
3536
// get openmoji.json
3637
const index = JSON.parse(fs.readFileSync(path.join(__dirname, OPENMOJI_DIR, 'data/openmoji.json')).toString());
3738

@@ -79,7 +80,7 @@ const ${iconName} = ({size, outline}) => {
7980
'<svg id="emoji"',
8081
'<svg width={size} height={size} className="openmoji"'
8182
)
82-
.replace(/x[a-z]+:[a-z]+="[^>]+"/g, '')/*rem namespace tags*/
83+
.replace(/[a-z]+:[a-z]+="[^>"]+"/g, '')/*rem namespace tags*/
8384
.replace(/\n */g, '')}
8485
);
8586
} else {
@@ -88,7 +89,7 @@ const ${iconName} = ({size, outline}) => {
8889
'<svg id="emoji"',
8990
'<svg width={size} height={size} className="openmoji"'
9091
)
91-
.replace(/x[a-z]+:[a-z]+="[^>]+"/g, '')/*rem namespace tags*/
92+
.replace(/[a-z]+:[a-z]+="[^>"]+"/g, '')/*rem namespace tags*/
9293
.replace(/\n +/g, '')}
9394
);
9495
}

build/correct-dom-properties.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ iconScriptFiles.forEach(file => {
1010
content.replace(/"stroke-width"/g, 'strokeWidth')
1111
.replace(/"stroke-linejoin"/g, 'strokeLinejoin')
1212
.replace(/"stroke-linecap"/g, 'strokeLinecap')
13-
.replace(/"stroke-miterlimit"/g, 'strokeMiterlimit'),
13+
.replace(/"stroke-miterlimit"/g, 'strokeMiterlimit')
14+
.replace(/"fill-rule"/g, 'fillRule')
15+
.replace(/"clip-rule"/g, 'clipRule'),
1416
{encoding: 'utf-8'}, (err) => {
1517
if (err) throw err;
1618
});

build/main.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ const _applyCorrectReplace = (child, options) =>
3535
export function replaceEmojis(string, options) {
3636
if (!string) return;
3737
let array = [string]
38-
38+
if (!options)
39+
options = {}
3940
options = {
40-
size: typeof options?.size === 'string' ? options.size : undefined,
41-
outline: typeof options?.outline === 'boolean' ? options.outline : undefined
41+
size: typeof options.size === 'string' ? options.size : undefined,
42+
outline: typeof options.outline === 'boolean' ? options.outline : undefined
4243
};
4344

4445
/*
@@ -48,7 +49,7 @@ export function replaceEmojis(string, options) {
4849
* matches all joined (ZWJ) emojis with all attached components matches attached gender
4950
*/
5051

51-
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;
52+
const regex = /\p{Extended_Pictographic}[\u{1f3fb}-\u{1f3ff}\u{1f9b0}-\u{1f9b3}]?\ufe0f?(\u200d\p{Extended_Pictographic}[\u{1f3fb}-\u{1f3ff}\u{1f9b0}-\u{1f9b3}]?\ufe0f?)*[\u2640\u2642]?\ufe0f?(?!\ufe0e)/gu;
5253
let m, j = 0;
5354

5455
while ((m = regex.exec(string)) !== null) {
@@ -63,10 +64,11 @@ export function replaceEmojis(string, options) {
6364
let subUnicode = m[0].codePointAt(i)
6465
// dismiss low surrogates characters (56320-57343)
6566
if ((subUnicode >= 56320 && subUnicode <= 57343)) continue
66-
emojiName += '_' + subUnicode?.toString(16).toUpperCase()
67+
if (subUnicode)
68+
emojiName += '_' + subUnicode.toString(16).toUpperCase()
6769

6870
// check if is done: if this hexcode is longer than 4, check the next but one codepoint
69-
done = m[0].codePointAt(i)?.toString(16).length > 4
71+
done = m[0].codePointAt(i).toString(16).length > 4
7072
? !m[0].codePointAt(i + 2)
7173
: !m[0].codePointAt(i + 1)
7274
}

0 commit comments

Comments
 (0)