es6.string.from-code-point.js 865 B

123456789101112131415161718192021222324
  1. var $export = require('./_export');
  2. var toAbsoluteIndex = require('./_to-absolute-index');
  3. var fromCharCode = String.fromCharCode;
  4. var $fromCodePoint = String.fromCodePoint;
  5. // length should be 1, old FF problem
  6. $export($export.S + $export.F * (!!$fromCodePoint && $fromCodePoint.length != 1), 'String', {
  7. // 21.1.2.2 String.fromCodePoint(...codePoints)
  8. fromCodePoint: function fromCodePoint(x) { // eslint-disable-line no-unused-vars
  9. var res = [];
  10. var aLen = arguments.length;
  11. var i = 0;
  12. var code;
  13. while (aLen > i) {
  14. code = +arguments[i++];
  15. if (toAbsoluteIndex(code, 0x10ffff) !== code) throw RangeError(code + ' is not a valid code point');
  16. res.push(code < 0x10000
  17. ? fromCharCode(code)
  18. : fromCharCode(((code -= 0x10000) >> 10) + 0xd800, code % 0x400 + 0xdc00)
  19. );
  20. } return res.join('');
  21. }
  22. });