Package detail

array.prototype.indexof

es-shims2.6kMIT1.0.8

An ES2015 spec-compliant Array.prototype.indexOf shim/polyfill/replacement that works as far down as ES3.

Array.prototype.indexOf, indexOf, array, ES5

readme

array.prototype.indexof Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

An ES2015 spec-compliant Array.prototype.indexof shim/polyfill/replacement that works as far down as ES3.

This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the spec.

Because Array.prototype.indexOf depends on a receiver (the “this” value), the main export takes the array to operate on as the first argument.

Example

var indexOf = require('array.prototype.indexof');
var assert = require('assert');

assert.equal(indexOf([1, 2, 3], 2), 1);
assert.equal(indexOf([1, 0, 1], 1), 0);
assert.equal(indexOf([1, 2, 3], 4), -1);
assert.equal(indexOf([NaN], NaN), -1);
var indexOf = require('array.prototype.indexof');
var assert = require('assert');
/* when Array#indexOf is not present */
delete Array.prototype.indexOf;
var shimmedMap = indexOf.shim();
assert.equal(shimmedMap, indexOf.getPolyfill());
assert.equal([1, 2, 3].indexOf(2), 1);
assert.equal([1, 0, 1].indexOf(1), 0);
assert.equal([1, 2, 3].indexOf(4), -1);
assert.equal([NaN].indexOf(NaN), -1);
var indexOf = require('array.prototype.indexof');
var assert = require('assert');
/* when Array#indexOf is present */
var shimmedMap = indexOf.shim();
assert.equal(shimmedMap, Array.prototype.indexOf);
assert.equal([1, 2, 3].indexOf(2), 1);

Tests

Simply clone the repo, npm install, and run npm test

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v1.0.8 - 2024-12-20

Commits

  • [actions] split out node 10-20, and 20+ a8ce49d
  • [Dev Deps] update @es-shims/api, @ljharb/eslint-config, auto-changelog, tape 3d90e3a
  • [Refactor] use call-bound directly f5aa29e
  • [Deps] update call-bind, es-abstract, is-string eb46fe3
  • [Tests] replace aud with npm audit 2adc98e
  • [Dev Deps] add missing peer dep a714cf8

v1.0.7 - 2024-03-18

Commits

  • [Deps] update call-bind, define-properties, es-abstract, is-negative-zero 162105b
  • [actions] remove redundant finisher 919a937
  • [Refactor] use es-object-atoms where possible fe30f76
  • [Dev Deps] update aud, npmignore, tape a7b2836

v1.0.6 - 2023-09-05

Commits

  • [Deps] update define-properties, es-abstract 7c38d02
  • [Dev Deps] update @es-shims/api, @ljharb/eslint-config, aud, tape 87bd4cc

v1.0.5 - 2022-11-03

Commits

  • [Deps] update es-abstract e5ddae8
  • [actions] update rebase action to use reusable workflow 5efca90
  • [Dev Deps] update aud, tape ca75de7

v1.0.4 - 2022-05-24

Commits

  • [actions] reuse common workflows af13e9e
  • [meta] use npmignore to autogenerate an npmignore file 0df70cf
  • [Tests] more accurate tests 6716f45
  • [Dev Deps] update eslint, @ljharb/eslint-config, @es-shims/api, safe-publish-latest, tape 465819c
  • [Refactor] update implementation to use LengthOfArrayLike 1b62a3e
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, functions-have-names, tape a47cb21
  • [actions] update codecov uploader 7309c25
  • [Deps] update define-properties, es-abstract e17b09f
  • [Deps] update es-abstract, is-negative-zero dd65c04

v1.0.3 - 2021-10-01

Commits

  • [actions] use node/install instead of node/run; use codecov action caef355
  • [Deps] update es-abstract, is-string 854aa2a
  • [Dev Deps] use call-bind instead of function-bind eebd1e0
  • [Dev Deps] update eslint, @ljharb/eslint-config, @es-shims/api, aud, auto-changelog, tape 8d8a37e
  • [readme] add github actions/codecov badges 6c9b5bf
  • [Dev Deps] update eslint, tape e03b76e
  • [meta] use prepublishOnly, for npm 7+ 7ac81d3
  • [Deps] update es-abstract 476f149

v1.0.2 - 2021-02-21

Commits

  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, functions-have-names, has-strict-mode, tape e2c35fc
  • [actions] update workflows 7ec55f8
  • [Deps] update call-bind, es-abstract, is-negative-zero 44d0b70
  • [readme] remove travis badge 22b338d
  • [Tests] increase coverage ac51274

v1.0.1 - 2020-11-18

Commits

  • [Tests] migrate tests to Github Actions a88ec68
  • [meta] do not publish Github Action workflows ae2fa82
  • [Deps] update es-abstract; add call-bind where applicable b2c31ae
  • [Tests] run nyc on all tests 2797270
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, tape dadff6f
  • [actions] add "Allow Edits" workflow 920d304
  • [Tests] run es-shim-api in postlint; use tape runner e3c9f5f
  • [Dev Deps] update auto-changelog, tape 32a3c2d
  • [Dev Deps] update @ljharb/eslint-config, tape 079d245
  • [Dev Deps] update auto-changelog; add aud 60a4e1f
  • [actions] switch Automatic Rebase workflow to pull_request_target event 1401a04
  • [Tests] only audit prod deps e6d34f4
  • [Deps] update es-abstract 38255f4
  • [Deps] update es-abstract e1f5c56
  • [Dev Deps] update functions-have-names 41a0cac

v1.0.0 - 2020-01-17

Commits