-
Notifications
You must be signed in to change notification settings - Fork 29
/
options-template.js
50 lines (38 loc) · 1.23 KB
/
options-template.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
'use strict';
var _;
_ = require('lodash');
/**
* Used for templating http options
* @param {object} Base options to be used in the template
*/
function OptionsTemplate (options) {
this._options = options || {};
if (!_.isObject(this._options) || _.isArray(this._options)) {
throw new Error('Options template must be initialized with an object');
}
}
/**
* Returns the current base object deeply extended (merged) by the extender, this does not modify
* the base object
* @param {object} Object whose properties will be added to the base object
* @return {object} POJO created by extending base object with extender
*/
OptionsTemplate.prototype.build = function (extender) {
var ext;
ext = extender || {};
if (!_.isObject(ext) || _.isArray(ext)) {
throw new Error('Extender must be an object');
}
return _.merge(_.cloneDeep(this._options), ext);
};
/**
* Replaces the base object of the template for a new one
* @param {object} new base object to be used
*/
OptionsTemplate.prototype.reset = function (options) {
this._options = options || {};
if (!_.isObject(this._options) || _.isArray(this._options)) {
throw new Error('Options template must be initialized with an object');
}
};
module.exports = OptionsTemplate;