{"size": 1536, "ext": "js", "max_stars_repo_path": "index.js", "max_stars_repo_name": "SC5/aws-lambda-info", "max_stars_repo_stars_event_min_datetime": "2015-09-26T03:30:57.000Z", "max_stars_repo_stars_event_max_datetime": "2015-09-26T03:30:57.000Z", "max_issues_repo_path": "index.js", "max_issues_repo_name": "SC5/aws-lambda-info", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "index.js", "max_forks_repo_name": "SC5/aws-lambda-info", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.2608695652, "max_line_length": 57, "alphanum_fraction": 0.6458333333}
 // name_version_stage
var nameDelimiter = '_';
var baseNamePos = 0;
var versionPos = -2; // second last element
var stagePos = -1; // last element
var testName = null;


function partElement(list, pos) {
    if (pos < 0) {
        // Negative indexes start from end
        pos = list.length + pos;
    }

    return list[pos];
}

var initFn = function(params) {
    if (params.hasOwnProperty('nameDelimiter')) {
        nameDelimiter = params.nameDelimiter;
    }
    if (params.hasOwnProperty('baseNamePos')) {
        baseNamePos = params.baseNamePos;
    }
    if (params.hasOwnProperty('versionPos')) {
        versionPos = params.versionPos;
    }
    if (params.hasOwnProperty('stagePos')) {
        stagePos = params.stagePos;
    }

    return module;
}

var getBaseNameFn = function() {
    var parts = getFunctionNameFn().split(nameDelimiter);

    return partElement(parts, baseNamePos);
}

var getFunctionNameFn = function() {
    return process.env.AWS_LAMBDA_FUNCTION_NAME;
} 

var getStageFn = function() {
    if (stagePos === null) {
        return '';
    }

    var parts = getFunctionNameFn().split(nameDelimiter);
    return partElement(parts, stagePos);
}

var getVersionFn = function() {
    if (versionPos === null) {
        return '';
    }
    var parts = getFunctionNameFn().split(nameDelimiter);
    return partElement(parts, versionPos);  
}

module.exports = exports = {
    init: initFn,
    fullName: getFunctionNameFn,
    baseName: getBaseNameFn,
    stage: getStageFn,
    version: getVersionFn
};
