forked from skulpt/skulpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
John Denker
committed
Sep 21, 2015
1 parent
33e5949
commit fdd9078
Showing
1 changed file
with
59 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,62 @@ | ||
/*! https://mths.be/fromcodepoint v0.2.1 by @mathias */ | ||
if (!String.fromCodePoint) { | ||
(function() { | ||
var defineProperty = (function() { | ||
// IE 8 only supports `Object.defineProperty` on DOM elements | ||
try { | ||
var object = {}; | ||
var $defineProperty = Object.defineProperty; | ||
var result = $defineProperty(object, object, object) && $defineProperty; | ||
} catch(error) {} | ||
return result; | ||
}()); | ||
var stringFromCharCode = String.fromCharCode; | ||
var floor = Math.floor; | ||
var fromCodePoint = function(_) { | ||
var MAX_SIZE = 0x4000; | ||
var codeUnits = []; | ||
var highSurrogate; | ||
var lowSurrogate; | ||
var index = -1; | ||
var length = arguments.length; | ||
if (!length) { | ||
return ''; | ||
} | ||
var result = ''; | ||
while (++index < length) { | ||
var codePoint = Number(arguments[index]); | ||
if ( | ||
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity` | ||
codePoint < 0 || // not a valid Unicode code point | ||
codePoint > 0x10FFFF || // not a valid Unicode code point | ||
floor(codePoint) != codePoint // not an integer | ||
) { | ||
throw RangeError('Invalid code point: ' + codePoint); | ||
} | ||
if (codePoint <= 0xFFFF) { // BMP code point | ||
codeUnits.push(codePoint); | ||
} else { // Astral code point; split in surrogate halves | ||
// https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae | ||
codePoint -= 0x10000; | ||
highSurrogate = (codePoint >> 10) + 0xD800; | ||
lowSurrogate = (codePoint % 0x400) + 0xDC00; | ||
codeUnits.push(highSurrogate, lowSurrogate); | ||
} | ||
if (index + 1 == length || codeUnits.length > MAX_SIZE) { | ||
result += stringFromCharCode.apply(null, codeUnits); | ||
codeUnits.length = 0; | ||
} | ||
} | ||
return result; | ||
}; | ||
if (defineProperty) { | ||
defineProperty(String, 'fromCodePoint', { | ||
'value': fromCodePoint, | ||
'configurable': true, | ||
'writable': true | ||
}); | ||
} else { | ||
String.fromCodePoint = fromCodePoint; | ||
} | ||
}()); | ||
(function() { | ||
var defineProperty = (function() { | ||
// IE 8 only supports `Object.defineProperty` on DOM elements | ||
try { | ||
var object = {}; | ||
var $defineProperty = Object.defineProperty; | ||
var result = $defineProperty(object, object, object) && $defineProperty; | ||
} catch(error) {} | ||
return result; | ||
}()); | ||
var stringFromCharCode = String.fromCharCode; | ||
var floor = Math.floor; | ||
var fromCodePoint = function(_) { | ||
var MAX_SIZE = 0x4000; | ||
var codeUnits = []; | ||
var highSurrogate; | ||
var lowSurrogate; | ||
var index = -1; | ||
var length = arguments.length; | ||
if (!length) { | ||
return ''; | ||
} | ||
var result = ''; | ||
while (++index < length) { | ||
var codePoint = Number(arguments[index]); | ||
if ( | ||
!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity` | ||
codePoint < 0 || // not a valid Unicode code point | ||
codePoint > 0x10FFFF || // not a valid Unicode code point | ||
floor(codePoint) != codePoint // not an integer | ||
) { | ||
throw RangeError('Invalid code point: ' + codePoint); | ||
} | ||
if (codePoint <= 0xFFFF) { // BMP code point | ||
codeUnits.push(codePoint); | ||
} else { // Astral code point; split in surrogate halves | ||
// https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae | ||
codePoint -= 0x10000; | ||
highSurrogate = (codePoint >> 10) + 0xD800; | ||
lowSurrogate = (codePoint % 0x400) + 0xDC00; | ||
codeUnits.push(highSurrogate, lowSurrogate); | ||
} | ||
if (index + 1 == length || codeUnits.length > MAX_SIZE) { | ||
result += stringFromCharCode.apply(null, codeUnits); | ||
codeUnits.length = 0; | ||
} | ||
} | ||
return result; | ||
}; | ||
if (defineProperty) { | ||
defineProperty(String, 'fromCodePoint', { | ||
'value': fromCodePoint, | ||
'configurable': true, | ||
'writable': true | ||
}); | ||
} else { | ||
String.fromCodePoint = fromCodePoint; | ||
} | ||
}()); | ||
} |