"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/es5-ext/string/from-code-point/shim.js" (7 Feb 2017, 829 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Based on:
    2 // http://norbertlindenberg.com/2012/05/ecmascript-supplementary-characters/
    3 // and:
    4 // https://github.com/mathiasbynens/String.fromCodePoint/blob/master
    5 // /fromcodepoint.js
    6 
    7 'use strict';
    8 
    9 var floor = Math.floor, fromCharCode = String.fromCharCode;
   10 
   11 module.exports = function (codePoint/*, …codePoints*/) {
   12     var chars = [], l = arguments.length, i, c, result = '';
   13     for (i = 0; i < l; ++i) {
   14         c = Number(arguments[i]);
   15         if (!isFinite(c) || c < 0 || c > 0x10FFFF || floor(c) !== c) {
   16             throw new RangeError("Invalid code point " + c);
   17         }
   18 
   19         if (c < 0x10000) {
   20             chars.push(c);
   21         } else {
   22             c -= 0x10000;
   23             chars.push((c >> 10) + 0xD800, (c % 0x400) + 0xDC00);
   24         }
   25         if (i + 1 !== l && chars.length <= 0x4000) continue;
   26         result += fromCharCode.apply(null, chars);
   27         chars.length = 0;
   28     }
   29     return result;
   30 };