Skip to content

Latest commit

 

History

History
46 lines (38 loc) · 1.35 KB

README.md

File metadata and controls

46 lines (38 loc) · 1.35 KB

immutable-merge-patch

An implementation of RFC 7396 (JSON Merge Patch) for Immutable.js Maps.

Thoroughly tested with full code coverage using Mocha and Istanbul.

Installation

npm install --save immutable-merge-patch

Usage

var Immutable = require("immutable");
var immutableMergePatch = require("immutable-merge-patch");

var a = Map({
	a: 1,
	b: 2,
	c: 3
});
var b = Map({
	a: 1,
	b: 5,
	c: "some string"
});

var diff = immutableMergePatch.generate(a, b);
// diff = Map { b: 5, c: "some string" }
var c = immutableMergePatch.apply(a, diff);
// c.equals(a) === true

Limitations / features not specified in RFC 7396

  • Non-string keys are currently totally ignored. (Have a reason for this to change? Open an issue and I'll consider it.)
  • The generate function only recurses into Immutable.Map objects, not plain JavaScript objects.
  • If the Maps passed into generate() are OrderedMaps, an OrderedMap is returned, with the keys inheriting their order from the first parameter where possible.

License

immutable-merge-patch is licensed under the MIT License.

P.S. It's also forthebadge. ;)