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

deepmerge-ts

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deepmerge-ts

Deeply merge 2 or more objects respecting type information.

  • 7.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is deepmerge-ts?

The deepmerge-ts package is a TypeScript library designed to deeply merge two or more objects. It ensures type safety and is particularly useful for complex nested objects where shallow merging would not suffice.

What are deepmerge-ts's main functionalities?

Basic Deep Merge

This feature allows you to deeply merge two objects. In this example, obj1 and obj2 are merged such that the nested properties are combined.

const deepmerge = require('deepmerge-ts').default;
const obj1 = { a: 1, b: { c: 2 } };
const obj2 = { b: { d: 3 } };
const result = deepmerge(obj1, obj2);
console.log(result); // { a: 1, b: { c: 2, d: 3 } }

Array Merge

This feature allows you to merge arrays within objects. In this example, the arrays in obj1 and obj2 are concatenated.

const deepmerge = require('deepmerge-ts').default;
const obj1 = { a: [1, 2, 3] };
const obj2 = { a: [4, 5] };
const result = deepmerge(obj1, obj2);
console.log(result); // { a: [1, 2, 3, 4, 5] }

Custom Merge Function

This feature allows you to define custom merge functions for specific keys. In this example, the custom merge function concatenates arrays for the key 'a'.

const deepmerge = require('deepmerge-ts').default;
const customMerge = (key, options) => {
  if (key === 'a') {
    return (a, b) => a.concat(b);
  }
  return undefined;
};
const obj1 = { a: [1, 2, 3], b: { c: 2 } };
const obj2 = { a: [4, 5], b: { d: 3 } };
const result = deepmerge(obj1, obj2, { customMerge });
console.log(result); // { a: [1, 2, 3, 4, 5], b: { c: 2, d: 3 } }

Other packages similar to deepmerge-ts

Keywords

FAQs

Package last updated on 08 Oct 2024

Did you know?

Socket

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.

Install

Related posts

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