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

123456789101112131415161718192021222324
  1. var $export = require('./$.export')
  2. , toIndex = require('./$.to-index')
  3. , fromCharCode = String.fromCharCode
  4. , $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. , $$ = arguments
  11. , $$len = $$.length
  12. , i = 0
  13. , code;
  14. while($$len > i){
  15. code = +$$[i++];
  16. if(toIndex(code, 0x10ffff) !== code)throw RangeError(code + ' is not a valid code point');
  17. res.push(code < 0x10000
  18. ? fromCharCode(code)
  19. : fromCharCode(((code -= 0x10000) >> 10) + 0xd800, code % 0x400 + 0xdc00)
  20. );
  21. } return res.join('');
  22. }
  23. });