UNPKG

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