From 13a934e427af3e4e3346151fea010efe10308496 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 18 Jan 2020 01:07:38 -0800 Subject: [PATCH] readme --- README.md | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++- package.json | 3 +++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bdf1fb3..fb6ffc8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,67 @@ -# Array.prototype.entries +# array.prototype.entries [![Version Badge][npm-version-svg]][package-url] + +[![Build Status][travis-svg]][travis-url] +[![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] + +[![npm badge][npm-badge-png]][package-url] + An ES2015 spec-compliant `Array.prototype.entries` shim/polyfill/replacement that works as far down as ES3. + +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/6.0/). + +Because `Array.prototype.entries` depends on a receiver (the “this” value), the main export takes the array to operate on as the first argument. + +## Example + +```js +var entries = require('array.prototype.entries'); +var assert = require('assert'); +var iterate = require('iterate-iterator'); + +assert.deepStrictEqual(iterate(entries([1, 2, 3])), [[0, 1], [1, 2], [2, 3]]); +assert.deepStrictEqual(iterate(entries([1, 0, 1])), [[0, 1], [1, 0], [2, 1]]); +assert.deepStrictEqual(iterate(entries([NaN])), [[0, NaN]]); +assert.deepStrictEqual(iterate(entries([1,,3])), [[0, 1], [1, undefined], [2, 3]]); +``` + +```js +var entries = require('array.prototype.entries'); +var assert = require('assert'); +/* when Array#entries is not present */ +delete Array.prototype.entries; +var shimmedMap = entries.shim(); +assert.deepStrictEqual(shimmedMap, entries.getPolyfill()); +assert.deepStrictEqual(iterate([1, 2, 3].entries()), [[0, 1], [1, 2], [2, 3]]); +assert.deepStrictEqual(iterate([1, 0, 1].entries()), [[0, 1], [1, 0], [2, 1]]); +assert.deepStrictEqual(iterate([NaN].entries()), [[0, NaN]]); +assert.deepStrictEqual(iterate([1,,3].entries()), [[0, 1], [1, undefined], [2, 3]]); +``` + +```js +var entries = require('array.prototype.entries'); +var assert = require('assert'); +/* when Array#entries is present */ +var shimmedMap = entries.shim(); +assert.equal(shimmedMap, Array.prototype.entries); +assert.deepStrictEqual(iterate([1, 2, 3].entries()), [[0, 1], [1, 2], [2, 3]]); +``` + +## Tests +Simply clone the repo, `npm install`, and run `npm test` + +[package-url]: https://npmjs.org/package/array.prototype.entries +[npm-version-svg]: http://versionbadg.es/es-shims/Array.prototype.entries.svg +[travis-svg]: https://travis-ci.org/es-shims/Array.prototype.entries.svg +[travis-url]: https://travis-ci.org/es-shims/Array.prototype.entries +[deps-svg]: https://david-dm.org/es-shims/Array.prototype.entries.svg +[deps-url]: https://david-dm.org/es-shims/Array.prototype.entries +[dev-deps-svg]: https://david-dm.org/es-shims/Array.prototype.entries/dev-status.svg +[dev-deps-url]: https://david-dm.org/es-shims/Array.prototype.entries#info=devDependencies +[npm-badge-png]: https://nodei.co/npm/array.prototype.entries.png?downloads=true&stars=true +[license-image]: https://img.shields.io/npm/l/array.prototype.entries.svg +[license-url]: LICENSE +[downloads-image]: https://img.shields.io/npm/dm/array.prototype.entries.svg +[downloads-url]: https://npm-stat.com/charts.html?package=array.prototype.entries diff --git a/package.json b/package.json index 6b32087..0b63c14 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "prepublish": "safe-publish-latest", "pretest": "npm run lint", + "prelint": "evalmd README.md", "lint": "eslint .", "test": "echo \"Error: no test specified\" && exit 1" }, @@ -39,6 +40,8 @@ "devDependencies": { "@ljharb/eslint-config": "^15.1.0", "eslint": "^6.8.0", + "evalmd": "^0.0.19", + "iterate-iterator": "^1.0.1", "safe-publish-latest": "^1.1.4" } }