Skip to content

Commit

Permalink
Merge pull request #47 from KwanEsq/emojibase
Browse files Browse the repository at this point in the history
Switch to emojibase-data for emoji info in tests
  • Loading branch information
jfkthame authored Apr 17, 2019
2 parents f95494b + 00ad395 commit 4fc88a8
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"url": "git+https://github.com/mozilla/twemoji-colr.git"
},
"dependencies": {
"emoji-table": "^0.1.0",
"emojibase-data": "^3.2.1",
"grunt": "^1.0.2",
"grunt-cli": "^1.2.0",
"grunt-webfont": "^1.6.0",
Expand Down
72 changes: 58 additions & 14 deletions tests/reporter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var EmojiInfoService = {
URL: '../node_modules/emoji-table/dist/emoji.json',
URL: '../node_modules/emojibase-data/en/compact.json',
map: null,

_initPromise: null,
Expand All @@ -19,18 +19,64 @@ var EmojiInfoService = {
this.map = new Map();

if (!json) {
console.warn('EmojiInfoService: Failed to load table.');
console.warn('EmojiInfoService: Failed to load data.');
return;
};
for (var info of json) {
this.map.set(info.code, info);
if (info.skins) {
this._flattenSkins(info);
}
this.map.set(info.hexcode, info);
}
this._augmentInfo();
}.bind(this));

this._initPromise = p;
return p;
},

_flattenSkins: function(emoji) {
for (var skin of emoji.skins) {
skin.tags = emoji.tags;
this.map.set(skin.hexcode, skin);
}
emoji.skins = undefined;
},

_augmentInfo: function() {
// Regional Indicator Symbol Letters
for (var i = 127462; i <= 127487; ++i) {
// '1F1E6' <= && <= '1F1FF'
// RISLs are offset from their plain ascii cousins by 127397
var letter = String.fromCodePoint(i - 127397);
var hexcode = i.toString(16).toUpperCase();
this.map.set(hexcode, {
annotation: 'regional indicator symbol letter ' + letter,
tags: ['regional', 'letter', letter],
hexcode,
});
}
// Fitzpatrick skin tone modifiers
var toneMap = {
'1F3FB': ['Light', '1-2'], '1F3FC': ['Medium-Light', 3],
'1F3FD': ['Medium', 4], '1F3FE': ['Medium-Dark', 5],
'1F3FF': ['Dark', 6],
};
for (var [hexcode, [name, type]] of Object.entries(toneMap)) {
this.map.set(hexcode, {
annotation: `${name} skin tone modifier`,
tags: [name + ' skin tone', 'fitzpatrick', 'type ' + type],
hexcode,
});
}
// Non-standard
this.map.set('E50A', {
annotation: 'shibuya',
tags: ['private use area', 'non-standard'],
hexcode: 'E50A',
});
},

getInfo: function(codePoints) {
var p = Promise.resolve();
if (!this.map) {
Expand All @@ -42,17 +88,15 @@ var EmojiInfoService = {
while (str.length < 4) {
str = '0' + str;
}
return 'U+' + str;
return str;
});

var i = codePoints.length;
do {
var str = codePointsStrArr.slice(0, i).join(' ');
var info = this.map.get(str);
if (info) {
return info;
}
} while (--i);

var str = codePointsStrArr.join('-');
var info = this.map.get(str);
if (info) {
return info;
}

return null;
}.bind(this));
Expand Down Expand Up @@ -246,11 +290,11 @@ TestReport.prototype = {
EmojiInfoService.getInfo(result.codePoints)
.then(function(info) {
if (!info) {
infoEl.parentNode.removeChild(infoEl);
infoEl.textContent = 'tags: non-standard';
return;
}
infoEl.textContent =
info.name + '. tags: ' + info.tags.join(', ') + '.';
info.annotation + '. tags: ' + info.tags.join(', ') + '.';
})
.catch(function(e) { console.error(e); });
reportEl.appendChild(infoEl);
Expand Down

0 comments on commit 4fc88a8

Please sign in to comment.