Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

collect.js

Package Overview
Dependencies
Maintainers
1
Versions
149
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

collect.js - npm Package Compare versions

Comparing version 3.0.52 to 3.1.0

25

dist/methods/flatMap.js
'use strict';
module.exports = function flatMap(fn) {
var _this = this;
var items = [];
var values = [];
this.items.forEach(function (childObject, index) {
var keys = Object.keys(childObject);
var values = [];
Object.keys(this.items).forEach(function (property) {
values.push(_this.items[property]);
});
keys.forEach(function (prop) {
values.push(childObject[prop]);
});
var newValues = fn(values);
var mapped = fn(values, index);
var collection = {};
var collection = {};
Object.keys(this.items).forEach(function (value, index) {
collection[value] = newValues[index];
keys.forEach(function (key, i) {
collection[key] = mapped[i];
});
items.push(collection);
});
return new this.constructor(collection);
return new this.constructor(Object.assign.apply(Object, items));
};

2

package.json
{
"name": "collect.js",
"version": "3.0.52",
"version": "3.1.0",
"description": "Convenient and dependency free wrapper for working with arrays and objects.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -455,7 +455,7 @@ # <img src="https://raw.githubusercontent.com/ecrmnn/collect.js/master/collectjs.jpg" alt="collect.js">

```js
const collection = collect({
name: 'Robbie Fowler',
nickname: 'The God',
position: 'Striker'
});
const collection = collect([
{ name: 'Robbie Fowler' },
{ nickname: 'The God' },
{ position: 'Striker' },
]);

@@ -462,0 +462,0 @@ const flatMapped = collection.flatMap(function (values) {

'use strict';
module.exports = function flatMap(fn) {
const values = [];
const items = [];
Object.keys(this.items).forEach((property) => {
values.push(this.items[property]);
});
this.items.forEach((childObject, index) => {
const keys = Object.keys(childObject);
const values = [];
const newValues = fn(values);
keys.forEach((prop) => {
values.push(childObject[prop]);
});
const collection = {};
const mapped = fn(values, index);
Object.keys(this.items).forEach((value, index) => {
collection[value] = newValues[index];
const collection = {};
keys.forEach((key, i) => {
collection[key] = mapped[i];
});
items.push(collection);
});
return new this.constructor(collection);
return new this.constructor(Object.assign(...items));
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc