From 2f73ad0241453fac379925a8c48426c5125ed2eb Mon Sep 17 00:00:00 2001 From: Corentin Smith Date: Fri, 5 Feb 2016 12:08:49 -0800 Subject: [PATCH] Add String.prototype.includes polyfill Summary: Add a polyfill for `String.prototype.includes` taken from MDN (https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/includes) See https://github.com/facebook/react-native/issues/5727 Closes https://github.com/facebook/react-native/pull/5735 Reviewed By: svcscm Differential Revision: D2906667 Pulled By: vjeux fb-gh-sync-id: e02f605bf57171062b29a98b98ba9fc898cedfc2 --- .../Resolver/polyfills/String.prototype.es6.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packager/react-packager/src/Resolver/polyfills/String.prototype.es6.js b/packager/react-packager/src/Resolver/polyfills/String.prototype.es6.js index afc68d76a..c455ef1ee 100644 --- a/packager/react-packager/src/Resolver/polyfills/String.prototype.es6.js +++ b/packager/react-packager/src/Resolver/polyfills/String.prototype.es6.js @@ -83,3 +83,18 @@ if (!String.prototype.repeat) { return result; }; } + +if (!String.prototype.includes) { + String.prototype.includes = function(search, start) { + 'use strict'; + if (typeof start !== 'number') { + start = 0; + } + + if (start + search.length > this.length) { + return false; + } else { + return this.indexOf(search, start) !== -1; + } + }; +}