Git Product home page Git Product logo

array.prototype.push's Introduction

array.prototype.push Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

An ES spec-compliant Array.prototype.push 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.push depends on a receiver (the β€œthis” value), the main export takes the array to operate on as the first argument.

Engines where this is needed

Note: this list is not exhaustive.

  • in node/chrome (including node 18-19): push fails to throw on a nonwritable length property
  • IE 8 and below, and pre-ES6 engines: deleteCount isn't defaulted to length - start until ES6
  • Safari 5.0: sometimes it returns undefined
  • Safari 7/8: sparse arrays of size 1e5 or greater break
  • Opera 12.15: breaks on small sparse arrays

Example

var push = require('array.prototype.push');
var assert = require('assert');

var a = [1, 1, 1];
assert.equal(push(a, 1, 2), 5);
assert.deepEqual(a, [1, 1, 1, 1, 2]);
var push = require('array.prototype.push');
var assert = require('assert');
/* when Array#push is not present */
delete Array.prototype.push;
var shimmed = push.shim();
assert.equal(shimmed, push.getPolyfill());
assert.equal(shimmed, Array.prototype.push);
var a = [1, 2, 3];
var b = [1, 2, 3];
assert.equal(a.push(1, 2, 3), push(b, 1, 2, 3));
assert.deepEqual(a, b);
var push = require('array.prototype.push');
var assert = require('assert');
/* when Array#push is present */
var shimmed = push.shim();
assert.equal(shimmed, Array.prototype.push);
assert.deepEqual([1, 2, 3].push(1, 2, 3), push([1, 2, 3], 1, 2, 3));

Tests

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

array.prototype.push's People

Contributors

ljharb avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

isabella232

array.prototype.push's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Pending Approval

These branches will be created by Renovate only once you click their checkbox below.

  • [Deps] Update Update eslint to v8.57.0
  • [Deps] Update Update eslint to v9
  • [Deps] Update Update nyc to v17
  • πŸ” Create all pending approval PRs at once πŸ”

Detected dependencies

github-actions
.github/workflows/node-aught.yml
.github/workflows/node-pretest.yml
.github/workflows/node-tens.yml
.github/workflows/rebase.yml
.github/workflows/require-allow-edits.yml
npm
package.json
  • 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
  • get-intrinsic ^1.2.4
  • has-property-descriptors ^1.0.2
  • is-string ^1.0.7
  • @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
  • evalmd ^0.0.19
  • functions-have-names ^1.2.3
  • has-strict-mode ^1.0.1
  • hasown ^2.0.2
  • in-publish ^2.0.1
  • npmignore ^0.3.1
  • nyc ^10.3.2
  • safe-publish-latest ^2.0.0
  • tape ^5.7.5
  • node >= 0.4

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.