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

array.prototype.findindex

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array.prototype.findindex - npm Package Compare versions

Comparing version 2.1.1 to 2.2.0

.nycrc

6

CHANGELOG.md

@@ -0,1 +1,7 @@

# 2.2.0
- [New] `shim`/`auto`: add `findIndex` to `Symbol.unscopables`
- [Tests] migrate to tape
- [Deps] update `es-abstract`
- [Dev Deps] update `@ljharb/eslint-config`
# 2.1.1

@@ -2,0 +8,0 @@ - [Refactor] update implementation to match spec text

17

package.json
{
"name": "array.prototype.findindex",
"version": "2.1.1",
"version": "2.2.0",
"description": "Array.prototype.findIndex ES2015 polyfill.",

@@ -18,3 +18,3 @@ "keywords": [

"pretest": "npm run lint",
"tests-only": "mocha test",
"tests-only": "nyc tape 'test/**/*.js'",
"test": "npm run tests-only",

@@ -34,9 +34,11 @@ "posttest": "aud --production"

"@es-shims/api": "^2.2.3",
"@ljharb/eslint-config": "^20.2.3",
"@ljharb/eslint-config": "^21.0.0",
"aud": "^2.0.0",
"chai": "^3.5.0",
"eslint": "=8.8.0",
"functions-have-names": "^1.2.2",
"has-strict-mode": "^1.0.1",
"in-publish": "^2.0.1",
"mocha": "^2.4.5",
"safe-publish-latest": "^2.0.0"
"nyc": "^10.3.2",
"safe-publish-latest": "^2.0.0",
"tape": "^5.5.3"
},

@@ -46,4 +48,5 @@ "dependencies": {

"define-properties": "^1.1.3",
"es-abstract": "^1.19.2"
"es-abstract": "^1.19.4",
"es-shim-unscopables": "^1.0.0"
}
}
'use strict';
var define = require('define-properties');
var shimUnscopables = require('es-shim-unscopables');
var getPolyfill = require('./polyfill');

@@ -9,9 +11,15 @@

define(Array.prototype, { findIndex: polyfill }, {
findIndex: function () {
return Array.prototype.findIndex !== polyfill;
define(
Array.prototype,
{ findIndex: polyfill },
{
findIndex: function () {
return Array.prototype.findIndex !== polyfill;
}
}
});
);
shimUnscopables('findIndex');
return polyfill;
};

@@ -1,122 +0,17 @@

var expect = require('chai').expect;
var arrayFindIndex = require('../');
'use strict';
var runTests = function (findIndex) {
var list = [5, 10, 15, 20];
var keys = require('../');
var test = require('tape');
var runTests = require('./tests');
describe('Array#findIndex', function () {
it('should have a length of 1', function () {
expect(findIndex.length).to.equal(1);
});
it('should find item key by predicate', function () {
var result = findIndex.call(list, function (item) { return item === 15; });
expect(result).to.equal(2);
});
it('should return -1 when nothing matched', function () {
var result = findIndex.call(list, function (item) { return item === 'a'; });
expect(result).to.equal(-1);
});
it('should throw TypeError when function was not passed', function () {
expect(function () { list.findIndex(); }).to['throw'](TypeError);
});
it('should receive all three parameters', function () {
var i = findIndex.call(list, function (value, index, arr) {
expect(list[index]).to.equal(value);
expect(list).to.eql(arr);
return false;
});
expect(i).to.equal(-1);
});
it('should work with the context argument', function () {
var context = {};
findIndex.call([1], function () { expect(this).to.equal(context); }, context);
});
it('should work with an array-like object', function () {
var obj = { 0: 1, 1: 2, 2: 3, length: 3 };
var foundIndex = findIndex.call(obj, function (item) { return item === 2; });
expect(foundIndex).to.equal(1);
});
it('should work with an array-like object with negative length', function () {
var obj = { 0: 1, 1: 2, 2: 3, length: -3 };
var foundIndex = findIndex.call(obj, function () {
throw new Error('should not reach here');
});
expect(foundIndex).to.equal(-1);
});
it('should work with a sparse array', function () {
var obj = [1, , undefined]; // eslint-disable-line no-sparse-arrays
expect(1 in obj).to.equal(false);
var seen = [];
var foundIndex = findIndex.call(obj, function (item, idx) {
seen.push([idx, item]);
return item === undefined && idx === 2;
});
expect(foundIndex).to.equal(2);
expect(seen).to.eql([[0, 1], [1, undefined], [2, undefined]]);
});
it('should work with a sparse array-like object', function () {
var obj = { 0: 1, 2: undefined, length: 3.2 };
var seen = [];
var foundIndex = findIndex.call(obj, function (item, idx) {
seen.push([idx, item]);
return false;
});
expect(foundIndex).to.equal(-1);
expect(seen).to.eql([[0, 1], [1, undefined], [2, undefined]]);
});
test('as a function', function (t) {
t.test('bad array/this value', function (st) {
st['throws'](function () { keys(undefined); }, TypeError, 'undefined is not an object');
st['throws'](function () { keys(null); }, TypeError, 'null is not an object');
st.end();
});
};
describe('polyfill', function () {
describe('clean Object.prototype', function () {
runTests(arrayFindIndex.implementation);
});
runTests(keys, t);
describe('polluted Object.prototype', function () {
Object.prototype[1] = 42; // eslint-disable-line no-extend-native
runTests(arrayFindIndex.implementation);
delete Object.prototype[1];
});
t.end();
});
describe('shim', function () {
arrayFindIndex.shim();
var implementation = Array.prototype.findIndex;
describe('clean Object.prototype', function () {
runTests(implementation);
});
describe('polluted Object.prototype', function () {
Object.prototype[1] = 42; // eslint-disable-line no-extend-native
runTests(implementation);
delete Object.prototype[1];
});
});
describe('single function', function () {
var findIndexAsFunction = function (func) { // eslint-disable-line no-unused-vars
var args = Array.prototype.slice.call(arguments);
args.unshift(this);
return arrayFindIndex.apply(undefined, args);
};
describe('clean Object.prototype', function () {
runTests(findIndexAsFunction);
});
describe('polluted Object.prototype', function () {
Object.prototype[1] = 42; // eslint-disable-line no-extend-native
runTests(findIndexAsFunction);
delete Object.prototype[1];
});
});

Sorry, the diff of this file is not supported yet

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