array.prototype.filter
Advanced tools
Comparing version 0.1.1 to 1.0.0
57
index.js
@@ -1,44 +0,25 @@ | ||
/** | ||
* Array.prototype.filter() - Polyfill | ||
* | ||
* @ref https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter | ||
*/ | ||
'use strict'; | ||
(function() { | ||
if (!Array.prototype.filter) { | ||
Array.prototype.filter = function(fun/*, thisArg*/) { | ||
'use strict'; | ||
var define = require('define-properties'); | ||
var RequireObjectCoercible = require('es-abstract/2020/RequireObjectCoercible'); | ||
var callBound = require('call-bind/callBound'); | ||
if (this === void 0 || this === null) { | ||
throw new TypeError(); | ||
} | ||
var implementation = require('./implementation'); | ||
var getPolyfill = require('./polyfill'); | ||
var polyfill = getPolyfill(); | ||
var shim = require('./shim'); | ||
var t = Object(this); | ||
var len = t.length >>> 0; | ||
if (typeof fun !== 'function') { | ||
throw new TypeError(); | ||
} | ||
var $slice = callBound('Array.prototype.slice'); | ||
var res = []; | ||
var thisArg = arguments.length >= 2 ? arguments[1] : void 0; | ||
for (var i = 0; i < len; i++) { | ||
if (i in t) { | ||
var val = t[i]; | ||
// eslint-disable-next-line no-unused-vars | ||
var bound = function filter(array, callbackfn) { | ||
RequireObjectCoercible(array); | ||
return polyfill.apply(array, $slice(arguments, 1)); | ||
}; | ||
define(bound, { | ||
getPolyfill: getPolyfill, | ||
implementation: implementation, | ||
shim: shim | ||
}); | ||
// NOTE: Technically this should Object.defineProperty at | ||
// the next index, as push can be affected by | ||
// properties on Object.prototype and Array.prototype. | ||
// But that method's new, and collisions should be | ||
// rare, so use the more-compatible alternative. | ||
if (fun.call(thisArg, val, i, t)) { | ||
res.push(val); | ||
} | ||
} | ||
} | ||
return res; | ||
}; | ||
} | ||
})(); | ||
module.exports = bound; |
100
package.json
{ | ||
"name": "array.prototype.filter", | ||
"version": "0.1.1", | ||
"description": "Simple ES6 Array.prototype.filter polyfill for older environments.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/ryanhefner/Array.prototype.filter.git" | ||
}, | ||
"keywords": [ | ||
"javascript", | ||
"es6", | ||
"polyfill", | ||
"array", | ||
"filter" | ||
], | ||
"author": "Ryan Hefner <hi@ryanhefner.com> (https://www.ryanhefner.com)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/ryanhefner/Array.prototype.filter/issues" | ||
}, | ||
"homepage": "https://github.com/ryanhefner/Array.prototype.filter#readme" | ||
"name": "array.prototype.filter", | ||
"version": "1.0.0", | ||
"description": "An ES5 spec-compliant `Array.prototype.filter` shim/polyfill/replacement that works as far down as ES3.", | ||
"main": "index.js", | ||
"scripts": { | ||
"prepublish": "not-in-publish || npm run prepublishOnly", | ||
"prepublishOnly": "safe-publish-latest", | ||
"preversion": "auto-changelog", | ||
"prelint": "evalmd README.md", | ||
"lint": "eslint .", | ||
"postlint": "es-shim-api --bound", | ||
"pretest": "npm run lint", | ||
"test": "npm run tests-only", | ||
"posttest": "npx aud --production", | ||
"tests-only": "nyc tape 'test/**/*.js'", | ||
"testling": "npx testling --html > test.html", | ||
"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.filter.git" | ||
}, | ||
"keywords": [ | ||
"Array.prototype.filter", | ||
"filter", | ||
"array", | ||
"ES5", | ||
"shim", | ||
"polyfill", | ||
"es-shim API" | ||
], | ||
"author": "Jordan Harband <ljharb@gmail.com>", | ||
"funding": { | ||
"url": "https://github.com/sponsors/ljharb" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/es-shims/Array.prototype.filter/issues" | ||
}, | ||
"homepage": "https://github.com/es-shims/Array.prototype.filter#readme", | ||
"engines": { | ||
"node": ">= 0.4" | ||
}, | ||
"devDependencies": { | ||
"@es-shims/api": "^2.1.2", | ||
"@ljharb/eslint-config": "^17.5.1", | ||
"aud": "^1.1.4", | ||
"auto-changelog": "^2.2.1", | ||
"es-value-fixtures": "^1.2.1", | ||
"eslint": "^7.23.0", | ||
"evalmd": "^0.0.19", | ||
"for-each": "^0.3.3", | ||
"function-bind": "^1.1.1", | ||
"functions-have-names": "^1.2.2", | ||
"globalthis": "^1.0.2", | ||
"has-strict-mode": "^1.0.1", | ||
"nyc": "^10.3.2", | ||
"safe-publish-latest": "^1.1.4", | ||
"tape": "^5.2.2" | ||
}, | ||
"dependencies": { | ||
"call-bind": "^1.0.2", | ||
"define-properties": "^1.1.3", | ||
"es-abstract": "^1.18.0", | ||
"es-array-method-boxes-properly": "^1.0.0", | ||
"is-string": "^1.0.5" | ||
}, | ||
"auto-changelog": { | ||
"output": "CHANGELOG.md", | ||
"template": "keepachangelog", | ||
"unreleased": false, | ||
"commitLimit": false, | ||
"backfillLimit": false, | ||
"hideCredit": true | ||
} | ||
} |
@@ -1,17 +0,60 @@ | ||
# ES6 `Array.prototype.filter` polyfill | ||
# array.prototype.filter <sup>[![Version Badge][npm-version-svg]][package-url]</sup> | ||
## Installation | ||
* `npm install array.prototype.filter` | ||
[![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] | ||
## Usage | ||
* Coming soon... | ||
[![npm badge][npm-badge-png]][package-url] | ||
## License | ||
The MIT License (MIT) | ||
Copyright (c) 2016 Ryan Hefner [https://www.ryanhefner.com](https://www.ryanhefner.com) | ||
An ES5 spec-compliant `Array.prototype.filter` shim/polyfill/replacement that works as far down as ES3. | ||
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: | ||
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 [spec](https://www.ecma-international.org/ecma-262/5.1/). | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
Because `Array.prototype.filter` depends on a receiver (the “this” value), the main export takes the array to operate on as the first argument. | ||
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. | ||
## Example | ||
```js | ||
var filter = require('array.prototype.filter'); | ||
var assert = require('assert'); | ||
assert.deepEqual(filter([1, 2, 3], function (x) { return x >= 2; }), [2, 3]); | ||
assert.deepEqual(filter([1, 2, 3], function (x) { return x <= 2; }), [1, 2]); | ||
``` | ||
```js | ||
var filter = require('array.prototype.filter'); | ||
var assert = require('assert'); | ||
/* when Array#filter is not present */ | ||
delete Array.prototype.filter; | ||
var shimmedFilter = filter.shim(); | ||
assert.equal(shimmedFilter, filter.getPolyfill()); | ||
var arr = [1, 2, 3]; | ||
var isOdd = function (x) { return x % 2 !== 0; }; | ||
assert.deepEqual(arr.filter(isOdd), filter(arr, isOdd)); | ||
``` | ||
```js | ||
var filter = require('array.prototype.filter'); | ||
var assert = require('assert'); | ||
/* when Array#filter is present */ | ||
var shimmedFilter = filter.shim(); | ||
assert.equal(shimmedFilter, Array.prototype.filter); | ||
assert.deepEqual(arr.filter(isOdd), filter(arr, isOdd)); | ||
``` | ||
## Tests | ||
Simply clone the repo, `npm install`, and run `npm test` | ||
[package-url]: https://npmjs.org/package/array.prototype.filter | ||
[npm-version-svg]: https://versionbadg.es/es-shims/Array.prototype.filter.svg | ||
[deps-svg]: https://david-dm.org/es-shims/Array.prototype.filter.svg | ||
[deps-url]: https://david-dm.org/es-shims/Array.prototype.filter | ||
[dev-deps-svg]: https://david-dm.org/es-shims/Array.prototype.filter/dev-status.svg | ||
[dev-deps-url]: https://david-dm.org/es-shims/Array.prototype.filter#info=devDependencies | ||
[npm-badge-png]: https://nodei.co/npm/array.prototype.filter.png?downloads=true&stars=true | ||
[license-image]: https://img.shields.io/npm/l/array.prototype.filter.svg | ||
[license-url]: LICENSE | ||
[downloads-image]: https://img.shields.io/npm/dm/array.prototype.filter.svg | ||
[downloads-url]: https://npm-stat.com/charts.html?package=array.prototype.filter |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
18927
16
336
0
61
5
15
2
+ Addedcall-bind@^1.0.2
+ Addeddefine-properties@^1.1.3
+ Addedes-abstract@^1.18.0
+ Addedis-string@^1.0.5
+ Addedarray-buffer-byte-length@1.0.1(transitive)
+ Addedarraybuffer.prototype.slice@1.0.3(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addeddata-view-buffer@1.0.1(transitive)
+ Addeddata-view-byte-length@1.0.1(transitive)
+ Addeddata-view-byte-offset@1.0.0(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addedes-abstract@1.23.3(transitive)
+ Addedes-array-method-boxes-properly@1.0.0(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedes-set-tostringtag@2.0.3(transitive)
+ Addedes-to-primitive@1.2.1(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedfunction.prototype.name@1.1.6(transitive)
+ Addedfunctions-have-names@1.2.3(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedget-symbol-description@1.0.2(transitive)
+ Addedglobalthis@1.0.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-bigints@1.0.2(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinternal-slot@1.0.7(transitive)
+ Addedis-array-buffer@3.0.4(transitive)
+ Addedis-bigint@1.0.4(transitive)
+ Addedis-boolean-object@1.1.2(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-data-view@1.0.1(transitive)
+ Addedis-date-object@1.0.5(transitive)
+ Addedis-negative-zero@2.0.3(transitive)
+ Addedis-number-object@1.0.7(transitive)
+ Addedis-regex@1.1.4(transitive)
+ Addedis-shared-array-buffer@1.0.3(transitive)
+ Addedis-string@1.0.7(transitive)
+ Addedis-symbol@1.0.4(transitive)
+ Addedis-typed-array@1.1.13(transitive)
+ Addedis-weakref@1.0.2(transitive)
+ Addedisarray@2.0.5(transitive)
+ Addedobject-inspect@1.13.1(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedobject.assign@4.1.5(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedregexp.prototype.flags@1.5.2(transitive)
+ Addedsafe-array-concat@1.1.2(transitive)
+ Addedsafe-regex-test@1.0.3(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedset-function-name@2.0.2(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedstring.prototype.trim@1.2.9(transitive)
+ Addedstring.prototype.trimend@1.0.8(transitive)
+ Addedstring.prototype.trimstart@1.0.8(transitive)
+ Addedtyped-array-buffer@1.0.2(transitive)
+ Addedtyped-array-byte-length@1.0.1(transitive)
+ Addedtyped-array-byte-offset@1.0.2(transitive)
+ Addedtyped-array-length@1.0.6(transitive)
+ Addedunbox-primitive@1.0.2(transitive)
+ Addedwhich-boxed-primitive@1.0.2(transitive)
+ Addedwhich-typed-array@1.1.15(transitive)