object-mutator
v0.0.2
Published
mutate objects based on rules
Downloads
4
Readme
mutator
🦑 mutate objects based on rules 🦑
const object1 = {
foo: 1,
bar: 1
};
const object2 = {
foo: 2,
bar: 2
};
const mutator = new Mutator();
mutator.addRule({
field: 'bar',
value: '2',
handler: (obj) => {
obj.foo = 3;
}
});
mutator.transform(object1); // object1.bar=1, so no transformation takes place
console.log(object1.foo);
// outputs 1
mutator.transform(object2); // object2.bar=2, so the transformation takes place
console.log(object2.foo);
// outputs 3