pax_global_header 0000666 0000000 0000000 00000000064 14576216676 0014536 g ustar 00root root 0000000 0000000 52 comment=cdc51a13770d15cfaa2ef8f650d7bc6627603bf4
paulmillr-Array.prototype.find-32cafa3/ 0000775 0000000 0000000 00000000000 14576216676 0020262 5 ustar 00root root 0000000 0000000 paulmillr-Array.prototype.find-32cafa3/.editorconfig 0000664 0000000 0000000 00000000203 14576216676 0022732 0 ustar 00root root 0000000 0000000 [*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
[*.{js,json}]
indent_style = tab
paulmillr-Array.prototype.find-32cafa3/.eslintrc 0000664 0000000 0000000 00000001123 14576216676 0022103 0 ustar 00root root 0000000 0000000 {
"root": true,
"extends": "@ljharb",
"rules": {
"array-bracket-newline": 0,
"id-length": [2, { "min": 1, "max": 25, "properties": "never" }],
"max-statements-per-line": [2, { "max": 2 }],
"multiline-comment-style": 0,
"new-cap": [2, {
"capIsNewExceptions": [
"Call",
"IsCallable",
"RequireObjectCoercible",
"ToInteger",
"ToLength",
"ToObject",
"ToString",
]
}],
"no-magic-numbers": 0,
},
"overrides": [
{
"files": "test/**",
"rules": {
"id-length": 0,
"max-lines-per-function": 0,
"no-invalid-this": 0,
},
}
]
}
paulmillr-Array.prototype.find-32cafa3/.github/ 0000775 0000000 0000000 00000000000 14576216676 0021622 5 ustar 00root root 0000000 0000000 paulmillr-Array.prototype.find-32cafa3/.github/FUNDING.yml 0000664 0000000 0000000 00000001117 14576216676 0023437 0 ustar 00root root 0000000 0000000 # 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.find
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']
paulmillr-Array.prototype.find-32cafa3/.github/SECURITY.md 0000664 0000000 0000000 00000000235 14576216676 0023413 0 ustar 00root root 0000000 0000000 # Security
Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report.
paulmillr-Array.prototype.find-32cafa3/.github/workflows/ 0000775 0000000 0000000 00000000000 14576216676 0023657 5 ustar 00root root 0000000 0000000 paulmillr-Array.prototype.find-32cafa3/.github/workflows/node-aught.yml 0000664 0000000 0000000 00000000322 14576216676 0026432 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js < 10'
on: [pull_request, push]
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '< 10'
type: minors
command: npm run tests-only
paulmillr-Array.prototype.find-32cafa3/.github/workflows/node-pretest.yml 0000664 0000000 0000000 00000000206 14576216676 0027011 0 ustar 00root root 0000000 0000000 name: 'Tests: pretest/posttest'
on: [pull_request, push]
jobs:
tests:
uses: ljharb/actions/.github/workflows/pretest.yml@main
paulmillr-Array.prototype.find-32cafa3/.github/workflows/node-tens.yml 0000664 0000000 0000000 00000000324 14576216676 0026275 0 ustar 00root root 0000000 0000000 name: 'Tests: node.js >= 10'
on: [pull_request, push]
jobs:
tests:
uses: ljharb/actions/.github/workflows/node.yml@main
with:
range: '>= 10'
type: minors
command: npm run tests-only
paulmillr-Array.prototype.find-32cafa3/.github/workflows/rebase.yml 0000664 0000000 0000000 00000000257 14576216676 0025647 0 ustar 00root root 0000000 0000000 name: Automatic Rebase
on: [pull_request_target]
jobs:
_:
uses: ljharb/actions/.github/workflows/rebase.yml@main
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
paulmillr-Array.prototype.find-32cafa3/.github/workflows/require-allow-edits.yml 0000664 0000000 0000000 00000000303 14576216676 0030274 0 ustar 00root root 0000000 0000000 name: Require “Allow Edits”
on: [pull_request_target]
jobs:
_:
name: "Require “Allow Edits”"
runs-on: ubuntu-latest
steps:
- uses: ljharb/require-allow-edits@main
paulmillr-Array.prototype.find-32cafa3/.gitignore 0000664 0000000 0000000 00000000546 14576216676 0022257 0 ustar 00root root 0000000 0000000 # Numerous always-ignore extensions
*.diff
*.err
*.orig
*.log
*~
# OS or Editor folders
.DS_Store
.cache
Icon?
# Folders to ignore
.hg
.svn
# Node.js package manager
/node_modules
/npm-debug.log
# Other stuff
*.pyc
/tmp
# Project stuff
# Only apps should have lockfiles
npm-shrinkwrap.json
package-lock.json
yarn.lock
coverage
.nyc_output
.npmignore
paulmillr-Array.prototype.find-32cafa3/.npmrc 0000664 0000000 0000000 00000000067 14576216676 0021405 0 ustar 00root root 0000000 0000000 package-lock=false
allow-same-version=true
message=v%s
paulmillr-Array.prototype.find-32cafa3/.nycrc 0000664 0000000 0000000 00000000213 14576216676 0021375 0 ustar 00root root 0000000 0000000 {
"all": true,
"check-coverage": false,
"reporter": ["text-summary", "text", "html", "json"],
"exclude": [
"coverage",
"test"
]
}
paulmillr-Array.prototype.find-32cafa3/CHANGELOG.md 0000664 0000000 0000000 00000012650 14576216676 0022077 0 ustar 00root root 0000000 0000000 # 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).
## [v2.2.3](https://github.com/es-shims/Array.prototype.find/compare/v2.2.2...v2.2.3) - 2024-03-18
### Commits
- [actions] remove redundant finisher [`5699c0f`](https://github.com/es-shims/Array.prototype.find/commit/5699c0fd952c7e455b1fbe855ab8b6d1690d1e38)
- [Deps] update `call-bind`, `define-properties`, `es-abstract`, `es-shim-unscopables` [`01d9650`](https://github.com/es-shims/Array.prototype.find/commit/01d9650f299fc2aed1bba917fa047874b921b518)
- [Deps] update `es-abstract` [`9d82ddd`](https://github.com/es-shims/Array.prototype.find/commit/9d82dddadfc46d914bec2b0873fc66e8e26a9a4b)
- [Dev Deps] update `aud`, `npmignore`, `tape` [`b02d54e`](https://github.com/es-shims/Array.prototype.find/commit/b02d54e3426766a2bca083f2a6323ebc87d3b572)
- [Refactor] use `es-object-atoms` where possible [`1f05f62`](https://github.com/es-shims/Array.prototype.find/commit/1f05f62dd23747ea51d4e599efb71e2ca3ccb650)
- [meta] add missing `engines.node` [`b252946`](https://github.com/es-shims/Array.prototype.find/commit/b252946360156e5d3d09d4ed59224c3cbf14967c)
- [Dev Deps] update `tape` [`01ac3e8`](https://github.com/es-shims/Array.prototype.find/commit/01ac3e8b2d4b2566dd85f0d1b2dc4cda68693d7f)
## [v2.2.2](https://github.com/es-shims/Array.prototype.find/compare/v2.2.1...v2.2.2) - 2023-08-27
### Commits
- [meta] add `auto-changelog` [`90ef840`](https://github.com/es-shims/Array.prototype.find/commit/90ef8406f1a3bea1d863796bfe0ad8a6f7c715e3)
- [Deps] update `es-abstract` [`c83a92f`](https://github.com/es-shims/Array.prototype.find/commit/c83a92f20b4277eaac8d7b858c23daa1790be347)
- [Dev Deps] update `@es-shims/api`, `@ljharb/eslint-config`, `aud`, `tape` [`4f76839`](https://github.com/es-shims/Array.prototype.find/commit/4f76839dd1b7f5596a338921bc725959b316e99a)
- [Dev Deps] update `@ljharb/eslint-config`, `@es-shims/api`, `aud`, `tape` [`1997871`](https://github.com/es-shims/Array.prototype.find/commit/19978718a422c3ea13797d095b2c3a8bf1b62a8f)
- [Deps] update `define-properties`, `es-abstract` [`28eb0a6`](https://github.com/es-shims/Array.prototype.find/commit/28eb0a6f235d5cf5be9437e8a9d0f3b2d18bd77e)
- [meta] create SECURITY.md [`dba046f`](https://github.com/es-shims/Array.prototype.find/commit/dba046ffcabe15c05c980b4c71c8adccceb1d1e9)
- [meta] fix npmrc config [`574c8fd`](https://github.com/es-shims/Array.prototype.find/commit/574c8fdee7b4fbb3ece7f242b69b7ce1a1ac3968)
# 2.2.1
- [Deps] update `define-properties`, `es-abstract`
- [actions] update rebase action to use reusable workflow
- [meta] use `npmignore` to autogenerate an npmignore file
- [meta] create FUNDING.yml
- [Dev Deps] update `aud`, `functions-have-names`, `tape`
# 2.2.0
- [New] `shim`/`auto`: add `find` to `Symbol.unscopables`
- [Deps] update `es-abstract`
- [actions] reuse common workflows
- [actions] update codecov uploader
- [Tests] migrate to tape
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `@es-shims/api`, `aud`, `safe-publish-latest`
# 2.1.2
- [Deps] use `call-bind` for Array slice
- [Deps] update `es-abstract`
- [readme] update badges
- [meta] update scripts
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `@es-shims/api`
- [Tests] migrate travis-ci to Github Actions
# 2.1.1
- [Refactor] Only require the parts of es-abstract that are used (77% bundle size decrease) (#28)
- [meta] add `funding` field
- [Tests] use shared travis-ci configs
- [Tests] only run `aud` on prod deps
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`; add `safe-publish-latest`
# 2.1.0
- [New] add `auto` entry point
- [Performance] Remove unnecessary `ToInteger` call.
- [Performance] inline `ES.Call` since `IsCallable` is already checked prior to the loop.
- [Performance] avoid checking `arguments` indexes beyond `arguments.length`
- [meta] Add LICENSE file (#25)
- [Deps] update `define-properties`, `es-abstract`
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `chai`, `mocha`
- [Tests] fix matrix; use `nvm install-latest-npm`, test up to latest node
- [Tests] add `npm run posttest`
# 2.0.4
- [Performance] the entry point should use the native function when compliant
# 2.0.3
- [Fix] again: don’t needlessly shim `Array#find` (#22)
# 2.0.2
- [Fix] don’t needlessly shim `Array#find` (#22)
- [Deps] update `es-abstract`
- [Dev Deps] update `@es-shims/api`, `mocha`, `eslint`, `@ljharb/eslint-config`
- [Tests] up to `node` `v7.4`, `v4.7`; improve test matrix
# 2.0.1
- [Fix] use call instead of apply in bound entry point function (#20)
- [Tests] up to `node` `v7.0`, `v6.9`, `v5.12`; improve test matrix
- [Tests] add `npm run lint`
# 2.0.0
- [Breaking] implement es-shim API (#15)
- [Fix] use ToLength, not ToUint32 (#15)
- [Fix] Uncallable predicates must throw even when the array is empty (#15)
- [Docs] fix browserify example (#12)
# 1.0.0
- [Breaking] do not skip holes (per ES6 change) (#6)
- [Dev Deps] update `mocha`
- [Fix] Older browsers report the typeof some host objects and regexes as "function" (#8)
# 0.2.0
- [Tests] Add travis support (#5)
- [Tests] Add tests (#5)
- [Fix] Fix failing test: 'should work with an array-like object with negative length' (#5)
# 0.1.1
- [Fix] check if `Array#find` already exists (#4)
# 0.1.0
- Initial release
paulmillr-Array.prototype.find-32cafa3/LICENSE 0000664 0000000 0000000 00000002126 14576216676 0021270 0 ustar 00root root 0000000 0000000 The MIT License (MIT)
Copyright (c) 2019 Paul Miller (https://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.
paulmillr-Array.prototype.find-32cafa3/README.md 0000664 0000000 0000000 00000005215 14576216676 0021544 0 ustar 00root root 0000000 0000000 # array.prototype.find [![Version Badge][npm-version-svg]][package-url]
[![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]
Simple ES6 [Array.prototype.find](http://people.mozilla.org/%7Ejorendorff/es6-draft.html#sec-array.prototype.find) 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.find`
## Usage
* `Array.prototype.find(predicate[, thisArg])` returns first item that matches `predicate` function.
* `predicate(value, index, collection)`: takes three arguments
* `value`: current collection element
* `index`: current collection element index
* `collection`: the collection
```javascript
// as a function
var find = require('array.prototype.find');
find([1, 2], function (x) { return x === 2; }); // 2
// to shim it
require('array.prototype.find').shim();
```
Code example:
```javascript
// Default:
[1, 5, 10, 15].find(function (a) { return a > 9; }) // 10
```
## Acknowledgements
Tests, fixes, and travis support added by [_duncanhall](http://twitter.com/_duncanhall)
## License
[The MIT License](https://github.com/paulmillr/mit) (c) 2016 Paul Miller (http://paulmillr.com)
[package-url]: https://npmjs.org/package/array.prototype.find
[npm-version-svg]: https://versionbadg.es/es-shims/Array.prototype.find.svg
[deps-svg]: https://david-dm.org/es-shims/Array.prototype.find.svg
[deps-url]: https://david-dm.org/es-shims/Array.prototype.find
[dev-deps-svg]: https://david-dm.org/es-shims/Array.prototype.find/dev-status.svg
[dev-deps-url]: https://david-dm.org/es-shims/Array.prototype.find#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/array.prototype.find.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/array.prototype.find.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/array.prototype.find.svg
[downloads-url]: https://npm-stat.com/charts.html?package=array.prototype.find
[codecov-image]: https://codecov.io/gh/es-shims/Array.prototype.find/branch/master/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/es-shims/Array.prototype.find/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/Array.prototype.find
[actions-url]: https://github.com/es-shims/Array.prototype.find/actions
paulmillr-Array.prototype.find-32cafa3/auto.js 0000664 0000000 0000000 00000000044 14576216676 0021566 0 ustar 00root root 0000000 0000000 'use strict';
require('./shim')();
paulmillr-Array.prototype.find-32cafa3/implementation.js 0000664 0000000 0000000 00000001343 14576216676 0023646 0 ustar 00root root 0000000 0000000 'use strict';
var ToObject = require('es-object-atoms/ToObject');
var ToLength = require('es-abstract/2024/ToLength');
var IsCallable = require('es-abstract/2024/IsCallable');
module.exports = function find(predicate) {
var list = ToObject(this);
var length = ToLength(list.length);
if (!IsCallable(predicate)) {
throw new TypeError('Array#find: predicate must be a function');
}
if (length === 0) {
return void 0;
}
var thisArg;
if (arguments.length > 0) {
thisArg = arguments[1];
}
for (var i = 0, value; i < length; i++) {
value = list[i];
// inlined for performance: if (Call(predicate, thisArg, [value, i, list])) {
if (predicate.apply(thisArg, [value, i, list])) {
return value;
}
}
return void 0;
};
paulmillr-Array.prototype.find-32cafa3/index.js 0000664 0000000 0000000 00000001322 14576216676 0021725 0 ustar 00root root 0000000 0000000 'use strict';
var define = require('define-properties');
var callBound = require('call-bind/callBound');
var RequireObjectCoercible = require('es-object-atoms/RequireObjectCoercible');
var implementation = require('./implementation');
var getPolyfill = require('./polyfill');
var shim = require('./shim');
var $slice = callBound('Array.prototype.slice');
var polyfill = getPolyfill();
var boundFindShim = function find(array, predicate) { // eslint-disable-line no-unused-vars
RequireObjectCoercible(array);
var args = $slice(arguments, 1);
return polyfill.apply(array, args);
};
define(boundFindShim, {
getPolyfill: getPolyfill,
implementation: implementation,
shim: shim
});
module.exports = boundFindShim;
paulmillr-Array.prototype.find-32cafa3/package.json 0000664 0000000 0000000 00000004061 14576216676 0022551 0 ustar 00root root 0000000 0000000 {
"name": "array.prototype.find",
"version": "2.2.3",
"description": "Array.prototype.find ES6 polyfill.",
"keywords": [
"Array.prototype.find",
"find",
"es6",
"ecmascript 6",
"polyfill"
],
"main": "index.js",
"scripts": {
"prepack": "npmignore --auto --commentLines=autogenerated",
"prepublishOnly": "safe-publish-latest",
"prepublish": "not-in-publish || npm run prepublishOnly",
"lint": "eslint --ext=js,mjs .",
"postlint": "es-shim-api --bound",
"pretest": "npm run lint",
"tests-only": "nyc tape 'test/**/*.js'",
"test": "npm run tests-only",
"posttest": "aud --production",
"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://github.com/paulmillr/Array.prototype.find.git"
},
"author": "Paul Miller ",
"funding": {
"url": "https://github.com/sponsors/ljharb"
},
"contributors": [
{
"name": "Duncan Hall",
"email": "himself@duncanhall.net"
}
],
"license": "MIT",
"bugs": {
"url": "https://github.com/paulmillr/Array.prototype.find/issues"
},
"devDependencies": {
"@es-shims/api": "^2.4.2",
"@ljharb/eslint-config": "^21.1.0",
"aud": "^2.0.4",
"auto-changelog": "^2.4.0",
"eslint": "=8.8.0",
"functions-have-names": "^1.2.3",
"has-strict-mode": "^1.0.1",
"in-publish": "^2.0.1",
"npmignore": "^0.3.1",
"nyc": "^10.3.2",
"safe-publish-latest": "^2.0.0",
"tape": "^5.7.5"
},
"dependencies": {
"call-bind": "^1.0.7",
"define-properties": "^1.2.1",
"es-abstract": "^1.23.2",
"es-object-atoms": "^1.0.0",
"es-shim-unscopables": "^1.0.2"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true,
"startingVersion": "2.2.2"
},
"publishConfig": {
"ignore": [
".github/workflows"
]
},
"engines": {
"node": ">= 0.4"
}
}
paulmillr-Array.prototype.find-32cafa3/polyfill.js 0000664 0000000 0000000 00000000654 14576216676 0022457 0 ustar 00root root 0000000 0000000 'use strict';
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.find && [, 1].find(function () {
return true;
}) !== 1;
// eslint-disable-next-line global-require
return implemented ? Array.prototype.find : require('./implementation');
};
paulmillr-Array.prototype.find-32cafa3/shim.js 0000664 0000000 0000000 00000000642 14576216676 0021562 0 ustar 00root root 0000000 0000000 'use strict';
var define = require('define-properties');
var shimUnscopables = require('es-shim-unscopables');
var getPolyfill = require('./polyfill');
module.exports = function shimArrayPrototypeFind() {
var polyfill = getPolyfill();
define(
Array.prototype,
{ find: polyfill },
{
find: function () { return Array.prototype.find !== polyfill; }
}
);
shimUnscopables('find');
return polyfill;
};
paulmillr-Array.prototype.find-32cafa3/test/ 0000775 0000000 0000000 00000000000 14576216676 0021241 5 ustar 00root root 0000000 0000000 paulmillr-Array.prototype.find-32cafa3/test/implementation.js 0000664 0000000 0000000 00000001175 14576216676 0024630 0 ustar 00root root 0000000 0000000 '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();
});
paulmillr-Array.prototype.find-32cafa3/test/index.js 0000664 0000000 0000000 00000000644 14576216676 0022712 0 ustar 00root root 0000000 0000000 'use strict';
var index = 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 () { index(undefined); }, TypeError, 'undefined is not an object');
st['throws'](function () { index(null); }, TypeError, 'null is not an object');
st.end();
});
runTests(index, t);
t.end();
});
paulmillr-Array.prototype.find-32cafa3/test/shimmed.js 0000664 0000000 0000000 00000002300 14576216676 0023220 0 ustar 00root root 0000000 0000000 '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.find.length, 1, 'Array#find has a length of 1');
t.test('Function name', { skip: !functionsHaveNames }, function (st) {
st.equal(Array.prototype.find.name, 'find', 'Array#find has name "find"');
st.end();
});
t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
et.equal(false, isEnumerable.call(Array.prototype, 'find'), 'Array#find is not enumerable');
et.end();
});
t.test('bad array/this value', { skip: !hasStrictMode }, function (st) {
st['throws'](function () { return Array.prototype.find.call(undefined); }, TypeError, 'undefined is not an object');
st['throws'](function () { return Array.prototype.find.call(null); }, TypeError, 'null is not an object');
st.end();
});
runTests(callBind(Array.prototype.find), t);
t.end();
});
paulmillr-Array.prototype.find-32cafa3/test/tests.js 0000664 0000000 0000000 00000004017 14576216676 0022743 0 ustar 00root root 0000000 0000000 '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 (find, t) {
var list = [5, 10, 15, 20];
t.equal(
find(list, function (item) { return item === 15; }),
15,
'find item by predicate'
);
t.equal(
find(list, function (item) { return item === 'a'; }),
undefined,
'returns undefined when nothing matches'
);
t['throws'](
function () { find(list); },
TypeError,
'throws without callback'
);
var context = {};
var foundIndex = find(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, undefined, 'receives all three arguments');
var arraylike = { 0: 1, 1: 2, 2: 3, length: 3 };
var found = find(arraylike, function (item) {
return item === 2;
});
t.equal(found, 2, 'works with an array-like object');
t.equal(
find({ 0: 1, 1: 2, 2: 3, length: -3 }, thrower),
undefined,
'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 = find(obj, function (item, idx) {
seen.push([idx, item]);
return false;
});
s2t.equal(foundSparse, undefined);
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 = find(obj, function (item, idx) {
seen.push([idx, item]);
return false;
});
s2t.equal(foundSparse, undefined);
s2t.deepEqual(seen, [[0, 1], [1, undefined], [2, undefined]]);
s2t.end();
});
st.end();
});
};