This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@forcir/deep-merge
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Strongly-typed deep & recursive object merging

Continuous Integration

Install

Forcir's internal coding standards require version clamping so we've included an --exact flag. For your convenience we've placed that flag at the end so you can optionally omit copying it.

yarn add @forcir/deep-merge --exact

Usage

import { merge } from '@forcir/deep-merge';

const defaults = {
  foo: false,
  bar: false,
  baz: {
    collection: [1, 2],
  },
};

const overrides = {
  bar: true,
  baz: {
    collection: [3, 4],
  },
};

const merged = merge(defaults, overrides);
console.log(merged);

// {
//   foo: false,
//   bar: true,
//   baz: {
//     collection: [1, 2, 3, 4],
//   },
// };

Highlights, FAQs & Notable Details

A very fair first question you might have is why. The answer is somewhat organization-specific, but this code also has a change to benefit the TS/JS ecosystem more broadly, so we've chosen to open-source it in hopes that it solves the exact problem for others that we were facing.

This library exports a merge function that is the functional equivalent of the lodash _.defaultsDeep method. However, this library does not rely upon the use of eval which makes this library compliant with some defacto runtime standards like the Vercel Edge Runtime.

There are also a few notable details that push this library beyond other options published to NPM:

  • Written in TypeScript
  • Strongly Typed input and output
  • Client-side validated to throw errors if unsafe (modified) objects are provided
  • Strongly tested against all primitive types, object-like or manipulated plain objects.

Readme

Keywords

none

Package Sidebar

Install

npm i @forcir/deep-merge

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

9.67 kB

Total Files

6

Last publish

Collaborators

  • austinpaquette
  • forcirbot