Debian Codegraph @

debian/build_modules/relateurl/lib/options.js

raw
1 "use strict";
2
3 var objUtils = require("./util/object");
4
5
6
7 function getOptions(options, defaults)
8 {
9 if ( objUtils.isPlainObject(options) )
10 {
11 var newOptions = {};
12
13 for (var i in defaults)
14 {
15 if ( defaults.hasOwnProperty(i) )
16 {
17 if (options[i] !== undefined)
18 {
19 newOptions[i] = mergeOption(options[i], defaults[i]);
20 }
21 else
22 {
23 newOptions[i] = defaults[i];
24 }
25 }
26 }
27
28 return newOptions;
29 }
30 else
31 {
32 return defaults;
33 }
34 }
35
36
37
38 function mergeOption(newValues, defaultValues)
39 {
40 if (defaultValues instanceof Object && newValues instanceof Object)
41 {
42 if (defaultValues instanceof Array && newValues instanceof Array)
43 {
44 return defaultValues.concat(newValues);
45 }
46 else
47 {
48 return objUtils.shallowMerge(newValues, defaultValues);
49 }
50 }
51
52 return newValues;
53 }
54
55
56
57 module.exports = getOptions;