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

Make [emoji] implementation deterministic #103

Closed
wants to merge 1 commit into from

Conversation

kohlikohl
Copy link

PR for issue #102.
Make use of hashing function to choose an emoji instead of randomly selecting one.
Fun fact: Not that this would be needed much but it supports 1k+ emojis per hash. 🚀

@jsf-clabot
Copy link

jsf-clabot commented Nov 8, 2017

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@TheLarkInn TheLarkInn left a comment

Choose a reason for hiding this comment

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

This looks great to me! Awesome work! 🙇‍♂️

Copy link
Member

@TheLarkInn TheLarkInn left a comment

Choose a reason for hiding this comment

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

Actually I just caught something with the help of @sokra "over my shoulder".

Instead of the .9999 approach, it needs to be more like https://github.com/webpack/loader-utils/blob/master/lib/getHashDigest.js where emoji is another base in addition to existing ones there.

Let me know if that makes sense @kohlikohl

@kohlikohl
Copy link
Author

@TheLarkInn I think that makes sense. I'll take another stab at it.

@kohlikohl kohlikohl force-pushed the deterministic-emojis branch 2 times, most recently from dcb56b2 to 43f0889 Compare November 9, 2017 07:52
@kohlikohl
Copy link
Author

@TheLarkInn @sokra Pushed an update. Is this what you had in mind?

@kohlikohl kohlikohl force-pushed the deterministic-emojis branch 2 times, most recently from 7ee5269 to 88497a3 Compare November 9, 2017 08:15
Copy link
Member

@sokra sokra left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Just a few little code style comments

return emojis.splice(0, maxLength).join("");
}

function sliceOutput(output, digestType, maxLength) {
Copy link
Member

Choose a reason for hiding this comment

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

To simpily this could you:

  • make encodeBufferToBase return an array.
  • Use Array.prototype.slice instead of String.prototype.substring to ensure maxLength
  • Convert array to string with join after that.
  • Remove sliceEmojis, sliceOutput, emoji-regex

Copy link
Author

Choose a reason for hiding this comment

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

As for the emoji-regex package. I'd encourage to keep it as it is better in detecting the different code points of emojis. Here is an example https://runkit.com/kohlikohl/emoji-regex.
The simple regex seems to only detect emojis that have two code points. Flags for example have four so it would miss identify and split them.
Maybe it is not relevant in this case, if so let me know and I'll make the final change.

@@ -36,15 +43,35 @@ function encodeBufferToBase(buffer, base) {
return output;
}

function getBase(digestType) {
Copy link
Member

Choose a reason for hiding this comment

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

To simpily this could you:

  • Add a encodeTable argument to encodeBufferToBase
  • Add a encodeBufferToDigestType which calls encodeBufferToBase with the correct arguments according to digestType.
  • Remove emojis from the baseEncodeTables (looks weird)

digestType === "base49" || digestType === "base52" || digestType === "base58" ||
digestType === "base62" || digestType === "base64") {
return encodeBufferToBase(hash.digest(), digestType.substr(4)).substr(0, maxLength);
if(digestType && !!baseEncodeTables[getBase(digestType)]) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a const array of valid digestTypes?

Copy link
Author

Choose a reason for hiding this comment

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

This was the idea with usingbaseEncodeTables as a const to not have to repeat the digestTypes. Lets see 😄

const emojisList = require("emojis-list");
const emojiRegex = require("emoji-regex")();

const BASE_EMOJI = "baseEmoji";
Copy link
Member

Choose a reason for hiding this comment

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

just call it emoji

@TheLarkInn
Copy link
Member

Requested changes pending, otherwise this is looking great so far. Excellent work @kohlikohl

@kohlikohl
Copy link
Author

Pushed the changes based on the comments. Please have another look @TheLarkInn @sokra

As mentioned in the response to the comments, I'd encourage to keep the emoji-regex package as it is better in detecting the different code points of emojis. Here is an example https://runkit.com/kohlikohl/emoji-regex.
The simple regex seems to only detect emojis that have two code points. Flags for example have four so it would miss identify and split them.
Maybe it is not relevant in this case, if so let me know and I'll make the final change.

@milushov
Copy link

milushov commented Dec 1, 2017

When this PR will be merged? :)

@kohlikohl
Copy link
Author

@TheLarkInn @sokra Are you guys happy with this PR? Is it ready to be merged in?

@michaeltaranto
Copy link

michaeltaranto commented Apr 5, 2018

Would love to see this merged. @kohlikohl can i suggest fixing the coverage regression, as maybe the lack of a ✅ on the PR checks is halting the approvals?

@alexander-akait
Copy link
Member

/cc @kohlikohl sorry for big delay, can you rebase feature?

@alexander-akait
Copy link
Member

No valid anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants