main repo

This commit is contained in:
Basilosaurusrex
2025-11-24 18:09:40 +01:00
parent b636ee5e70
commit f027651f9b
34146 changed files with 4436636 additions and 0 deletions

36
node_modules/array.prototype.findlastindex/.eslintrc generated vendored Normal file
View File

@@ -0,0 +1,36 @@
{
"root": true,
"extends": "@ljharb",
"rules": {
"array-bracket-newline": 0,
"id-length": 0,
"new-cap": [2, {
"capIsNewExceptions": [
"GetIntrinsic",
"Call",
"Get",
"IsCallable",
"LengthOfArrayLike",
"RequireObjectCoercible",
"ToBoolean",
"ToObject",
"ToString",
],
}],
"no-magic-numbers": 0,
},
"overrides": [
{
"files": "test/**",
"rules": {
"func-name-matching": 0,
"max-lines-per-function": 0,
"no-invalid-this": 1,
"strict": 1,
},
},
],
}

View 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.findlastindex
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.findlastindex/.nycrc generated vendored Normal file
View File

@@ -0,0 +1,9 @@
{
"all": true,
"check-coverage": false,
"reporter": ["text-summary", "text", "html", "json"],
"exclude": [
"coverage",
"test"
]
}

View File

@@ -0,0 +1,95 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.2.5](https://github.com/es-shims/Array.prototype.findLastIndex/compare/v1.2.4...v1.2.5) - 2024-03-19
### Commits
- [meta] remove useless ESM [`4ed36ab`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/4ed36ab7bde25f3b265a2769163409a939d9a4de)
- [Deps] update `call-bind`, `es-abstract` [`a6e3816`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/a6e38162c958d3a54c73094a84fd27e9e48992d3)
- [Refactor] use `es-object-atoms` where possible [`3fbee9b`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/3fbee9b07d97a472b59204360620a491ff1f3cdd)
- [Dev Deps] update `hasown`, `tape` [`dc6356c`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/dc6356c69902912aa1eaee0f5677c6c64fb8ee11)
## [v1.2.4](https://github.com/es-shims/Array.prototype.findLastIndex/compare/v1.2.3...v1.2.4) - 2024-02-05
### Commits
- [Deps] update `call-bind`, `define-properties`, `es-abstract`, `es-shim-unscopables`, `get-intrinsic` [`b689455`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/b689455f6194d84d929bd678755a175aa63b1b37)
- [Refactor] use `es-errors`, so things that only need those do not need `get-intrinsic` [`ca636e6`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/ca636e60abae73755c613117f9a8eccb49a32f48)
- [Tests] use `functions-have-names` [`b91692c`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/b91692c2a695c0065805fcb4f6b6f081d27852c8)
- [Dev Deps] update `aud`, `npmignore`, `tape` [`4f87dff`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/4f87dff212fd5f0b05bdd412e669b4536e8b06f9)
- [Dev Deps] use `hasown` instead of `has` [`57ce292`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/57ce2920dc645c3dec27b3aa8bcbfff9b0bfd135)
- [Dev Deps] update `object-inspect`, `tape` [`fa74bab`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/fa74babe7cf90ec07b8c12c3ab10e89b7093e0b4)
## [v1.2.3](https://github.com/es-shims/Array.prototype.findLastIndex/compare/v1.2.2...v1.2.3) - 2023-08-29
### Commits
- [Deps] update `define-properties`, `es-abstract`, `get-intrinsic` [`27e8133`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/27e8133ccdccab46896da19cd26e3147691a77eb)
- [Tests] add passing test262 test [`678edb3`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/678edb3bc91b10298b4e72a5e471b1aa41f915dc)
- [Dev Deps] update `@es-shims/api`, `@ljharb/eslint-config`, `aud`, `object-inspect`, `tape` [`47abe8b`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/47abe8b2cc14ee1b9f4b785a9aa26947ba20305a)
- [Tests] use `globalthis` [`0cf9142`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/0cf914237811822d9d5268a057c0c9a108b8e5c0)
## [v1.2.2](https://github.com/es-shims/Array.prototype.findLastIndex/compare/v1.2.1...v1.2.2) - 2022-11-02
### Commits
- [meta] use `npmignore` to autogenerate an npmignore file [`f910dc6`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/f910dc6e5999e6941892232810ae9b3910d925ec)
- [Deps] update `es-abstract`, `get-intrinsic` [`6e44207`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/6e4420705d7435b8b9bb978e4858814ba0216fa5)
- [actions] update rebase action to use reusable workflow [`aac0471`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/aac0471a0b2f0f44765ac6055211b58f26fa6636)
- [Deps] update `define-properties`, `es-abstract`, `get-intrinsic` [`c1d1d70`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/c1d1d7083bfa8ab32a9e5560e4b2aa16ce9d0a6d)
- [Dev Deps] update `es-value-fixtures`, `object-inspect`, `tape` [`64c4c0f`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/64c4c0f6dda4793c5d9db5110ec82c6004bcc4ef)
- [Dev Deps] update `aud`, `tape` [`603fbac`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/603fbacf4d034298ff40ab6886f6af7031651acd)
- [Tests] add indication of whether it was shimmed [`7d711f6`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/7d711f6e68c9c5e4e0556946d026c159f7d82f22)
- [Tests] make nullish receiver tests more robust [`335cf53`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/335cf5381ec0bc7ce60de8824b736cb3b40918ae)
## [v1.2.1](https://github.com/es-shims/Array.prototype.findLastIndex/compare/v1.2.0...v1.2.1) - 2022-04-11
### Commits
- [Refactor] use `es-shim-unscopables` [`abe84ee`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/abe84ee8794ce9c84180bc01cf499a7bb2494b3d)
## [v1.2.0](https://github.com/es-shims/Array.prototype.findLastIndex/compare/v1.1.1...v1.2.0) - 2022-04-11
### Commits
- [actions] reuse common workflows [`670cc4c`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/670cc4c0b6f23b7f01d365a9afd2dd88ee2e4967)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `@es-shims/api`, `object-inspect`, `safe-publish-latest`, `tape` [`11bc460`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/11bc460ab842d2a08c43b67aab182e0697d65308)
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `auto-changelog`, `object-inspect`, `tape` [`b076ad6`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/b076ad6ed9246f3139efa72d0ddbf2e0d861f982)
- [actions] update codecov uploader [`0d62d86`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/0d62d8602c2d3ecefdd0965c25cafb2a864c0903)
- [New] `shim`/`auto`: add `findLast` to `Symbol.unscopables` [`b09e4a6`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/b09e4a6a194366b45945c6d65cdcc64ca786e570)
- [Deps] update `es-abstract` [`024128c`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/024128c1abc5b58863859ea8b9cf4c1cb1df548b)
- [Deps] update `es-abstract` [`2dcab99`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/2dcab99e3ed43546cd6610b12d489d95d8e94d90)
## [v1.1.1](https://github.com/es-shims/Array.prototype.findLastIndex/compare/v1.1.0...v1.1.1) - 2021-10-01
### Commits
- [Refactor] remove unnecessary ESM files [`35161c7`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/35161c76758835dd3fbecdf0b5fbf41a3ce9f218)
- [Tests] add new tests from test262 [`e26fa25`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/e26fa256601f60b1feb5918e4fbcc76d0d773d13)
- [Deps] update `es-abstract` [`5ff80b1`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/5ff80b116f2e083ae72605275af0efec367f3a89)
- [readme] fix URLs [`b962fe2`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/b962fe225fac8a450624d861b5d6e444526bcf32)
- [Dev Deps] update `@ljharb/eslint-config`, `@es-shims/api` [`5aa11dd`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/5aa11dd23ee2bcdc9ca7d2d6007e7f44a9356743)
## [v1.1.0](https://github.com/es-shims/Array.prototype.findLastIndex/compare/v1.0.0...v1.1.0) - 2021-08-07
### Commits
- [New] add ESM entry points [`ac5ada3`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/ac5ada3d359ff267e6933dd817f4106e6de2c157)
- [Fix] ES3 engines: ensure nullish receiver throws [`4c6592a`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/4c6592a7962351e82bb1b06c79de496bf4bcd08d)
- [Dev Deps] update `eslint`, `@tape` [`6895166`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/6895166742a738a80d19ac4eaa6f12c97a5c7814)
- [Fix] add missing entry points to `exports` [`ac2f138`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/ac2f1384dcd9a9f736ce1c3c5dc7ac87e16c4f90)
- [Deps] update `es-abstract` [`c379fb7`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/c379fb7681ea3bb078891bf394756b1086bc43e7)
## v1.0.0 - 2021-07-13
### Commits
- Implementation & Tests [`cf5cae1`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/cf5cae1d78c0c74588a5baade5156950e17f4558)
- Initial commit [`2778f1c`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/2778f1cc708cc79d3bdbc20d5b84d210b9670b8a)
- npm init [`873482d`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/873482d650b6800e9484865c3b0d6d33664bcf9e)
- Only apps should have lockfiles [`b7c73ee`](https://github.com/es-shims/Array.prototype.findLastIndex/commit/b7c73ee858f01b0b1ff70800e09c0bbc2632e1a5)

21
node_modules/array.prototype.findlastindex/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 ECMAScript Shims
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.

74
node_modules/array.prototype.findlastindex/README.md generated vendored Normal file
View File

@@ -0,0 +1,74 @@
# array.prototype.findlastindex <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![dependency status][deps-svg]][deps-url]
[![dev dependency status][dev-deps-svg]][dev-deps-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![npm badge][npm-badge-png]][package-url]
An ESnext spec-compliant `Array.prototype.findLastIndex` shim/polyfill/replacement that works as far down as ES3.
This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment and complies with the proposed [spec](https://tc39.es/proposal-array-find-from-last).
Because `Array.prototype.findLastIndex` depends on a receiver (the `this` value), the main export takes the array to operate on as the first argument.
## Getting started
```sh
npm install --save array.prototype.findlastindex
```
## Usage/Examples
```js
var findLastIndex = require('array.prototype.findlastindex');
var assert = require('assert');
var arr = [1, [2], [], 3, [[4]]];
var isNumber = function (x) { return typeof x === 'number' };
assert.deepEqual(findLastIndex(arr, isNumber), 3);
```
```js
var findLastIndex = require('array.prototype.findlastindex');
var assert = require('assert');
/* when Array#findLastIndex is not present */
delete Array.prototype.findLastIndex;
var shimmed = findLastIndex.shim();
assert.equal(shimmed, findLastIndex.getPolyfill());
assert.deepEqual(arr.findLastIndex(isNumber), findLastIndex(arr, isNumber));
```
```js
var findLastIndex = require('array.prototype.findlastindex');
var assert = require('assert');
/* when Array#findLastIndex is present */
var shimmed = findLastIndex.shim();
assert.equal(shimmed, Array.prototype.findLastIndex);
assert.deepEqual(arr.findLastIndex(isNumber), findLastIndex(arr, isNumber));
```
## Tests
Simply clone the repo, `npm install`, and run `npm test`
[package-url]: https://npmjs.org/package/array.prototype.findlastindex
[npm-version-svg]: https://versionbadg.es/es-shims/Array.prototype.findLastIndex.svg
[deps-svg]: https://david-dm.org/es-shims/Array.prototype.findLastIndex.svg
[deps-url]: https://david-dm.org/es-shims/Array.prototype.findLastIndex
[dev-deps-svg]: https://david-dm.org/es-shims/Array.prototype.findLastIndex/dev-status.svg
[dev-deps-url]: https://david-dm.org/es-shims/Array.prototype.findLastIndex#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/array.prototype.findlastindex.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/array.prototype.findlastindex.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/array.prototype.findlastindex.svg
[downloads-url]: https://npm-stat.com/charts.html?package=array.prototype.findlastindex
[codecov-image]: https://codecov.io/gh/es-shims/Array.prototype.findLastIndex/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/es-shims/Array.prototype.findLastIndex/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/Array.prototype.findLastIndex
[actions-url]: https://github.com/es-shims/Array.prototype.findLastIndex

3
node_modules/array.prototype.findlastindex/auto.js generated vendored Normal file
View File

@@ -0,0 +1,3 @@
'use strict';
require('./shim')();

View File

@@ -0,0 +1,38 @@
'use strict';
var $TypeError = require('es-errors/type');
var Call = require('es-abstract/2024/Call');
var Get = require('es-abstract/2024/Get');
var IsCallable = require('es-abstract/2024/IsCallable');
var LengthOfArrayLike = require('es-abstract/2024/LengthOfArrayLike');
var ToBoolean = require('es-abstract/2024/ToBoolean');
var ToObject = require('es-object-atoms/ToObject');
var ToString = require('es-abstract/2024/ToString');
module.exports = function findLastIndex(predicate) {
var O = ToObject(this);
var len = LengthOfArrayLike(O);
if (!IsCallable(predicate)) {
throw new $TypeError('predicate must be a function');
}
var thisArg;
if (arguments.length > 1) {
thisArg = arguments[1];
}
var k = len - 1;
while (k >= 0) {
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.findlastindex/index.js generated vendored Normal file
View File

@@ -0,0 +1,28 @@
'use strict';
var define = require('define-properties');
var callBind = require('call-bind');
var callBound = require('call-bind/callBound');
var RequireObjectCoercible = require('es-object-atoms/RequireObjectCoercible');
var implementation = require('./implementation');
var getPolyfill = require('./polyfill');
var polyfill = getPolyfill();
var shim = require('./shim');
var $slice = callBound('Array.prototype.slice');
var bound = callBind.apply(polyfill);
// eslint-disable-next-line no-unused-vars
var boundFindLast = function findLastIndex(array, predicate) {
RequireObjectCoercible(array);
return bound(array, $slice(arguments, 1));
};
define(boundFindLast, {
getPolyfill: getPolyfill,
implementation: implementation,
shim: shim
});
module.exports = boundFindLast;

114
node_modules/array.prototype.findlastindex/package.json generated vendored Normal file
View File

@@ -0,0 +1,114 @@
{
"name": "array.prototype.findlastindex",
"version": "1.2.5",
"description": "An ESnext spec-compliant `Array.prototype.findLastIndex` shim/polyfill/replacement that works as far down as ES3.",
"author": {
"name": "Jordan Harband",
"email": "ljharb@gmail.com",
"url": "http://ljharb.codes"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"contributors": [
{
"name": "Jordan Harband",
"email": "ljharb@gmail.com",
"url": "http://ljharb.codes"
}
],
"license": "MIT",
"bugs": {
"url": "https://github.com/es-shims/Array.prototype.findLastIndex/issues"
},
"homepage": "https://github.com/es-shims/Array.prototype.findLastIndex#readme",
"main": "index.js",
"exports": {
".": "./index.js",
"./auto": "./auto.js",
"./polyfill": "./polyfill.js",
"./implementation": "./implementation.js",
"./shim": "./shim.js",
"./package.json": "./package.json"
},
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"prepublishOnly": "safe-publish-latest",
"prepublish": "not-in-publish || npm run prepublishOnly",
"pretest": "npm run --silent lint",
"posttest": "aud --production",
"tests-only": "nyc tape 'test/**/*.js'",
"test": "npm run tests-only",
"prelint": "evalmd README.md",
"lint": "eslint --ext=js,mjs .",
"postlint": "es-shim-api --bound",
"version": "auto-changelog && git add CHANGELOG.md",
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
},
"repository": {
"type": "git",
"url": "git+https://github.com/es-shims/Array.prototype.findLastIndex.git"
},
"keywords": [
"Array.prototype.findLastIndex",
"find",
"findLast",
"findLastIndex",
"array",
"ESnext",
"shim",
"polyfill",
"last",
"es-shim API"
],
"dependencies": {
"call-bind": "^1.0.7",
"define-properties": "^1.2.1",
"es-abstract": "^1.23.2",
"es-errors": "^1.3.0",
"es-object-atoms": "^1.0.0",
"es-shim-unscopables": "^1.0.2"
},
"devDependencies": {
"@es-shims/api": "^2.4.2",
"@ljharb/eslint-config": "^21.1.0",
"aud": "^2.0.4",
"auto-changelog": "^2.4.0",
"es-value-fixtures": "^1.4.2",
"eslint": "=8.8.0",
"evalmd": "^0.0.19",
"for-each": "^0.3.3",
"functions-have-names": "^1.2.3",
"globalthis": "^1.0.3",
"has-strict-mode": "^1.0.1",
"hasown": "^2.0.2",
"in-publish": "^2.0.1",
"npmignore": "^0.3.1",
"nyc": "^10.3.2",
"object-inspect": "^1.13.1",
"safe-publish-latest": "^2.0.0",
"tape": "^5.7.5"
},
"testling": {
"files": [
"test/index.js",
"test/shimmed.js"
]
},
"engines": {
"node": ">= 0.4"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
},
"publishConfig": {
"ignore": [
".github/workflows"
]
}
}

View File

@@ -0,0 +1,7 @@
'use strict';
var implementation = require('./implementation');
module.exports = function getPolyfill() {
return Array.prototype.findLastIndex || implementation;
};

18
node_modules/array.prototype.findlastindex/shim.js generated vendored Normal file
View File

@@ -0,0 +1,18 @@
'use strict';
var define = require('define-properties');
var getPolyfill = require('./polyfill');
var shimUnscopables = require('es-shim-unscopables');
module.exports = function shimFindLastIndex() {
var polyfill = getPolyfill();
define(
Array.prototype,
{ findLastIndex: polyfill },
{ findLastIndex: function () { return Array.prototype.findLastIndex !== polyfill; } }
);
shimUnscopables('findLastIndex');
return polyfill;
};

View File

@@ -0,0 +1,20 @@
'use strict';
var implementation = 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 () { implementation.call(undefined); }, TypeError, 'undefined is not an object');
st['throws'](function () { implementation.call(null); }, TypeError, 'null is not an object');
st.end();
});
runTests(callBind(implementation), t);
t.end();
});

