node/tools/eslint/node_modules/es5-ext/string/from-code-point/shim.js
Michaël Zasso 2d441493a4 tools: update eslint to v1.10.3
PR-URL: https://github.com/nodejs/io.js/pull/2286
Reviewed-By: Roman Reiss <me@silverwind.io>
2016-01-13 23:15:39 +01:00

31 lines
829 B
JavaScript

// 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;
};