Skip to content

Commit

Permalink
Resolve #13
Browse files Browse the repository at this point in the history
Possible solution.
  • Loading branch information
nkalvi committed Oct 9, 2022
1 parent 2e97afb commit ed1717a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions data-by-emoji.json
Original file line number Diff line number Diff line change
Expand Up @@ -12256,15 +12256,15 @@
},
"#️⃣": {
"name": "keycap #",
"slug": "keycap_",
"slug": "keycap_number_sign",
"group": "Symbols",
"emoji_version": "0.6",
"unicode_version": "0.6",
"skin_tone_support": false
},
"*️⃣": {
"name": "keycap *",
"slug": "keycap_",
"slug": "keycap_asterix",
"group": "Symbols",
"emoji_version": "2.0",
"unicode_version": "2.0",
Expand Down
4 changes: 2 additions & 2 deletions data-by-group.json
Original file line number Diff line number Diff line change
Expand Up @@ -12273,15 +12273,15 @@
"emoji": "#️⃣",
"skin_tone_support": false,
"name": "keycap #",
"slug": "keycap_",
"slug": "keycap_number_sign",
"unicode_version": "0.6",
"emoji_version": "0.6"
},
{
"emoji": "*️⃣",
"skin_tone_support": false,
"name": "keycap *",
"slug": "keycap_",
"slug": "keycap_asterix",
"unicode_version": "2.0",
"emoji_version": "2.0"
},
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion script/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,35 @@ groupedEmojiData.split('\n').forEach(line => {
}
})


// 'flag: St. Kitts & Nevis' -> 'flag_st_kitts_nevis'
// 'family: woman, woman, boy, boy' -> 'family_woman_woman_boy_boy'
// 'A button (blood type)' -> 'a_button'
// 'Cocos (Keeling) Islands' -> 'cocos_islands'
//
// Returns machine readable emoji short code
function slugify(str) {
return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/\(.+\)/g, '').trim().replace(/[\W|_]+/g, '_').toLowerCase()

// Helpers for slugify
const SLUGIFY_REPLACEMENT = new Map([
["*", "asterix"],
["#", "number sign"]
])

const charsToReplace = Array.from(SLUGIFY_REPLACEMENT.keys()).map(x => escapeRegExp(x)).join("|")
const regexSlugify = new RegExp(`([${escapeRegExp(charsToReplace)}])`, 'g')

function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}

function replacer(match, p1, offset, string) {
return SLUGIFY_REPLACEMENT.has(p1) ? SLUGIFY_REPLACEMENT.get(p1) : p1;
}

return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/\(.+\)/g, '').trim()
.replace(regexSlugify, replacer)
.replace(/[\W|_]+/g, '_').toLowerCase()
}

// U+1F44B ; 6.0 # 👋 waving hand
Expand Down

0 comments on commit ed1717a

Please sign in to comment.