Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Mixme is a utility library for deep merging of objects. It allows you to combine multiple objects into one, handling nested properties and arrays gracefully.
Deep Merge
This feature allows you to deeply merge two or more objects. Nested properties are merged recursively.
const mixme = require('mixme');
const obj1 = { a: 1, b: { c: 2 } };
const obj2 = { b: { d: 3 } };
const result = mixme.merge(obj1, obj2);
console.log(result); // { a: 1, b: { c: 2, d: 3 } }
Array Merge
This feature allows you to merge arrays within objects. The arrays are concatenated.
const mixme = require('mixme');
const obj1 = { a: [1, 2] };
const obj2 = { a: [3, 4] };
const result = mixme.merge(obj1, obj2);
console.log(result); // { a: [1, 2, 3, 4] }
Custom Merge Function
This feature allows you to provide a custom merge function to define how values should be combined.
const mixme = require('mixme');
const obj1 = { a: 1, b: 2 };
const obj2 = { a: 3, b: 4 };
const customMerge = (a, b) => a + b;
const result = mixme.merge(obj1, obj2, customMerge);
console.log(result); // { a: 4, b: 6 }
Lodash is a popular utility library that provides a wide range of functions for manipulating arrays, objects, and other data types. It includes a `merge` function similar to mixme's deep merge, but also offers many other utilities.
Deepmerge is a library specifically designed for deep merging of JavaScript objects. It is similar to mixme in its core functionality but focuses solely on merging, without additional utilities.
Merge is a simple utility for merging objects. It provides basic deep merge functionality but lacks some of the advanced features and customizability of mixme.
Merge multiple object recursively, with TypeScript support. The last object takes precedence over the previous ones. Only objects are merged. Arrays are overwritten.
The API is minimalist. The most popular functions are merge
, mutate
and is_object_literal
.
camelize(object)
Clone a object and convert its properties into snake case.
import { snake_case } from "mixme"
snake_case({aA: "1", bB: cC: "2"})
// Return {a_a: "1", b_b: c_c: "2"}
camelize_str(str)
Convert a camel case string to snake case, used internally by snake_case
.
import { snake_case_str } from "mixme";
snake_case("myValue");
// Return "my_value"
compare(item_1, item_2)
Compare two items and return true if their values match.
import { compare } from "mixme";
compare([{ a: 1 }], [{ a: 1 }]);
// Return true
compare({ a: 1 }, { a: 2 });
// Return false
clone(data)
It is possible to clone a literal object by simply calling mixme
with this object as the first argument. Use the clone
function in case you wish to clone any type of argument including arrays:
import { clone } from "mixme";
const target = clone(["a", "b"]);
// target is now a copy of source
is_object_literal(object)
Use the is_object_literal
function to ensure an object is literate.
import { is_object_literal } from "mixme";
// {} is literate
is_object_literal({});
// error is not literate
is_object_literal(new Error("Catch me"));
// Array is not literate
is_object_literal([]);
merge(...data)
The API is minimalist, Merge all literal object provided as arguments. This function is immutable, the source objects won't be altered.
import { merge } from "mixme";
const target = merge({ a: "1" }, { b: "2" });
// target is {a: "1", b: "2"}
mutate(...data)
Use the mutate
function to enrich an object. The first argument will be mutated:
import { mutate } from "mixme";
const source = { a: "1" };
const target = mutate(source, { b: "2" });
target.c = "3";
// source and target are both {a: "1", b: "2", c: "3"}
snake_case(object)
Clone a object and convert its properties into snake case.
import { snake_case } from "mixme"
snake_case({aA: "1", bB: cC: "2"})
// Return {a_a: "1", b_b: c_c: "2"}
snake_case_str(str)
Convert a camel case string to snake case, used internally by snake_case
.
import { snake_case_str } from "mixme";
snake_case("myValue");
// Return "my_value"
Create a new object from two objects:
import { merge } from "mixme";
const obj1 = { a_key: "a value", b_key: "b value" };
const obj2 = { b_key: "new b value" };
const result = merge(obj1, obj2);
assert.eql(result.b_key, "new b value");
Merge an existing object with a second one:
import { mutate } from "mixme";
const obj1 = { a_key: "a value", b_key: "b value" };
const obj2 = { b_key: "new b value" };
const result = mutate(obj1, obj2);
assert.eql(result, obj1);
assert.eql(obj1.b_key, "new b value");
Clone the repo, install the development dependencies and run the tests:
git clone http://github.com/wdavidw/node-mixme.git .
npm install
npm run test
To automatically generate a new version:
npm run release
Package publication is handled by the CI/CD with GitHub action.
Note:
This package is developed by Adaltas.
FAQs
A library for recursively merging JavaScript objects
The npm package mixme receives a total of 759,679 weekly downloads. As such, mixme popularity was classified as popular.
We found that mixme demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.