Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

string.prototype.includes

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string.prototype.includes - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

.eslintrc

2

auto.js
/*! https://mths.be/includes v2.0.0 by @mathias */
'use strict';
require('./shim')();

16

implementation.js

@@ -5,7 +5,7 @@ /*! https://mths.be/includes v2.0.0 by @mathias */

var callBound = require('es-abstract/helpers/callBound')
var RequireObjectCoercible = require('es-abstract/2019/RequireObjectCoercible');
var ToString = require('es-abstract/2019/ToString');
var ToInteger = require('es-abstract/2019/ToInteger');
var IsRegExp = require('es-abstract/2019/IsRegExp');
var callBound = require('call-bind/callBound');
var RequireObjectCoercible = require('es-abstract/2024/RequireObjectCoercible');
var ToString = require('es-abstract/2024/ToString');
var ToIntegerOrInfinity = require('es-abstract/2024/ToIntegerOrInfinity');
var IsRegExp = require('es-abstract/2024/IsRegExp');

@@ -20,3 +20,3 @@ var min = Math.min;

if (IsRegExp(searchString)) {
throw TypeError('Argument to String.prototype.includes cannot be a RegExp');
throw new TypeError('Argument to String.prototype.includes cannot be a RegExp');
}

@@ -26,3 +26,3 @@ var searchStr = String(searchString);

var position = arguments.length > 1 ? arguments[1] : undefined;
var pos = ToInteger(position);
var pos = ToIntegerOrInfinity(position);
var len = S.length;

@@ -34,3 +34,3 @@ var start = min(max(pos, 0), len);

}
return indexOf(S, searchStr, pos) != -1;
return indexOf(S, searchStr, pos) !== -1;
};

@@ -5,3 +5,3 @@ /*! https://mths.be/includes v2.0.0 by @mathias */

var callBind = require('es-abstract/helpers/callBind');
var callBind = require('call-bind');
var define = require('define-properties');

@@ -8,0 +8,0 @@

{
"name": "string.prototype.includes",
"version": "2.0.0",
"version": "2.0.1",
"description": "A robust & optimized `String.prototype.includes` polyfill, based on the ECMAScript 6 specification.",

@@ -10,5 +10,5 @@ "homepage": "https://mths.be/includes",

"./auto": "./auto.js",
"./polyfill": "./polyfill.js",
"./implementation": "./implementation.js",
"./shim": "./shim.js",
"./getPolyfill": "./getPolyfill.js",
"./implementation": "./implementation.js",
"./package.json": "./package.json"

@@ -34,18 +34,30 @@ },

"scripts": {
"pretest": "es-shim-api --bound",
"lint": "eslint --ext=js,mjs .",
"postlint": "es-shim-api --bound",
"pretest": "npm run lint",
"test": "npm run tests-only",
"tests-only": "tape 'tests/*.js'",
"posttest": "npx npm@'>=10.2' audit --production",
"cover": "istanbul cover --report html --verbose --dir coverage tape 'tests/*.js'"
},
"dependencies": {
"define-properties": "^1.1.3",
"es-abstract": "^1.17.5"
"call-bind": "^1.0.7",
"define-properties": "^1.2.1",
"es-abstract": "^1.23.3"
},
"devDependencies": {
"@es-shims/api": "^2.1.2",
"function-bind": "^1.1.1",
"functions-have-names": "^1.2.1",
"@es-shims/api": "^2.5.1",
"@ljharb/eslint-config": "^21.1.1",
"eslint": "=8.8.0",
"functions-have-names": "^1.2.3",
"istanbul": "^0.4.5",
"tape": "^5.0.0"
"mock-property": "^1.1.0",
"tape": "^5.9.0"
},
"engines": {
"node": ">= 0.4"
},
"directories": {
"test": "tests"
}
}

@@ -8,3 +8,3 @@ 'use strict';

var defineProperties = require('define-properties');
var bind = require('function-bind');
var callBind = require('call-bind');
var isEnumerable = Object.prototype.propertyIsEnumerable;

@@ -28,5 +28,5 @@ var functionsHaveNames = require('functions-have-names')();

runTests(bind.call(Function.call, String.prototype.includes), t);
runTests(callBind(String.prototype.includes), t);
t.end();
});
'use strict';
var mockProperty = require('mock-property');
function fakeArg(fn) {
return function(st) {
try {
Object.prototype[1] = 2; // try to break `arguments[1]`
fn(st);
} finally {
delete Object.prototype[1];
}
return function (st) {
// try to break `arguments[1]`
st.teardown(mockProperty(Object.prototype, 1, { value: 2 }));
return fn(st);
};
}
module.exports = function(includes, t) {
t.test('cast searchString arg', fakeArg(function(st) {
module.exports = function (includes, t) {
t.test('cast searchString arg', fakeArg(function (st) {
st.equals(includes('abc'), false);

@@ -29,3 +28,3 @@ st.equals(includes('aundefinedb'), true);

t.test('basic support', fakeArg(function(st) {
t.test('basic support', fakeArg(function (st) {
st.equals(includes('abc', 'abc'), true);

@@ -40,3 +39,3 @@ st.equals(includes('abc', 'def'), false);

t.test('pos argument', function(st) {
t.test('pos argument', function (st) {
st.equals(includes('abc', 'b', -Infinity), true);

@@ -55,7 +54,7 @@ st.equals(includes('abc', 'b', -1), true);

st.equals(includes('abc', 'b', 4), false);
st.equals(includes('abc', 'b', +Infinity), false);
st.equals(includes('abc', 'b', Number(Infinity)), false);
st.end();
});
t.test('cast stringSearch arg with pos - included', function(st) {
t.test('cast stringSearch arg with pos - included', function (st) {
st.equals(includes('abc123def', 1, -Infinity), true);

@@ -75,7 +74,7 @@ st.equals(includes('abc123def', 1, -1), true);

st.equals(includes('abc123def', 1, 5), false);
st.equals(includes('abc123def', 1, +Infinity), false);
st.equals(includes('abc123def', 1, Number(Infinity)), false);
st.end();
});
t.test('cast stringSearch arg with pos - not included', function(st) {
t.test('cast stringSearch arg with pos - not included', function (st) {
st.equals(includes('abc123def', 9, -Infinity), false);

@@ -95,17 +94,17 @@ st.equals(includes('abc123def', 9, -1), false);

st.equals(includes('abc123def', 9, 5), false);
st.equals(includes('abc123def', 9, +Infinity), false);
st.equals(includes('abc123def', 9, Number(Infinity)), false);
st.end();
});
t.test('regex searchString', function(st) {
t.test('regex searchString', function (st) {
st.equals(includes('foo[a-z]+(bar)?', '[a-z]+'), true);
st['throws'](function() { includes('foo[a-z]+(bar)?', /[a-z]+/); }, TypeError);
st['throws'](function() { includes('foo/[a-z]+/(bar)?', /[a-z]+/); }, TypeError);
st['throws'](function () { includes('foo[a-z]+(bar)?', /[a-z]+/); }, TypeError);
st['throws'](function () { includes('foo/[a-z]+/(bar)?', /[a-z]+/); }, TypeError);
st.equals(includes('foo[a-z]+(bar)?', '(bar)?'), true);
st['throws'](function() { includes('foo[a-z]+(bar)?', /(bar)?/); }, TypeError);
st['throws'](function() { includes('foo[a-z]+/(bar)?/', /(bar)?/); }, TypeError);
st['throws'](function () { includes('foo[a-z]+(bar)?', /(bar)?/); }, TypeError);
st['throws'](function () { includes('foo[a-z]+/(bar)?/', /(bar)?/); }, TypeError);
st.end();
});
t.test('astral symbols', function(st) {
t.test('astral symbols', function (st) {
// https://mathiasbynens.be/notes/javascript-unicode#poo-test

@@ -122,23 +121,23 @@ var string = 'I\xF1t\xEBrn\xE2ti\xF4n\xE0liz\xE6ti\xF8n\u2603\uD83D\uDCA9';

t.test('nullish this object', function(st) {
st['throws'](function() { includes(undefined); }, TypeError);
st['throws'](function() { includes(undefined, 'b'); }, TypeError);
st['throws'](function() { includes(undefined, 'b', 4); }, TypeError);
st['throws'](function() { includes(null); }, TypeError);
st['throws'](function() { includes(null, 'b'); }, TypeError);
st['throws'](function() { includes(null, 'b', 4); }, TypeError);
t.test('nullish this object', function (st) {
st['throws'](function () { includes(undefined); }, TypeError);
st['throws'](function () { includes(undefined, 'b'); }, TypeError);
st['throws'](function () { includes(undefined, 'b', 4); }, TypeError);
st['throws'](function () { includes(null); }, TypeError);
st['throws'](function () { includes(null, 'b'); }, TypeError);
st['throws'](function () { includes(null, 'b', 4); }, TypeError);
st.end();
});
t.test('cast this object', function(st) {
t.test('cast this object', function (st) {
st.equals(includes(42, '2'), true);
st.equals(includes(42, 'b', 4), false);
st.equals(includes(42, '2', 4), false);
st.equals(includes({ 'toString': function() { return 'abc'; } }, 'b', 0), true);
st.equals(includes({ 'toString': function() { return 'abc'; } }, 'b', 1), true);
st.equals(includes({ 'toString': function() { return 'abc'; } }, 'b', 2), false);
st['throws'](function() { includes({ 'toString': function() { throw RangeError(); } }, /./); }, RangeError);
st['throws'](function() { includes({ 'toString': function() { return 'abc'; } }, /./); }, TypeError);
st.equals(includes({ toString: function () { return 'abc'; } }, 'b', 0), true);
st.equals(includes({ toString: function () { return 'abc'; } }, 'b', 1), true);
st.equals(includes({ toString: function () { return 'abc'; } }, 'b', 2), false);
st['throws'](function () { includes({ toString: function () { throw new RangeError(); } }, /./); }, RangeError);
st['throws'](function () { includes({ toString: function () { return 'abc'; } }, /./); }, TypeError);
st.end();
});
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc