@gaikema/emojify
Version:
Transform a block of text into an emojipasta
35 lines (34 loc) • 896 B
JavaScript
;
class Emojify {
constructor(text) {
this.text = text;
}
static zip(a, b) {
let c = a.map(function (e, i) {
return [e, b[i]];
});
return [].concat.apply([], c);
}
static printCodes() {
console.log(Emojify.codes);
}
static sample(arr) {
let n = arr.length;
let res = new Array();
for (let i = 0; i < n; i++) {
let index = Math.floor(Math.random() * n);
res.push(arr[index]);
}
return res;
}
emojify() {
let prep = this.text.split(" ");
let emojis = Emojify.sample(Emojify.codes.map(function (e) {
return String.fromCodePoint(Number(e));
}));
let c = Emojify.zip(prep, emojis);
return c.join(" ");
}
}
Emojify.codes = require('../data/emojis.json');
exports.Emojify = Emojify;