Socket
Socket
Sign inDemoInstall

array.prototype.filter

Package Overview
Dependencies
66
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.1 to 1.0.0

.eslintignore

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;
{
"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
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc