Skip to content

Array.isArray spec-compliant polyfill

License

Notifications You must be signed in to change notification settings

es-shims/Array.isArray

Repository files navigation

array.isarray Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

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

Example

var isArray = require('array.isarray');
var assert = require('assert');

assert.equal(isArray([1, 2, 3]), true);
assert.equal(isArray({ length: 0 }), false);
var isArray = require('array.isarray');
var assert = require('assert');
/* when Array.isArray is not present */
delete Array.isArray;
var shimmed = isArray.shim();
assert.equal(shimmed, isArray.getPolyfill());
assert.equal(shimmed, Array.isArray);
assert.equal(isArray([1, 2, 3]), Array.isArray([1, 2, 3]));
var isArray = require('array.isarray');
var assert = require('assert');
/* when Array.isArray is present */
var shimmed = isArray.shim();
assert.equal(shimmed, Array.isArray);
assert.deepEqual(Array.isArray([1, 2, 3]), isArray([1, 2, 3]));

Tests

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