CoolFace
Apppublic

Umama-at-Bluchip/Quick-UI

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
1# array.prototype.flat <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.flat` 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 proposed [spec](https://tc39.github.io/proposal-flatMap/).15 16Because `Array.prototype.flat` depends on a receiver (the `this` value), the main export takes the array to operate on as the first argument.17 18## Getting started19 20```sh21npm install --save array.prototype.flat22```23 24## Usage/Examples25 26```js27var flat = require('array.prototype.flat');28var assert = require('assert');29 30var arr = [1, [2], [], 3, [[4]]];31 32assert.deepEqual(flat(arr, 1), [1, 2, 3, [4]]);33```34 35```js36var flat = require('array.prototype.flat');37var assert = require('assert');38/* when Array#flat is not present */39delete Array.prototype.flat;40var shimmedFlat = flat.shim();41 42assert.equal(shimmedFlat, flat.getPolyfill());43assert.deepEqual(arr.flat(), flat(arr));44```45 46```js47var flat = require('array.prototype.flat');48var assert = require('assert');49/* when Array#flat is present */50var shimmedIncludes = flat.shim();51 52var mapper = function (x) { return [x, 1]; };53 54assert.equal(shimmedIncludes, Array.prototype.flat);55assert.deepEqual(arr.flat(mapper), flat(arr, mapper));56```57 58## Tests59Simply clone the repo, `npm install`, and run `npm test`60 61[package-url]: https://npmjs.org/package/array.prototype.flat62[npm-version-svg]: https://versionbadg.es/es-shims/Array.prototype.flat.svg63[deps-svg]: https://david-dm.org/es-shims/Array.prototype.flat.svg64[deps-url]: https://david-dm.org/es-shims/Array.prototype.flat65[dev-deps-svg]: https://david-dm.org/es-shims/Array.prototype.flat/dev-status.svg66[dev-deps-url]: https://david-dm.org/es-shims/Array.prototype.flat#info=devDependencies67[npm-badge-png]: https://nodei.co/npm/array.prototype.flat.png?downloads=true&stars=true68[license-image]: https://img.shields.io/npm/l/array.prototype.flat.svg69[license-url]: LICENSE70[downloads-image]: https://img.shields.io/npm/dm/array.prototype.flat.svg71[downloads-url]: https://npm-stat.com/charts.html?package=array.prototype.flat72[codecov-image]: https://codecov.io/gh/es-shims/Array.prototype.flat/branch/main/graphs/badge.svg73[codecov-url]: https://app.codecov.io/gh/es-shims/Array.prototype.flat/74[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/Array.prototype.flat75[actions-url]: https://github.com/es-shims/Array.prototype.flat/actions76