Passed
Pull Request — master (#4)
by Yo
01:15
created

index.js (1 issue)

1
/*****************************************************************************************************************
2
 * @summary Simple parameter bag module, inspired by Symfony ParameterBag
3
 * @description ParameterBag provide Object oriented way to store key value pair
4
 *
5
 * @example <caption>Instantiation</caption>
6
 * const ParameterBag = require('parameterBag');
7
 * var bag = new ParameterBag();
8
 *
9
 * @example <caption>Setter</caption>
10
 *  bag.set('key', 'value');
11
 *
12
 * @example <caption>Getter</caption
13
 *  var myValue = bag.get('key');
14
 *****************************************************************************************************************/
15
16
/**
17
 * @constructor
18
 */
19
function ParameterBag() {
20
    this.store = new Array();
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
21
}
22
23
/**
24
 * @public
25
 * @param {string} key
26
 * @param {mixed}  data
27
 */
28
ParameterBag.prototype.set = function(key, data) {
29
    this.store[key] = data;
30
};
31
/**
32
 * @public
33
 * @param {string} key
34
 * @param {mixed}  defaultValue If value is undefined for the key, defaultValue will be returned
35
 *
36
 * @returns {mixed}
37
 */
38
ParameterBag.prototype.get = function (key, defaultValue) {
39
    var value = this.store[key];
40
    if ('undefined' == typeof(value)) {
41
        return defaultValue;
42
    }
43
44
    return value;
45
};
46
47
/**
48
 * @private
49
 * @type {Array}
50
 */
51
ParameterBag.prototype.store = null;
52
53
/* Export class */
54
module.exports = ParameterBag;
55