Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update emojilib to v3 #132

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"@sindresorhus/is": "^5.3.0",
"char-regex": "^2.0.1",
"emojilib": "^2.4.0",
"emojilib": "^3.0.10",
"skin-tone": "^3.0.0",
"tsup": "^6.7.0"
},
Expand Down
27 changes: 24 additions & 3 deletions src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,30 @@ import emojilib from 'emojilib'

import { normalizeCode } from './utils.js'

export const emojiData = Object.entries(emojilib.lib).map(
([name, { char: emoji }]) => [name, emoji]
)
export const emojiData = [
// First we fill in all possible names for each emoji
...Object.entries(emojilib).flatMap(([emoji, names]) => {
return names.map(name => [name, emoji])
}),
// Then we give priority to the first name for each emoji
...Object.entries(emojilib).flatMap(([emoji, [name]]) => {
const results = [[name, emoji]]

if (name.startsWith('flag_')) {
results.push([name.slice('flag_'.length), emoji])
}

if (name.startsWith('smiling_face_with_')) {
results.push([name.slice('smiling_face_with_'.length), emoji])
}

if (name.endsWith('_face')) {
results.push([name.slice(0, name.length - '_face'.length), emoji])
}

return results
}),
]
Copy link
Collaborator Author

@JoshuaKGoldberg JoshuaKGoldberg May 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a few explicit handlers (e.g. :mexico: is no longer an alias of :flag_mexico:). Other changes are causing more test failures. I don't know what to do here - do we maintain explicit backwards compatibility? File issues on emojilib? Accept breaking changes? 😬

cc @omnidan, I don't know what to do 😄

Copy link
Collaborator Author

@JoshuaKGoldberg JoshuaKGoldberg May 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked on Discord: I'm going to add compatibility helpers for the old aliases like this one. That way this isn't a breaking change for users in the sense of dropping emoji name support. Edit: there are a lot of changes 😞 so a compatibility layer would be quite large to write. Never mind on that.

I'll also look into whether we should file any issues on emojilib. muan/emojilib#178 indicated intentionally removing some aliases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'm waiting on #112 / muan/emojilib#194)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! How is the status of this??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WHoooo yeah how is the status...

  1. emojilib v3 had a bunch of changes to its keywords - to the point where node-emoji can't directly transition.
  2. I pinged the maintainer (muan) and was added as a collaborator there a few weeks ago.
  3. What I want to do next is make a comparison of keywords: what exists in unicode, common operating systems, common messaging apps, GitHub, etc. (beyond what muan actually asked for)
  4. I haven't found a good tracking table yet that has all that info
    • I sent a request to get access the invite-only Emojipedia API a day or two ago but haven't heard back yet

So there is progress being made, just... slow progress.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello beautiful humans, I love what you did with this lib and thank you for providing this library for developer like me to build on top of it, is there a way we can get this fix merged? I desprately need some emojis which are missing from your lib. Maybe we can add a .extend(":emoji-code","✅") function, just in case some emojis are missing, developer can update it and make it searchable across project?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add a .extend(":emoji-code","✅") function

Oh! I like that idea standalone - could you file a new issue for that please? Let's track it separately so we can maybe get it in much sooner!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #144 :)


export const emojiCodesByName = new Map(emojiData)

Expand Down
8 changes: 6 additions & 2 deletions src/emojify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ describe('emojify', () => {
it('parses multiple :emoji: in a string when there are multiple emoji', () => {
expect(
emojify(
'I :heart: :coffee:! - :hushed::star::heart_eyes: ::: test : : :+1:+'
'I :beating_heart: :coffee:! - :hushed::star::heart_eyes: ::: test : : :+1:+'
)
).toBe('I ❤️ ☕! - 😯⭐😍 ::: test : : 👍+')
).toBe('I 💓 ☕! - 😯⭐😍 ::: test : : 👍+')
})

it('formats emoji when given a format function', () => {
Expand All @@ -50,4 +50,8 @@ describe('emojify', () => {
})
).toBe('I [:unknown_emoji:] [⭐] [:another_one:]')
})

it('includes emojis added in emojilib v3', () => {
expect(emojify(':airplane_departure: and :flashlight:')).toBe('🛫 and 🔦')
})
})