emoji: Iterate over emoji_codes data with Object.{entries,values}.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2020-02-05 17:16:33 -08:00 committed by Tim Abbott
parent 5de013b11e
commit 8bb515dbd9
3 changed files with 10 additions and 11 deletions

View File

@ -115,7 +115,7 @@ run_test('translate_emoticons_to_names', () => {
{name: 'between symbols', original: 'Hello.<original>! World.', expected: 'Hello.<original>! World.'},
{name: 'before end of sentence', original: 'Hello <original>!', expected: 'Hello <converted>!'},
];
_.each(emoji_codes.emoticon_conversions, (full_name, shortcut) => {
for (const [shortcut, full_name] of Object.entries(emoji_codes.emoticon_conversions)) {
_.each(testcases, (t) => {
const converted_value = full_name;
let original = t.original;
@ -126,5 +126,5 @@ run_test('translate_emoticons_to_names', () => {
const result = emoji.translate_emoticons_to_names(original);
assert.equal(result, expected);
});
});
}
});

View File

@ -77,9 +77,8 @@ exports.initialize = function initialize() {
exports.build_emoji_data = function (realm_emojis) {
exports.emojis_by_name.clear();
let emoji_dict;
for (const [realm_emoji_name, realm_emoji] of realm_emojis) {
emoji_dict = {
const emoji_dict = {
name: realm_emoji_name,
display_name: realm_emoji_name,
aliases: [realm_emoji_name],
@ -90,12 +89,12 @@ exports.build_emoji_data = function (realm_emojis) {
exports.emojis_by_name.set(realm_emoji_name, emoji_dict);
}
_.each(emoji_codes.emoji_catalog, function (codepoints) {
_.each(codepoints, function (codepoint) {
for (const codepoints of Object.values(emoji_codes.emoji_catalog)) {
for (const codepoint of codepoints) {
if (emoji_codes.codepoint_to_name.hasOwnProperty(codepoint)) {
const emoji_name = emoji_codes.codepoint_to_name[codepoint];
if (!exports.emojis_by_name.has(emoji_name)) {
emoji_dict = {
const emoji_dict = {
name: emoji_name,
display_name: emoji_name,
aliases: exports.default_emoji_aliases.get(codepoint),
@ -106,8 +105,8 @@ exports.build_emoji_data = function (realm_emojis) {
exports.emojis_by_name.set(emoji_name, emoji_dict);
}
}
});
});
}
}
};
exports.build_emoji_upload_widget = function () {

View File

@ -106,7 +106,7 @@ exports.generate_emoji_picker_data = function (realm_emojis) {
exports.complete_emoji_catalog.Custom.push(emoji.emojis_by_name.get(realm_emoji_name));
}
_.each(emoji_codes.emoji_catalog, function (codepoints, category) {
for (const [category, codepoints] of Object.entries(emoji_codes.emoji_catalog)) {
exports.complete_emoji_catalog[category] = [];
_.each(codepoints, function (codepoint) {
if (emoji_codes.codepoint_to_name.hasOwnProperty(codepoint)) {
@ -118,7 +118,7 @@ exports.generate_emoji_picker_data = function (realm_emojis) {
}
}
});
});
}
exports.complete_emoji_catalog.Popular = [];
_.each(typeahead.popular_emojis, function (codepoint) {