1.3.2 • Published 7 months ago

array.prototype.flatmap v1.3.2

Weekly downloads
6,099,932
License
MIT
Repository
github
Last release
7 months ago

array.prototype.flatmap Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

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

Getting started

npm install --save array.prototype.flatmap

Usage/Examples

var flatMap = require('array.prototype.flatmap');
var assert = require('assert');

var arr = [1, [2], [], 3];

var results = flatMap(arr, function (x, i) {
	assert.equal(x, arr[i]);
	return x;
});

assert.deepEqual(results, [1, 2, 3]);
var flatMap = require('array.prototype.flatmap');
var assert = require('assert');
/* when Array#flatMap is not present */
delete Array.prototype.flatMap;
var shimmedFlatMap = flatMap.shim();

var mapper = function (x) { return [x, 1]; };

assert.equal(shimmedFlatMap, flatMap.getPolyfill());
assert.deepEqual(arr.flatMap(mapper), flatMap(arr, mapper));
var flatMap = require('array.prototype.flatmap');
var assert = require('assert');
/* when Array#flatMap is present */
var shimmedIncludes = flatMap.shim();

var mapper = function (x) { return [x, 1]; };

assert.equal(shimmedIncludes, Array.prototype.flatMap);
assert.deepEqual(arr.flatMap(mapper), flatMap(arr, mapper));

Tests

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

eslint-plugin-importeslint-plugin-reacteslint-plugin-jsx-a11yairbnb-js-shimseasy-select-rnreact-native-bluetooth2killi8n-react-native-fast-imagevoid-mailreact-native-template-rfbaseairscanairscan-examplereact-native-esc-pos-sahaab@borisovart/atol-kkt-module@xavo/clideneme323112@ntt_app/react-native-custom-notificationreact-native-covid-sdkgql_din_modmutasi-bca@saeon/quick-formreact-native-printer-brothersreact-native-shekhar-bridge-testcogoportutilswilscanner@oiti/documentoscopy-react-nativequoc-test@saaspe/components@hexlantcontract/wizardexpand-react-bridgeopea-bootstraapluminos-ui-coresklif-ui-kitsklif-api@everything-registry/sub-chunk-1165jawwy-sdkjawwy_gamification_release@deepakorg/test@deepak757/testreact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkgp149-tablesklif-uimachinebeemrcapsreact-native-jawwy_sample@geeky-apo/react-native-advanced-clipboardkrondoleletherego932letsgoobraderlist-exportshighered-utilshoteakarvickytea93klosokhaled-salem-custom-componentskintilidin15lembah1leonardsinggihtea46ihza32is-well-known-symbolistanbul-mergejonbitco12joalvonsoanonsjohncarlonice21jp-gedenjordy-frijters-test-libjpearcey-eslint-plugin-react-safeminatonamikaze63moonwalkerswap-default-token-lists@maxxim/mxmilsmxmilsmyzallnka-gantt-task-reactnode-exports-infomtva-teleport-toolmtd-functionsmicroend-componentjulien-easy-modaljrennsoh88-react-native-scroll-indicatorintentalyzer-luis-integrationintentalyzer-tokenflow-integrationjusmelon204my-rizki-appnative-date-picker-modulenative-modal-damage-vehiclenative-kakao-loginnative-google-loginnative-apple-loginmy-library-buttonnew-awesome-4321menyalatea021mama-exporternovacap-componentsnpm_qwertynpm_one_12_34_1_npm_one_1_2_3npm_one_2_2mavectra
1.3.2

7 months ago

1.3.1

1 year ago

1.3.0

2 years ago

1.2.5

2 years ago

1.2.4

3 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago