tsmerge
Shallow object merge.
Last updated 9 years ago by jason-rev .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install tsmerge 
SYNC missed versions from official npm registry.

tsmerge

A shallow merge function that works nicely with typescript.

In the spirit of making things immutable, it is important to be able to merge objects together in an easy fashion.

In the ideal world, we could have a spread ... operator in typescript like the one supported by JSX:

const options = {...defaults, ...customizations};

which would copy all the fields in defaults and override with any custom fields from customizations.

The new ES6 Object.assign, does what we want, but has a strange syntax.

const options = Object.assign({}, defaults, customizations);

tsmerge is just a friendlier way of doing Object.assign.

Example:

import {merge} from 'tsmerge';
...

const options = merge(defaults, customizations);

Install:

npm install tsmerge --save

Usage:

import {merge} from 'tsmerge';

const defaults = { timeout: 30000, retries: 3 };
const customizations = { retries: 10 };
const options = merge(defaults, customizations);
console.log(options);  // output: { timeout: 30000, retries: 10 }

Current Tags

  • 1.0.4                                ...           latest (9 years ago)

3 Versions

  • 1.0.4                                ...           9 years ago
  • 1.0.1                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
Maintainers (1)
Downloads
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (3)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |