New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

group-objects-array

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

group-objects-array - npm Package Compare versions

Comparing version
1.0.3
to
1.0.6
+11
-4
package.json
{
"name": "group-objects-array",
"version": "1.0.3",
"version": "1.0.6",
"description": "Groups and merges array of objects by a single key.",

@@ -10,6 +10,9 @@ "main": "index.js",

"keywords": [
"objects",
"group",
"object",
"array",
"key",
"group"
"merge",
"unique",
"deduplicated"
],

@@ -25,3 +28,7 @@ "author": "Jana Rangasamy <janagr7@gmail.com>",

"url": "https://github.com/grjan7/group-objects-array/issues"
}
},
"files": [
"index.js",
"lib/"
]
}
# group-objects-array
Groups JavaScript objects array by a key and returns grouped array.
[![NPM version](https://img.shields.io/npm/v/group-objects-array.svg)](https://www.npmjs.com/package/group-objects-array)
[![NPM downloads](https://img.shields.io/npm/dm/group-objects-array.svg)](https://www.npmjs.com/package/group-objects-array)
[![Known Vulnerabilities](https://snyk.io/test/github/grjan7/group-objects-array/badge.svg)](https://snyk.io/test/github/grjan7/group-objects-array)
## Summary
## Description
Groups the scattered objects in an array based on a `groupByKey` (e.g. id). For the given `groupByKey` value, if there is a multiple occurrence of same key (e.g., contact key for id: 3) but with unique values, then the values will be grouped into an array.
> Groups JavaScript objects array by a key and returns grouped array.
> Groups the scattered objects in an array based on a `groupByKey` (e.g. id). For the given `groupByKey` value, if there is a multiple occurrence of same key (e.g., contact key for id: 3) but with unique values, then the values will be grouped into an array.
## Installation

@@ -10,0 +14,0 @@

'use strict';
const { groupObjectArrayByKey } = require('../index.js');
let objArray = [
{ id: 1, name: "John" },
{ id: 2, name: "Aaron" },
{ id: 1, age: 20 },
{ id: 2, age: 30 },
{ id: 3, name: "Michel" },
{ id: 1, address: { street: "123 Main Street", city: "NY", country: "USA" } },
{ id: 3, contact: "+01-51245 53125" },
{ id: 3, contact: "+02-51245 53125" },
{ id: 1, address: { street: "123 Main Street", city: "NY", country: "USA" } }
];
console.log(groupObjectArrayByKey(objArray, "id"));
'use strict';
const deduplicateObjectValues = require("../../lib/util/deduplicateObjectValues");
let obj = {
id: [1, 1, 1],
name: ["John"],
age: [30],
address: [
{ street: "123 Main Street", city: "NY", country: "USA" },
{ street: "123 Main Street", city: "NY", country: "USA" }
]
}
console.log(deduplicateObjectValues(obj));
'use strict';
const flattenArray = require("../../lib/util/flattenArray");
//Example 1:
let arr = [1, 2, [3, 4, 5]];
console.log(flattenArray(arr));
//Example 2:
arr = [[1, [2, 3]], 4, 5];
console.log(flattenArray(arr));
'use strict';
const isItemInArray = require("../../lib/util/isItemInArray");
//Example 1:
let arr = ["a", "b", "c"];
console.log(isItemInArray(arr, "a")); // returns true
//Example 2:
arr = ["hello", "world"];
console.log(isItemInArray(arr, "Hello")); // returns false
//Example 3:
arr = [{ name: "John" }, "world"];
console.log(isItemInArray(arr, { name: "John" })); // returns true
'use strict';
const isObject = require("../../lib/util/isObject");
console.log(isObject("Hello")); // returns false
console.log(isObject(40)); // returns false
console.log(isObject({})); // returns true
console.log(isObject({ name: "Rocky" })); // returns true
console.log(isObject([{}])); // returns false
console.log(isObject(["a"])); // returns false
console.log(isObject(null)); // returns false
console.log(isObject(undefined)); // returns false
console.log(isObject(false)); // returns false
'use strict';
const isObjectArray = require("../../lib/util/isObjectArray");
let item = [{}];
console.log(isObjectArray(item)); // returns true
item = [{ id: 1, name: "Aaron" }, { id: 1, age: 30 }];
console.log(isObjectArray(item)); // returns true
item = [{}, "hello", 40];
console.log(isObjectArray(item)); // returns false
item = "Hello";
console.log(isObjectArray(item)); // returns false
item = 40;
console.log(isObjectArray(item)); // returns false
item = [];
console.log(isObjectArray(item)); // returns false
'use strict';
const mergeTwoObjects = require("../../lib/util/mergeTwoObjects");
//Example 1:
let obj1 = { name: "John", age: 20 };
let obj2 = { name: "Doe", age: 30 };
console.log(mergeTwoObjects(obj1, obj2));
//Example 2:
obj1 = { name: "John", age: 20 };
obj2 = { address: "123 Main Street, NY, USA", phone: "+1-124552 124523" };
console.log(mergeTwoObjects(obj1, obj2));
'use strict';
const uniqueArray = require("../../lib/util/uniqueArray");
let arr = ["a", "b", "c", "a", "c", "b"];
console.log(uniqueArray(arr));
arr = [40, 10, "hello", "world", 40, "hello"];
console.log(uniqueArray(arr));
arr = [{ name: "John", age: 30 }, { name: "Doe", age: 29 }, { name: "John", age: 30 }, { name: "Michel", age: 21 }];
console.log(uniqueArray(arr));
'use strict';
const unwindArray = require("../../lib/util/unwindArray");
let arr = ["a", "b"];
console.log(unwindArray(arr));
arr = [{ name: "John", age: 30 }];
console.log(unwindArray(arr));
arr = ["a"];
console.log(unwindArray(arr));
arr = [44];
console.log(unwindArray(arr));
arr = [['a', 'b']];
console.log(unwindArray(arr));