Skip to content

Commit

Permalink
Add String.prototype.includes polyfill
Browse files Browse the repository at this point in the history
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 #5727
Closes #5735

Reviewed By: svcscm

Differential Revision: D2906667

Pulled By: vjeux

fb-gh-sync-id: e02f605bf57171062b29a98b98ba9fc898cedfc2
  • Loading branch information
cosmith authored and facebook-github-bot-7 committed Feb 5, 2016
1 parent d2ab6ca commit 2f73ad0
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
}

0 comments on commit 2f73ad0

Please sign in to comment.