array.prototype.keys

1.1.3 • Public • Published

array.prototype.keys Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

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

Example

var keys = require('array.prototype.keys');
var assert = require('assert');
var iterate = require('iterate-iterator');

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

Tests

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

Package Sidebar

Install

npm i array.prototype.keys

Weekly Downloads

290

Version

1.1.3

License

MIT

Unpacked Size

23 kB

Total Files

15

Last publish

Collaborators

  • ljharb