{"size": 1205, "ext": "js", "max_stars_repo_path": "lib/calURLParse.js", "max_stars_repo_name": "calebgregory/cal.js", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/calURLParse.js", "max_issues_repo_name": "calebgregory/cal.js", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/calURLParse.js", "max_forks_repo_name": "calebgregory/cal.js", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 38.8709677419, "max_line_length": 92, "alphanum_fraction": 0.4340248963}
//                        TRANSFORMATION MAP
//
//   url route     =>   object                  =>   executable command
//
//   /cal/2015/1   =>   {year: 2015,month: 1}   =>   ./app.js 1 2015
//   /cal/1/2015   =>   {year: 2015,month: 1}   =>   ./app.js 1 2015
//   /cal/2015     =>   {year: 2015}            =>   ./app.js 2015
//   /cal          =>   {}                      =>   ./app.js

module.exports = function(route) {             // e.g., route = '/cal/1/2015'
  var cmd;
  route = route.split('/').slice(1);           // /cal/1/2015 => ['cal','1','2015']

  if (route[0] === 'cal') {
    cmd = './cal.js';
    route = route.slice(1);                    // route = ['1','2015']
  }

  var json = route.reduce(function(obj,arg) {
    if(isNaN(+arg)) cmd = null;                // return null if any input argument is NaN
    else if(arg<13) obj.month = arg;           // iteration 1 => { month : 1 }
    else obj.year = arg;                       // iteration 2 => { month : 1 , year : 2015 }
    return obj;
  },{});

  cmd += json.month ? ' ' + json.month : '';   // ./app.js 1
  cmd += json.year ? ' ' + json.year : '';     // ./app.js 1 2015

  return cmd.slice(0,4) === 'null' ? null : cmd;
}
