-
Notifications
You must be signed in to change notification settings - Fork 3
/
di.js
53 lines (43 loc) · 838 Bytes
/
di.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Dependency Injection
*
* @author Mohammad Fares <[email protected]>
*/
var is = require('is_js');
/**
* Dependencies
* @type {Object}
*/
var dependency = {};
/**
* Get a specific dependency
*
* @param {String} key
* @return {Object|Null} return null if not found
*/
module.exports.get = function(key) {
// Not found
if (is.not.propertyDefined(dependency, key)) {
return null;
}
return dependency[key];
};
/**
* Set/Add a dependency
*
* @param {String} key
* @param {Object} value
*/
module.exports.set = function(key, value) {
dependency[key] = value;
module.exports[key] = value;
};
/**
* Check if a specific dependency exists
*
* @param {String} key
* @return {Boolean}
*/
module.exports.exists = function(key) {
return is.propertyDefined(dependency, key);
};