array.prototype.flatmap
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -0,1 +1,10 @@ | ||
1.2.2 / 2019-10-10 | ||
================= | ||
* [Refactor] rename callback argument to `mapperFunction`, to match spec | ||
* [Deps] update `es-abstract`, `define-properties` | ||
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `covert`, `evalmd`, `object-inspect`, `safe-publish-latest`, `tape` | ||
* [meta] create FUNDING.yml | ||
* [Tests] up to `node` `v12.11`, `v11.15`, `v10.16`, `v9.11`, `v8.16`, `v6.17`, `v4.9`; use `nvm install-latest-npm` | ||
* [Tests] use `npx aud` instead of `nsp` or `npm audit` with hoops | ||
1.2.1 / 2018-02-23 | ||
@@ -2,0 +11,0 @@ ================= |
'use strict'; | ||
var ES = require('es-abstract/es2017'); | ||
var ES = require('es-abstract/es2019'); | ||
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || (Math.pow(2, 53) - 1); | ||
// eslint-disable-next-line max-params | ||
var FlattenIntoArray = function FlattenIntoArray(target, source, sourceLen, start, depth) { | ||
var targetIndex = start; | ||
var sourceIndex = 0; | ||
var mapperFunction; | ||
if (arguments.length > 5) { | ||
mapperFunction = arguments[5]; | ||
} | ||
while (sourceIndex < sourceLen) { | ||
var P = ES.ToString(sourceIndex); | ||
var exists = ES.HasProperty(source, P); | ||
if (exists) { | ||
var element = ES.Get(source, P); | ||
if (typeof mapperFunction !== 'undefined') { | ||
if (arguments.length <= 6) { | ||
throw new TypeError('Assertion failed: thisArg is required when mapperFunction is provided'); | ||
} | ||
element = ES.Call(mapperFunction, arguments[6], [element, sourceIndex, source]); | ||
} | ||
var shouldFlatten = false; | ||
if (depth > 0) { | ||
shouldFlatten = ES.IsArray(element); | ||
} | ||
if (shouldFlatten) { | ||
var elementLen = ES.ToLength(ES.Get(element, 'length')); | ||
targetIndex = FlattenIntoArray(target, element, elementLen, targetIndex, depth - 1); | ||
} else { | ||
if (targetIndex >= MAX_SAFE_INTEGER) { | ||
throw new TypeError('index too large'); | ||
} | ||
ES.CreateDataPropertyOrThrow(target, ES.ToString(targetIndex), element); | ||
targetIndex += 1; | ||
} | ||
} | ||
sourceIndex += 1; | ||
} | ||
return targetIndex; | ||
}; | ||
module.exports = function flatMap(callbackfn) { | ||
module.exports = function flatMap(mapperFunction) { | ||
var O = ES.ToObject(this); | ||
var sourceLen = ES.ToLength(ES.Get(O, 'length')); | ||
if (!ES.IsCallable(callbackfn)) { | ||
throw new TypeError('callback must be a function'); | ||
if (!ES.IsCallable(mapperFunction)) { | ||
throw new TypeError('mapperFunction must be a function'); | ||
} | ||
@@ -63,4 +19,4 @@ | ||
var A = ES.ArraySpeciesCreate(O, 0); | ||
FlattenIntoArray(A, O, sourceLen, 0, 1, callbackfn, T); | ||
ES.FlattenIntoArray(A, O, sourceLen, 0, 1, mapperFunction, T); | ||
return A; | ||
}; |
{ | ||
"name": "array.prototype.flatmap", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"author": { | ||
@@ -23,3 +23,3 @@ "name": "Jordan Harband", | ||
"test": "npm run --silent tests-only", | ||
"posttest": "npm run --silent security", | ||
"posttest": "npx aud --production", | ||
"pretests-only": "es-shim-api --bound", | ||
@@ -30,4 +30,3 @@ "tests-only": "npm run --silent test:shimmed && npm run --silent test:module", | ||
"coverage": "nyc npm run tests-only", | ||
"lint": "eslint test/*.js *.js", | ||
"security": "nsp check" | ||
"lint": "eslint test/*.js *.js" | ||
}, | ||
@@ -50,4 +49,4 @@ "repository": { | ||
"dependencies": { | ||
"define-properties": "^1.1.2", | ||
"es-abstract": "^1.10.0", | ||
"define-properties": "^1.1.3", | ||
"es-abstract": "^1.15.0", | ||
"function-bind": "^1.1.1" | ||
@@ -57,12 +56,11 @@ }, | ||
"@es-shims/api": "^2.1.2", | ||
"@ljharb/eslint-config": "^12.2.1", | ||
"covert": "^1.1.0", | ||
"eslint": "^4.18.1", | ||
"evalmd": "^0.0.17", | ||
"@ljharb/eslint-config": "^14.1.0", | ||
"covert": "^1.1.1", | ||
"eslint": "^6.5.1", | ||
"evalmd": "0.0.19", | ||
"foreach": "^2.0.5", | ||
"nsp": "^3.2.1", | ||
"nyc": "^10.3.2", | ||
"object-inspect": "^1.5.0", | ||
"safe-publish-latest": "^1.1.1", | ||
"tape": "^4.9.0" | ||
"object-inspect": "^1.6.0", | ||
"safe-publish-latest": "^1.1.3", | ||
"tape": "^4.11.0" | ||
}, | ||
@@ -69,0 +67,0 @@ "testling": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
10
23239
17
123
Updateddefine-properties@^1.1.3
Updatedes-abstract@^1.15.0