UNPKG

emoji-data

Version:

Emoji encoding swiss army knife for NodeJS

84 lines (71 loc) 1.93 kB
// Generated by CoffeeScript 1.8.0 var EmojiChar, punycode; punycode = require('punycode'); EmojiChar = (function() { function EmojiChar(blob) { var k, v; for (k in blob) { v = blob[k]; this[k] = v; } if (this.variations == null) { this.variations = []; } } EmojiChar.prototype.is_doublebyte = function() { return this.unified.indexOf('-') !== -1; }; EmojiChar.prototype.has_variants = function() { return this.variations.length > 0; }; EmojiChar.prototype.variant = function() { if (!(this.variations.length > 0)) { return null; } return this.variations[0]; }; EmojiChar.prototype.render = function(_arg) { var target, variant_encoding; variant_encoding = (_arg != null ? _arg : { variant_encoding: true }).variant_encoding; target = (function() { switch (false) { case !(this.has_variants() && variant_encoding): return this.variant(); default: return this.unified; } }).call(this); return EmojiChar._unified_to_char(target); }; EmojiChar.prototype.chars = function() { var id, _i, _len, _ref, _results; _ref = [this.unified].concat(this.variations); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { id = _ref[_i]; _results.push(EmojiChar._unified_to_char(id)); } return _results; }; EmojiChar.prototype.toString = function() { return this.render(); }; EmojiChar._unified_to_char = function(uid) { var cp, cps; cps = (function() { var _i, _len, _ref, _results; _ref = uid.split('-'); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { cp = _ref[_i]; _results.push(parseInt(cp, 16)); } return _results; })(); return punycode.ucs2.encode(cps); }; return EmojiChar; })(); module.exports = EmojiChar;