Skip to content

YaronKoresh/merge-objects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@yaronkoresh/merge-objects v3.0.0

A small tool for the community, made by: Yaron Koresh, Israel.

This project is licensed under MIT open-source license.

  • merge-objects utility, is a deep merging function.

  • An optional duplicates removal.

  • The source objects are NOT being changed (Objects are not being passed "by reference").

Example

// Require/Import this package

import "@yaronkoresh/merge-objects" // or: require("@yaronkoresh/merge-objects");

// Now you have a new global async function, called: "DeepMerge"

// First variable
let a = {
	a:{
		b: [1,2,3],
		c: {
			a:1,
			b:2
		}
	}
};

// Second variable
let b = {
	a:{
		b: [1,2,3],
		c: {
			a:2,
			b:2
		}
	}
};

// Third variable
let c = 4;

// Deep Merging while duplicates are included
const dup = await DeepMerge( "Dup", a, b, c );

// Deep Merging while duplicates are removed from arrays
// array with 1 element left, will not be returned as Array
const unq = await DeepMerge( "Unq", a, b, c );

console.log(dup);
// [
//	{
//		a:{
//			b: [1,2,3,1,2,3],
//			c: {
//				a: [1, 2],
//				b: [2, 2]
//			}
//		}
//	},
//	4
// ]

console.log(unq);
// [
//	{
//		a:{
//			b: [1,2,3],
//			c: {
//				a: [1, 2],
//				b: 2
//			}
//		}
//	},
//	4
// ]

The "DeepMerge" global async function, has a spesific syntax, of: action & parameter(s);

We have 2 actions:

Dup:

  • All object are being deeply merged & duplicates values are includes.

Unq:

  • All object are being deeply merged & duplicates values are removed (duplicates will be returned only 1 time).

Enjoy!

About

Deep merging chunks of data into a single set of data, could also remove duplicates.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published