0.9.4 • Published 10 years ago

manip v0.9.4

Weekly downloads
21
License
-
Repository
github
Last release
10 years ago

Manip

A library for manipulating nested data in a way reminiscent of MongoDB's "Update Operators" work (eg. $set, $unset, $push and $inc)".

The following operations are current supported:

  • $set
  • $unset
  • $push
  • $inc

Given a set of data, sometimes you want to be able to be able to modify deeply nested data without hard coding the path to that data or worring if the sub sub subdocument you want to add to already exists.

Take the following example:

var jack = {
	eyes: 'blue',
	car: {
		ford: {
			wheels: 4,
			age: 3,
			color: 'blue'
		}
	}
};

I could increase the age of the car by one year

manip(jack, {'$inc': {'car.ford.age': 1}}));

and now the data is:

{
	eyes: 'blue',
	car: {
		ford: {
			wheels: 4,
			age: 4,
			color: 'blue'
		}
	}
}

Source Code

Source code is prepared using Browserify which is also compatible with Node.JS. There is a UMD bundle which can be used with AMD or a vanilla browser (where it will export a global called manip.