View File

@@ -0,0 +1,18 @@
'use strict';
var index = require('../');
var callBind = require('call-bind');
var test = require('tape');
var runTests = require('./tests');
test('as a function', function (t) {
t.test('bad array/this value', function (st) {
st['throws'](callBind(index, null, undefined, function () {}), TypeError, 'undefined is not an object');
st['throws'](callBind(index, null, null, function () {}), TypeError, 'null is not an object');
st.end();
});
runTests(index, t);
t.end();
});

View File

@@ -0,0 +1,46 @@
'use strict';
var orig = Array.prototype.findLastIndex;
require('../auto');
var test = require('tape');
var hasOwn = require('hasown');
var defineProperties = require('define-properties');
var callBind = require('call-bind');
var isEnumerable = Object.prototype.propertyIsEnumerable;
var supportsStrictMode = require('has-strict-mode')();
var functionsHaveNames = require('functions-have-names')();
var runTests = require('./tests');
test('shimmed', function (t) {
t.comment('shimmed: ' + (orig === Array.prototype.findLastIndex ? 'no' : 'yes'));
t.equal(Array.prototype.findLastIndex.length, 1, 'Array#findLastIndex has a length of 1');
t.test('Function name', { skip: !functionsHaveNames }, function (st) {
st.equal(Array.prototype.findLastIndex.name, 'findLastIndex', 'Array#findLastIndex has name "findLastIndex"');
st.end();
});
t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
et.equal(false, isEnumerable.call(Array.prototype, 'findLastIndex'), 'Array#findLastIndex is not enumerable');
et.end();
});
t.test('bad array/this value', { skip: !supportsStrictMode }, function (st) {
st['throws'](function () { return Array.prototype.findLastIndex.call(undefined, function () {}); }, TypeError, 'undefined is not an object');
st['throws'](function () { return Array.prototype.findLastIndex.call(null, function () {}); }, TypeError, 'null is not an object');
st.end();
});
t.test('Symbol.unscopables', { skip: typeof Symbol !== 'function' || typeof Symbol.unscopables !== 'symbol' }, function (st) {
st.ok(hasOwn(Array.prototype[Symbol.unscopables], 'findLastIndex'), 'Array.prototype[Symbol.unscopables] has own `findLastIndex` property');
st.equal(Array.prototype[Symbol.unscopables].findLastIndex, true, 'Array.prototype[Symbol.unscopables].findLastIndex is true');
st.end();
});
runTests(callBind(Array.prototype.findLastIndex), t);
t.end();
});

View File

@@ -0,0 +1,246 @@
var hasStrictMode = require('has-strict-mode')();
var v = require('es-value-fixtures');
var forEach = require('for-each');
var inspect = require('object-inspect');
var maxSafeInteger = require('es-abstract/helpers/maxSafeInteger');
var global = require('globalthis')();
var trueThunk = function () { return true; };
var falseThunk = function () { return false; };
var canDistinguishSparseFromUndefined = 0 in [undefined]; // IE 6 - 8 have a bug where this returns false.
var undefinedIfNoSparseBug = canDistinguishSparseFromUndefined ? undefined : { valueOf: function () { return 0; } };
var createArrayLikeFromArray = function createArrayLikeFromArray(arr) {
var o = {};
for (var i = 0; i < arr.length; i += 1) {
if (i in arr) {
o[i] = arr[i];
}
}
o.length = arr.length;
return o;
};
var getTestArr = function () {
var arr = [0, false, null, 'hej', true, undefinedIfNoSparseBug, 3, 2];
delete arr[6];
return arr;
};
module.exports = function (findLastIndex, t) {
forEach(v.nonArrays, function (nonArray) {
if (nonArray != null) { // eslint-disable-line eqeqeq
t.equal(
findLastIndex(nonArray, function () { return true; }),
typeof nonArray.length === 'number' ? nonArray.length - 1 : -1,
inspect(nonArray) + ' is not an array'
);
}
});
t.test('throws on a non-callable predicate', function (st) {
forEach(v.nonFunctions, function (nonFunction) {
st['throws'](
function () { findLastIndex([], nonFunction); },
TypeError,
inspect(nonFunction) + ' is not a Function'
);
});
st.end();
});
t.test('passes the correct values to the callback', function (st) {
st.plan(5);
var expectedValue = {};
var arr = [expectedValue];
var context = {};
findLastIndex(arr, function (value, key, list) {
st.equal(arguments.length, 3);
st.equal(value, expectedValue, 'first argument is the value');
st.equal(key, 0, 'second argument is the index');
st.equal(list, arr, 'third argument is the array being iterated');
st.equal(this, context, 'receiver is the expected value');
return true;
}, context);
st.end();
});
t.test('does not visit elements added to the array after it has begun', function (st) {
st.plan(2);
var arr = [1, 2, 3];
var i = 0;
findLastIndex(arr, function (a) {
i += 1;
arr.push(a + 3);
return i > 3;
});
st.deepEqual(arr, [1, 2, 3, 6, 5, 4], 'array has received 3 new elements');
st.equal(i, 3, 'findLastIndex callback only called thrice');
st.end();
});
t.test('does not visit elements deleted from the array after it has begun', function (st) {
var arr = [1, 2, 3];
var actual = [];
findLastIndex(arr, function (x, i) {
actual.push([i, x]);
delete arr[1];
return false;
});
st.deepEqual(actual, [[2, 3], [1, undefined], [0, 1]]);
st.end();
});
t.test('sets the right context when given none', function (st) {
var context;
findLastIndex([1], function () { context = this; });
st.equal(context, global, 'receiver is global object in sloppy mode');
st.test('strict mode', { skip: !hasStrictMode }, function (sst) {
findLastIndex([1], function () {
'use strict';
context = this;
});
sst.equal(context, undefined, 'receiver is undefined in strict mode');
sst.end();
});
st.end();
});
t.test('empty array', function (st) {
st.equal(findLastIndex([], trueThunk), -1, 'true thunk callback yields -1');
st.equal(findLastIndex([], falseThunk), -1, 'false thunk callback yields -1');
var counter = 0;
var callback = function () { counter += 1; };
findLastIndex([], callback);
st.equal(counter, 0, 'counter is not incremented');
st.end();
});
t.equal(findLastIndex([1, 2, 3], trueThunk), 2, 'returns last index if findLastIndex callback returns true');
t.equal(findLastIndex([1, 2, 3], falseThunk), -1, 'returns -1 if no callback returns true');
t.test('stopping after N elements', function (st) {
st.test('no context', function (sst) {
var actual = {};
var count = 0;
findLastIndex(getTestArr(), function (obj, index) {
actual[index] = obj;
count += 1;
return count === 4;
});
sst.deepEqual(actual, { 4: true, 5: undefinedIfNoSparseBug, 6: undefined, 7: 2 });
sst.end();
});
st.test('with context', function (sst) {
var actual = {};
var context = { actual: actual };
var count = 0;
findLastIndex(getTestArr(), function (obj, index) {
this.actual[index] = obj;
count += 1;
return count === 4;
}, context);
sst.deepEqual(actual, { 4: true, 5: undefinedIfNoSparseBug, 6: undefined, 7: 2 });
sst.end();
});
st.test('arraylike, no context', function (sst) {
var actual = {};
var count = 0;
findLastIndex(createArrayLikeFromArray(getTestArr()), function (obj, index) {
actual[index] = obj;
count += 1;
return count === 4;
});
sst.deepEqual(actual, { 4: true, 5: undefinedIfNoSparseBug, 6: undefined, 7: 2 });
sst.end();
});
st.test('arraylike, context', function (sst) {
var actual = {};
var count = 0;
var context = { actual: actual };
findLastIndex(createArrayLikeFromArray(getTestArr()), function (obj, index) {
this.actual[index] = obj;
count += 1;
return count === 4;
}, context);
sst.deepEqual(actual, { 4: true, 5: undefinedIfNoSparseBug, 6: undefined, 7: 2 });
sst.end();
});
st.end();
});
t.test('list arg boxing', function (st) {
st.plan(3);
findLastIndex('bar', function (item, index, list) {
st.equal(item, 'r', 'last letter matches');
st.equal(typeof list, 'object', 'primitive list arg is boxed');
st.equal(Object.prototype.toString.call(list), '[object String]', 'boxed list arg is a String');
return true;
});
st.end();
});
t.test('array altered during loop', function (st) {
var arr = ['Shoes', 'Car', 'Bike'];
var results = [];
findLastIndex(arr, function (kValue) {
if (results.length === 0) {
arr.splice(1, 1);
}
results.push(kValue);
});
st.equal(results.length, 3, 'predicate called three times');
st.deepEqual(results, ['Bike', 'Bike', 'Shoes']);
results = [];
arr = ['Skateboard', 'Barefoot'];
findLastIndex(arr, function (kValue) {
if (results.length === 0) {
arr.push('Motorcycle');
arr[0] = 'Magic Carpet';
}
results.push(kValue);
});
st.equal(results.length, 2, 'predicate called twice');
st.deepEqual(results, ['Barefoot', 'Magic Carpet']);
st.end();
});
t.test('maximum index', function (st) {
// https://github.com/tc39/test262/pull/3775
var arrayLike = { length: Number.MAX_VALUE };
var calledWithIndex = [];
findLastIndex(arrayLike, function (_, index) {
calledWithIndex.push(index);
return true;
});
st.deepEqual(calledWithIndex, [maxSafeInteger - 1], 'predicate invoked once');
st.end();
});
};