32 lines
716 B
JavaScript
32 lines
716 B
JavaScript
(() => {
|
|
const root = window;
|
|
if (root?.twemoji?.convert?.toCodePoint) return;
|
|
|
|
function toCodePoint(unicodeSurrogates, sep = '-') {
|
|
const r = [];
|
|
let c = 0;
|
|
let p = 0;
|
|
let i = 0;
|
|
const s = String(unicodeSurrogates || '');
|
|
|
|
while (i < s.length) {
|
|
c = s.charCodeAt(i++);
|
|
if (p) {
|
|
r.push((0x10000 + ((p - 0xD800) * 0x400) + (c - 0xDC00)).toString(16));
|
|
p = 0;
|
|
} else if (c >= 0xD800 && c <= 0xDBFF) {
|
|
p = c;
|
|
} else {
|
|
r.push(c.toString(16));
|
|
}
|
|
}
|
|
|
|
return r.join(sep);
|
|
}
|
|
|
|
root.twemoji = root.twemoji || {};
|
|
root.twemoji.convert = root.twemoji.convert || {};
|
|
root.twemoji.convert.toCodePoint = toCodePoint;
|
|
})();
|
|
|