source: imaps-frontend/node_modules/relateurl/lib/options.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 845 bytes
Line 
1"use strict";
2
3var objUtils = require("./util/object");
4
5
6
7function 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
38function 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
57module.exports = getOptions;
Note: See TracBrowser for help on using the repository browser.