UNPKG

999 BJavaScriptView Raw
1var $ = require('../internals/export');
2var toAbsoluteIndex = require('../internals/to-absolute-index');
3
4var fromCharCode = String.fromCharCode;
5var nativeFromCodePoint = String.fromCodePoint;
6
7// length should be 1, old FF problem
8var INCORRECT_LENGTH = !!nativeFromCodePoint && nativeFromCodePoint.length != 1;
9
10// `String.fromCodePoint` method
11// https://tc39.github.io/ecma262/#sec-string.fromcodepoint
12$({ target: 'String', stat: true, forced: INCORRECT_LENGTH }, {
13 fromCodePoint: function fromCodePoint(x) { // eslint-disable-line no-unused-vars
14 var elements = [];
15 var length = arguments.length;
16 var i = 0;
17 var code;
18 while (length > i) {
19 code = +arguments[i++];
20 if (toAbsoluteIndex(code, 0x10FFFF) !== code) throw RangeError(code + ' is not a valid code point');
21 elements.push(code < 0x10000
22 ? fromCharCode(code)
23 : fromCharCode(((code -= 0x10000) >> 10) + 0xD800, code % 0x400 + 0xDC00)
24 );
25 } return elements.join('');
26 }
27});