node package manager
Don’t reinvent the wheel. Reuse code within your team. Create a free org »

emplace

node-emplace Travis-CI.org Build Status Coveralls.io Coverage Rating

Emplace objects and arrays - pointer to pointer style!

Example

var emplace = require('emplace');
 
var obj = {foo: 1234};
var obj2 = {bar: 'hello'};
 
emplace.replace(obj, obj2);
 
console.log(obj.foo); //-> undefined 
console.log(obj.bar); //-> hello 

API

.clear(obj)

Clears an object's properties in-place.

var obj = {foo: 1234};
 
emplace.clear(obj);
 
console.log('foo' in obj); //-> false 

.append(obj, otherObj)

Either appends an array, or merges two objects (overwriting duplicate keys).

var obj = {foo: 1234};
var obj2 = {bar: 'hello'};
 
emplace.append(obj, obj2);
 
console.log(obj.foo); //-> 1234 
console.log(obj.bar); //-> 'hello' 

.replace(obj, otherObj)

First .clears the object, then .appends to it.

See example.

License

Licensed under the MIT License. You can find a copy of it in LICENSE.