es.string.includes.js 857 B

123456789101112131415161718192021
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var uncurryThis = require('../internals/function-uncurry-this');
  4. var notARegExp = require('../internals/not-a-regexp');
  5. var requireObjectCoercible = require('../internals/require-object-coercible');
  6. var toString = require('../internals/to-string');
  7. var correctIsRegExpLogic = require('../internals/correct-is-regexp-logic');
  8. var stringIndexOf = uncurryThis(''.indexOf);
  9. // `String.prototype.includes` method
  10. // https://tc39.es/ecma262/#sec-string.prototype.includes
  11. $({ target: 'String', proto: true, forced: !correctIsRegExpLogic('includes') }, {
  12. includes: function includes(searchString /* , position = 0 */) {
  13. return !!~stringIndexOf(
  14. toString(requireObjectCoercible(this)),
  15. toString(notARegExp(searchString)),
  16. arguments.length > 1 ? arguments[1] : undefined
  17. );
  18. }
  19. });