/////////////////////////
/////////////////////////
function fromCodePoint(codepoint) {
var code = typeof codepoint === 'string' ?
parseInt(codepoint, 16) : codepoint;
return fromCharCode(code);
function parse(what, how) {
if (!how || typeof how === 'function') {
// if first argument is string, inject html <img> tags
// otherwise use the DOM tree and parse text nodes only
return (typeof what === 'string' ? parseString : parseNode)(what, {
callback: how.callback || defaultImageSrcGenerator,
attributes: typeof how.attributes === 'function' ? how.attributes : returnNull,
base: typeof how.base === 'string' ? how.base : twemoji.base,
ext: how.ext || twemoji.ext,
size: how.folder || toSizeSquaredAsset(how.size || twemoji.size),
className: how.className || twemoji.className,
onerror: how.onerror || twemoji.onerror
function replace(text, callback) {
return String(text).replace(re, callback);
// IE6 needs a reset before too
var result = re.test(text);
function toCodePoint(unicodeSurrogates, sep) {
while (i < unicodeSurrogates.length) {
c = unicodeSurrogates.charCodeAt(i++);
r.push((0x10000 + ((p - 0xD800) << 10) + (c - 0xDC00)).toString(16));
} else if (0xD800 <= c && c <= 0xDBFF) {
return r.join(sep || '-');