File: utils.js

package info (click to toggle)
r-cran-webshot 0.5.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 600 kB
  • sloc: javascript: 5,565; makefile: 5
file content (28 lines) | stat: -rw-r--r-- 721 bytes parent folder | download | duplicates (4)
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
// Given an array of arguments like:
//   [ '--vwidth=800','--vheight=600','--cliprect=0,0,800,600' ]
// return an object like:
// { vwidth: '800', vheight: '600', cliprect: '0,0,800,600' }
exports.parseArgs = function(args) {
  opts = {};

  args.forEach(function(arg) {
    arg = arg.replace(/^--/, "");

    var eq_idx = arg.indexOf("=");
    var argname = arg.substring(0, eq_idx);
    var argvalue = arg.substring(eq_idx + 1);

    opts[argname] = argvalue;
  });

  return opts;
};

// Copy properties from object b that are not defined in object a into object a.
exports.fillMissing = function(a, b) {
  for (var i in b) {
    if (b.hasOwnProperty(i) && !a.hasOwnProperty(i))
      a[i] = b[i];
  }
  return a;
};