source: imaps-frontend/node_modules/array.prototype.flatmap/README.md

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 3.1 KB
Line 
1# array.prototype.flatmap <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
2
3[![github actions][actions-image]][actions-url]
4[![coverage][codecov-image]][codecov-url]
5[![dependency status][deps-svg]][deps-url]
6[![dev dependency status][dev-deps-svg]][dev-deps-url]
7[![License][license-image]][license-url]
8[![Downloads][downloads-image]][downloads-url]
9
10[![npm badge][npm-badge-png]][package-url]
11
12An ES2019 spec-compliant `Array.prototype.flatMap` shim/polyfill/replacement that works as far down as ES3.
13
14This 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://tc39.es/ecma262/#sec-array.prototype.flatmap).
15
16Because `Array.prototype.flatMap` depends on a receiver (the `this` value), the main export takes the array to operate on as the first argument.
17
18## Getting started
19
20```sh
21npm install --save array.prototype.flatmap
22```
23
24## Usage/Examples
25
26```js
27var flatMap = require('array.prototype.flatmap');
28var assert = require('assert');
29
30var arr = [1, [2], [], 3];
31
32var results = flatMap(arr, function (x, i) {
33 assert.equal(x, arr[i]);
34 return x;
35});
36
37assert.deepEqual(results, [1, 2, 3]);
38```
39
40```js
41var flatMap = require('array.prototype.flatmap');
42var assert = require('assert');
43/* when Array#flatMap is not present */
44delete Array.prototype.flatMap;
45var shimmedFlatMap = flatMap.shim();
46
47var mapper = function (x) { return [x, 1]; };
48
49assert.equal(shimmedFlatMap, flatMap.getPolyfill());
50assert.deepEqual(arr.flatMap(mapper), flatMap(arr, mapper));
51```
52
53```js
54var flatMap = require('array.prototype.flatmap');
55var assert = require('assert');
56/* when Array#flatMap is present */
57var shimmedIncludes = flatMap.shim();
58
59var mapper = function (x) { return [x, 1]; };
60
61assert.equal(shimmedIncludes, Array.prototype.flatMap);
62assert.deepEqual(arr.flatMap(mapper), flatMap(arr, mapper));
63```
64
65## Tests
66Simply clone the repo, `npm install`, and run `npm test`
67
68[package-url]: https://npmjs.org/package/array.prototype.flatmap
69[npm-version-svg]: https://versionbadg.es/es-shims/Array.prototype.flatMap.svg
70[deps-svg]: https://david-dm.org/es-shims/Array.prototype.flatMap.svg
71[deps-url]: https://david-dm.org/es-shims/Array.prototype.flatMap
72[dev-deps-svg]: https://david-dm.org/es-shims/Array.prototype.flatMap/dev-status.svg
73[dev-deps-url]: https://david-dm.org/es-shims/Array.prototype.flatMap#info=devDependencies
74[npm-badge-png]: https://nodei.co/npm/array.prototype.flatmap.png?downloads=true&stars=true
75[license-image]: https://img.shields.io/npm/l/array.prototype.flatmap.svg
76[license-url]: LICENSE
77[downloads-image]: https://img.shields.io/npm/dm/array.prototype.flatmap.svg
78[downloads-url]: https://npm-stat.com/charts.html?package=array.prototype.flatmap
79[codecov-image]: https://codecov.io/gh/es-shims/Array.prototype.flatMap/branch/main/graphs/badge.svg
80[codecov-url]: https://app.codecov.io/gh/es-shims/Array.prototype.flatMap/
81[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/Array.prototype.flatMap
82[actions-url]: https://github.com/es-shims/Array.prototype.flatMap/actions
Note: See TracBrowser for help on using the repository browser.