forked from pandres95/object-injector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·31 lines (27 loc) · 882 Bytes
/
index.js
File metadata and controls
executable file
·31 lines (27 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* @module object-injector
* @description Object Injector
* @author Pablo Andrés Dorado Suárez <pandres95@boolinc.co>
* @version 0.0.1
*/
'use strict';
var _ = require('underscore');
/**
* @function General Injector
* @desc Injects selected keys from an object into another object.
* @param {Object} injectee - Destination object. This is where properties of
* origin object are being injected.
* @param {Object} injecter - Origin object. Properties of this object will be
* injected into destination object.
* @param {Array} [keys] - Array of keys that are being injected.
*/
module.exports = function(injectee, injecter, keys){
var props = (_.isArray(keys) ?
_.intersection(Object.keys(injecter), keys) :
Object.keys(injecter)
);
_.each(props, function(key){
injectee[key] = injecter[key];
});
return injectee;
};