From 5cdf5f3910567f48894b6f20afe174aa72540dd8 Mon Sep 17 00:00:00 2001 From: Naman Goel Date: Mon, 21 Aug 2017 16:22:03 -0700 Subject: [PATCH] Use proper script way to clone Emoji files from www Differential Revision: D5615872 fbshipit-source-id: 7f2c19f1a65f42b78136be7e6a608d0415c1a49f --- Libraries/polyfills/String.prototype.es6.js | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Libraries/polyfills/String.prototype.es6.js b/Libraries/polyfills/String.prototype.es6.js index 106c34694d13bd..195f5fd2969dd2 100644 --- a/Libraries/polyfills/String.prototype.es6.js +++ b/Libraries/polyfills/String.prototype.es6.js @@ -92,3 +92,39 @@ if (!String.prototype.includes) { } }; } + +if (!String.prototype.codePointAt) { + String.prototype.codePointAt = function(position) { + if (this == null) { + throw TypeError(); + } + var string = String(this); + var size = string.length; + // `ToInteger` + var index = position ? Number(position) : 0; + if (Number.isNaN(index)) { + index = 0; + } + // Account for out-of-bounds indices: + if (index < 0 || index >= size) { + return undefined; + } + // Get the first code unit + var first = string.charCodeAt(index); + var second; + if ( + // check if it’s the start of a surrogate pair + first >= 0xd800 && + first <= 0xdbff && // high surrogate + size > index + 1 // there is a next code unit + ) { + second = string.charCodeAt(index + 1); + if (second >= 0xdc00 && second <= 0xdfff) { + // low surrogate + // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae + return (first - 0xd800) * 0x400 + second - 0xdc00 + 0x10000; + } + } + return first; + }; +}