blob: 41fd7378f81c530b1ea5ea9d9acf9cf9bf2eb882 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
// Based on:
// http://norbertlindenberg.com/2012/05/ecmascript-supplementary-characters/
// and:
// https://github.com/mathiasbynens/String.fromCodePoint/blob/master
// /fromcodepoint.js
'use strict';
var floor = Math.floor, fromCharCode = String.fromCharCode;
module.exports = function (codePoint/*, …codePoints*/) {
var chars = [], l = arguments.length, i, c, result = '';
for (i = 0; i < l; ++i) {
c = Number(arguments[i]);
if (!isFinite(c) || c < 0 || c > 0x10FFFF || floor(c) !== c) {
throw new RangeError("Invalid code point " + c);
}
if (c < 0x10000) {
chars.push(c);
} else {
c -= 0x10000;
chars.push((c >> 10) + 0xD800, (c % 0x400) + 0xDC00);
}
if (i + 1 !== l && chars.length <= 0x4000) continue;
result += fromCharCode.apply(null, chars);
chars.length = 0;
}
return result;
};
|