jai shree ram
This commit is contained in:
8
node_modules/array.prototype.findindex/.editorconfig
generated
vendored
Normal file
8
node_modules/array.prototype.findindex/.editorconfig
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
charset = utf-8
|
||||
|
||||
[*.{js,json}]
|
||||
indent_style = tab
|
39
node_modules/array.prototype.findindex/.eslintrc
generated
vendored
Normal file
39
node_modules/array.prototype.findindex/.eslintrc
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"root": true,
|
||||
|
||||
"extends": "@ljharb",
|
||||
|
||||
"rules": {
|
||||
"array-bracket-newline": 0,
|
||||
"id-length": [2, { "min": 1, "max": 25, "properties": "never" }],
|
||||
"max-statements": [2, 14],
|
||||
"max-statements-per-line": [2, { "max": 2 }],
|
||||
"max-params": 0,
|
||||
"multiline-comment-style": 0,
|
||||
"new-cap": [2, {
|
||||
"capIsNewExceptions": [
|
||||
"Call",
|
||||
"Get",
|
||||
"IsCallable",
|
||||
"LengthOfArrayLike",
|
||||
"RequireObjectCoercible",
|
||||
"ToBoolean",
|
||||
"ToObject",
|
||||
"ToString",
|
||||
],
|
||||
}],
|
||||
"no-magic-numbers": 0,
|
||||
"object-curly-newline": 0,
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"files": "test/**",
|
||||
"rules": {
|
||||
"id-length": 0,
|
||||
"max-lines-per-function": 0,
|
||||
"no-invalid-this": 0,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
12
node_modules/array.prototype.findindex/.github/FUNDING.yml
generated
vendored
Normal file
12
node_modules/array.prototype.findindex/.github/FUNDING.yml
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: [ljharb]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: npm/array.prototype.findindex
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
9
node_modules/array.prototype.findindex/.nycrc
generated
vendored
Normal file
9
node_modules/array.prototype.findindex/.nycrc
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"all": true,
|
||||
"check-coverage": false,
|
||||
"reporter": ["text-summary", "text", "html", "json"],
|
||||
"exclude": [
|
||||
"coverage",
|
||||
"test"
|
||||
]
|
||||
}
|
54
node_modules/array.prototype.findindex/CHANGELOG.md
generated
vendored
Normal file
54
node_modules/array.prototype.findindex/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
# 2.2.1
|
||||
- [Deps] update `define-properties`, `es-abstract`
|
||||
- [meta] use `npmignore` to autogenerate an npmignore file
|
||||
- [actions] update rebase action to use reusable workflow
|
||||
- [Dev Deps] update `aud`, `functions-have-names`, `tape`
|
||||
|
||||
# 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
|
||||
- [Refactor] update implementation to match spec text
|
||||
- [meta] add `safe-publish-latest`
|
||||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `@es-shims/api`
|
||||
- [Tests] migrate tests to Github Actions
|
||||
|
||||
# 2.1.0
|
||||
- [New] add `auto` entry point
|
||||
- [Fix] remove `detect` file, broken/unused in v2
|
||||
- [Refactor] use split-up `es-abstract` (77% bundle size decrease)
|
||||
- [Performance] avoid checking `arguments` indexes beyond `arguments.length`
|
||||
- [Performance] inline `ES.Call` since `IsCallable` is already checked prior to the loop.
|
||||
- [Deps] update `define-properties`
|
||||
- [meta] Only apps should have lockfiles
|
||||
- [meta] add missing LICENSE file
|
||||
- [Tests] add `npm run lint`
|
||||
- [Tests] use shared travis-ci configs
|
||||
- [Tests] use `aud` in posttest
|
||||
|
||||
# 2.0.2
|
||||
- [Performance] the entry point should use the native function when compliant
|
||||
|
||||
# 2.0.1
|
||||
- [Fix] use call instead of apply in bound entry point function (#17)
|
||||
- [Refactor] Remove unnecessary double ToLength call (#16)
|
||||
- [Tests] run tests on travis-ci
|
||||
|
||||
# 2.0.0
|
||||
- [Breaking] use es-shim API (#13)
|
||||
- [Docs] fix example in README (#9)
|
||||
- [Docs] Fix npm install command in README (#7)
|
||||
|
||||
# 1.0.0
|
||||
- [Fix] do not skip holes, per ES6 change (#4)
|
||||
- [Fix] Older browsers report the typeof some host objects and regexes as "function" (#5)
|
||||
|
||||
# 0.1.1
|
||||
- [Fix] Support IE8 by wrapping Object.defineProperty with a try catch (#3)
|
||||
- [Refactor] remove redundant enumerable: false (#1)
|
||||
|
||||
# 0.1.0
|
||||
- Initial release.
|
21
node_modules/array.prototype.findindex/LICENSE
generated
vendored
Normal file
21
node_modules/array.prototype.findindex/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2013 Paul Miller, Jordan Harband, and contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
57
node_modules/array.prototype.findindex/README.md
generated
vendored
Normal file
57
node_modules/array.prototype.findindex/README.md
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
# ES6 `Array.prototype.findIndex` polyfill
|
||||
|
||||
Simple ES6 [Array.prototype.findIndex](http://people.mozilla.org/%7Ejorendorff/es6-draft.html#sec-array.prototype.findindex) polyfill for older environments taken from [es6-shim](https://github.com/paulmillr/es6-shim).
|
||||
|
||||
For browsers and node.js.
|
||||
|
||||
## Installation
|
||||
* Just include repo before your scripts.
|
||||
* `npm install array.prototype.findindex` if you’re using node.js.
|
||||
* `component install paulmillr/Array.prototype.findIndex` if you’re using [component(1)](https://github.com/component/component).
|
||||
* `bower install Array.prototype.findIndex` if you’re using [Twitter Bower](http://bower.io).
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
* `Array.prototype.findIndex(predicate[, thisArg])` returns first item index that matches `predicate` function.
|
||||
* `predicate(value, index, collection)`: takes three arguments
|
||||
* `value`: current collection element
|
||||
* `index`: current collection element index
|
||||
* `collection`: the collection
|
||||
|
||||
```javascript
|
||||
var findIndex = require('array.prototype.findindex');
|
||||
|
||||
findIndex.shim(); // if you want to install it on the global environment
|
||||
```
|
||||
|
||||
Code example:
|
||||
|
||||
```javascript
|
||||
// Default:
|
||||
[1, 5, 10, 15].findIndex(function(a) {return a > 9;}) // 2
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Paul Miller <http://paulmillr.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the “Software”), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
3
node_modules/array.prototype.findindex/auto.js
generated
vendored
Normal file
3
node_modules/array.prototype.findindex/auto.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
require('./shim')();
|
32
node_modules/array.prototype.findindex/implementation.js
generated
vendored
Normal file
32
node_modules/array.prototype.findindex/implementation.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
var Call = require('es-abstract/2022/Call');
|
||||
var Get = require('es-abstract/2022/Get');
|
||||
var IsCallable = require('es-abstract/2022/IsCallable');
|
||||
var LengthOfArrayLike = require('es-abstract/2022/LengthOfArrayLike');
|
||||
var ToBoolean = require('es-abstract/2022/ToBoolean');
|
||||
var ToObject = require('es-abstract/2022/ToObject');
|
||||
var ToString = require('es-abstract/2022/ToString');
|
||||
|
||||
module.exports = function findIndex(predicate) {
|
||||
var O = ToObject(this);
|
||||
var len = LengthOfArrayLike(O);
|
||||
if (!IsCallable(predicate)) {
|
||||
throw new TypeError('Array#findIndex: predicate must be a function');
|
||||
}
|
||||
|
||||
var thisArg = arguments.length > 1 ? arguments[1] : void undefined;
|
||||
|
||||
var k = 0;
|
||||
while (k < len) {
|
||||
var Pk = ToString(k);
|
||||
var kValue = Get(O, Pk);
|
||||
var testResult = ToBoolean(Call(predicate, thisArg, [kValue, k, O]));
|
||||
if (testResult) {
|
||||
return k;
|
||||
}
|
||||
k += 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
};
|
28
node_modules/array.prototype.findindex/index.js
generated
vendored
Normal file
28
node_modules/array.prototype.findindex/index.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
var define = require('define-properties');
|
||||
var RequireObjectCoercible = require('es-abstract/2022/RequireObjectCoercible');
|
||||
var callBind = require('call-bind');
|
||||
var callBound = require('call-bind/callBound');
|
||||
|
||||
var implementation = require('./implementation');
|
||||
var getPolyfill = require('./polyfill');
|
||||
var shim = require('./shim');
|
||||
|
||||
var $slice = callBound('Array.prototype.slice');
|
||||
|
||||
var polyfill = callBind.apply(getPolyfill());
|
||||
|
||||
var boundShim = function findIndex(array, predicate) { // eslint-disable-line no-unused-vars
|
||||
RequireObjectCoercible(array);
|
||||
var args = $slice(arguments, 1);
|
||||
return polyfill(array, args);
|
||||
};
|
||||
|
||||
define(boundShim, {
|
||||
getPolyfill: getPolyfill,
|
||||
implementation: implementation,
|
||||
shim: shim
|
||||
});
|
||||
|
||||
module.exports = boundShim;
|
56
node_modules/array.prototype.findindex/package.json
generated
vendored
Normal file
56
node_modules/array.prototype.findindex/package.json
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"name": "array.prototype.findindex",
|
||||
"version": "2.2.1",
|
||||
"description": "Array.prototype.findIndex ES2015 polyfill.",
|
||||
"keywords": [
|
||||
"Array.prototype.findIndex",
|
||||
"findIndex",
|
||||
"es6",
|
||||
"es2015"
|
||||
],
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"prepack": "npmignore --auto --commentLines=autogenerated",
|
||||
"prepublishOnly": "safe-publish-latest",
|
||||
"prepublish": "not-in-publish || npm run prepublishOnly",
|
||||
"prelint": "es-shim-api --bound",
|
||||
"lint": "eslint --ext=js,mjs .",
|
||||
"pretest": "npm run lint",
|
||||
"tests-only": "nyc tape 'test/**/*.js'",
|
||||
"test": "npm run tests-only",
|
||||
"posttest": "aud --production"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/paulmillr/Array.prototype.findIndex.git"
|
||||
},
|
||||
"author": "Paul Miller <http://paulmillr.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/paulmillr/Array.prototype.findIndex/issues"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@es-shims/api": "^2.2.3",
|
||||
"@ljharb/eslint-config": "^21.0.0",
|
||||
"aud": "^2.0.1",
|
||||
"eslint": "=8.8.0",
|
||||
"functions-have-names": "^1.2.3",
|
||||
"has-strict-mode": "^1.0.1",
|
||||
"in-publish": "^2.0.1",
|
||||
"npmignore": "^0.3.0",
|
||||
"nyc": "^10.3.2",
|
||||
"safe-publish-latest": "^2.0.0",
|
||||
"tape": "^5.6.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"call-bind": "^1.0.2",
|
||||
"define-properties": "^1.1.4",
|
||||
"es-abstract": "^1.20.4",
|
||||
"es-shim-unscopables": "^1.0.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"ignore": [
|
||||
".github/workflows"
|
||||
]
|
||||
}
|
||||
}
|
14
node_modules/array.prototype.findindex/polyfill.js
generated
vendored
Normal file
14
node_modules/array.prototype.findindex/polyfill.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var implementation = require('./implementation');
|
||||
|
||||
module.exports = function getPolyfill() {
|
||||
// Detect if an implementation exists
|
||||
// Detect early implementations which skipped holes in sparse arrays
|
||||
// eslint-disable-next-line no-sparse-arrays
|
||||
var implemented = Array.prototype.findIndex && ([, 1].findIndex(function (item, idx) {
|
||||
return idx === 0;
|
||||
}) === 0);
|
||||
|
||||
return implemented ? Array.prototype.findIndex : implementation;
|
||||
};
|
24
node_modules/array.prototype.findindex/shim.js
generated
vendored
Normal file
24
node_modules/array.prototype.findindex/shim.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
var define = require('define-properties');
|
||||
var shimUnscopables = require('es-shim-unscopables');
|
||||
|
||||
var getPolyfill = require('./polyfill');
|
||||
|
||||
module.exports = function shimFindIndex() {
|
||||
var polyfill = getPolyfill();
|
||||
|
||||
define(
|
||||
Array.prototype,
|
||||
{ findIndex: polyfill },
|
||||
{
|
||||
findIndex: function () {
|
||||
return Array.prototype.findIndex !== polyfill;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
shimUnscopables('findIndex');
|
||||
|
||||
return polyfill;
|
||||
};
|
20
node_modules/array.prototype.findindex/test/implementation.js
generated
vendored
Normal file
20
node_modules/array.prototype.findindex/test/implementation.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
var keys = require('../implementation');
|
||||
var callBind = require('call-bind');
|
||||
var test = require('tape');
|
||||
var hasStrictMode = require('has-strict-mode')();
|
||||
var runTests = require('./tests');
|
||||
|
||||
test('as a function', function (t) {
|
||||
t.test('bad array/this value', { skip: !hasStrictMode }, function (st) {
|
||||
/* eslint no-useless-call: 0 */
|
||||
st['throws'](function () { keys.call(undefined); }, TypeError, 'undefined is not an object');
|
||||
st['throws'](function () { keys.call(null); }, TypeError, 'null is not an object');
|
||||
st.end();
|
||||
});
|
||||
|
||||
runTests(callBind(keys), t);
|
||||
|
||||
t.end();
|
||||
});
|
17
node_modules/array.prototype.findindex/test/index.js
generated
vendored
Normal file
17
node_modules/array.prototype.findindex/test/index.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
var keys = require('../');
|
||||
var test = require('tape');
|
||||
var runTests = require('./tests');
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
runTests(keys, t);
|
||||
|
||||
t.end();
|
||||
});
|
31
node_modules/array.prototype.findindex/test/index.mjs
generated
vendored
Normal file
31
node_modules/array.prototype.findindex/test/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import keys from 'array.prototype.keys';
|
||||
import * as keysModule from 'array.prototype.keys';
|
||||
import test from 'tape';
|
||||
import runTests from './tests.js';
|
||||
|
||||
test('as a function', (t) => {
|
||||
t.test('bad array/this value', (st) => {
|
||||
st.throws(() => keys(undefined), TypeError, 'undefined is not an object');
|
||||
st.throws(() => keys(null), TypeError, 'null is not an object');
|
||||
st.end();
|
||||
});
|
||||
|
||||
runTests(keys, t);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('named exports', async (t) => {
|
||||
t.deepEqual(
|
||||
Object.keys(keysModule).sort(),
|
||||
['default', 'shim', 'getPolyfill', 'implementation'].sort(),
|
||||
'has expected named exports',
|
||||
);
|
||||
|
||||
const { shim, getPolyfill, implementation } = keysModule;
|
||||
t.equal((await import('array.prototype.keys/shim')).default, shim, 'shim named export matches deep export');
|
||||
t.equal((await import('array.prototype.keys/implementation')).default, implementation, 'implementation named export matches deep export');
|
||||
t.equal((await import('array.prototype.keys/polyfill')).default, getPolyfill, 'getPolyfill named export matches deep export');
|
||||
|
||||
t.end();
|
||||
});
|
36
node_modules/array.prototype.findindex/test/shimmed.js
generated
vendored
Normal file
36
node_modules/array.prototype.findindex/test/shimmed.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
require('../auto');
|
||||
|
||||
var test = require('tape');
|
||||
var defineProperties = require('define-properties');
|
||||
var callBind = require('call-bind');
|
||||
|
||||
var isEnumerable = Object.prototype.propertyIsEnumerable;
|
||||
var functionsHaveNames = require('functions-have-names')();
|
||||
var hasStrictMode = require('has-strict-mode')();
|
||||
|
||||
var runTests = require('./tests');
|
||||
|
||||
test('shimmed', function (t) {
|
||||
t.equal(Array.prototype.findIndex.length, 1, 'Array#findIndex has a length of 1');
|
||||
t.test('Function name', { skip: !functionsHaveNames }, function (st) {
|
||||
st.equal(Array.prototype.findIndex.name, 'findIndex', 'Array#findIndex has name "findIndex"');
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
|
||||
et.equal(false, isEnumerable.call(Array.prototype, 'findIndex'), 'Array#findIndex is not enumerable');
|
||||
et.end();
|
||||
});
|
||||
|
||||
t.test('bad array/this value', { skip: !hasStrictMode }, function (st) {
|
||||
st['throws'](function () { return Array.prototype.findIndex.call(undefined); }, TypeError, 'undefined is not an object');
|
||||
st['throws'](function () { return Array.prototype.findIndex.call(null); }, TypeError, 'null is not an object');
|
||||
st.end();
|
||||
});
|
||||
|
||||
runTests(callBind(Array.prototype.findIndex), t);
|
||||
|
||||
t.end();
|
||||
});
|
82
node_modules/array.prototype.findindex/test/tests.js
generated
vendored
Normal file
82
node_modules/array.prototype.findindex/test/tests.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
'use strict';
|
||||
|
||||
var canDistinguishSparseFromUndefined = 0 in [undefined]; // IE 6 - 8 have a bug where this returns false.
|
||||
|
||||
var thrower = function () {
|
||||
throw new Error('should not reach here');
|
||||
};
|
||||
|
||||
module.exports = function (findIndex, t) {
|
||||
var list = [5, 10, 15, 20];
|
||||
|
||||
t.equal(
|
||||
findIndex(list, function (item) { return item === 15; }),
|
||||
2,
|
||||
'find index by predicate'
|
||||
);
|
||||
t.equal(
|
||||
findIndex(list, function (item) { return item === 'a'; }),
|
||||
-1,
|
||||
'returns -1 when nothing matches'
|
||||
);
|
||||
t['throws'](
|
||||
function () { findIndex(list); },
|
||||
TypeError,
|
||||
'throws without callback'
|
||||
);
|
||||
|
||||
var context = {};
|
||||
var foundIndex = findIndex(list, function (value, index, arr) {
|
||||
t.equal(list[index], value);
|
||||
t.deepEqual(list, arr);
|
||||
t.equal(this, context, 'receiver is as expected');
|
||||
return false;
|
||||
}, context);
|
||||
t.equal(foundIndex, -1, 'receives all three arguments');
|
||||
|
||||
var arraylike = { 0: 1, 1: 2, 2: 3, length: 3 };
|
||||
t.equal(
|
||||
findIndex(arraylike, function (item) {
|
||||
return item === 2;
|
||||
}),
|
||||
1,
|
||||
'works with an array-like object'
|
||||
);
|
||||
|
||||
t.equal(
|
||||
findIndex({ 0: 1, 1: 2, 2: 3, length: -3 }, thrower),
|
||||
-1,
|
||||
'works with an array-like object with negative length'
|
||||
);
|
||||
|
||||
t.test('sparse arrays', { skip: !canDistinguishSparseFromUndefined }, function (st) {
|
||||
st.test('works with a sparse array', function (s2t) {
|
||||
var obj = [1, , undefined]; // eslint-disable-line no-sparse-arrays
|
||||
s2t.notOk(1 in obj);
|
||||
var seen = [];
|
||||
var foundSparse = findIndex(obj, function (item, idx) {
|
||||
seen.push([idx, item]);
|
||||
return false;
|
||||
});
|
||||
s2t.equal(foundSparse, -1);
|
||||
s2t.deepEqual(seen, [[0, 1], [1, undefined], [2, undefined]]);
|
||||
|
||||
s2t.end();
|
||||
});
|
||||
|
||||
st.test('works with a sparse array-like object', function (s2t) {
|
||||
var obj = { 0: 1, 2: undefined, length: 3.2 };
|
||||
var seen = [];
|
||||
var foundSparse = findIndex(obj, function (item, idx) {
|
||||
seen.push([idx, item]);
|
||||
return false;
|
||||
});
|
||||
s2t.equal(foundSparse, -1);
|
||||
s2t.deepEqual(seen, [[0, 1], [1, undefined], [2, undefined]]);
|
||||
|
||||
s2t.end();
|
||||
});
|
||||
|
||||
st.end();
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user