{"size": 1558, "ext": "js", "max_stars_repo_path": "generatorsCommon.js", "max_stars_repo_name": "Durtur/npcgen", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "generatorsCommon.js", "max_issues_repo_name": "Durtur/npcgen", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "generatorsCommon.js", "max_forks_repo_name": "Durtur/npcgen", "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": 35.4090909091, "max_line_length": 81, "alphanum_fraction": 0.5905006418}

function replaceAll(string, replacementString, replaceArray) {
    while (string.indexOf(replacementString) > -1) {
        string = string.replace(replacementString, replaceArray.pickOne());
    }
    return string;

}


function replacePlaceholders(string, isMale, data) {
    if (!string) return;

    data.replacement_values.forEach(replacement => {
        var replWith = replacement.replace_with;

        if (Array.isArray(replWith)) {
            string = replaceAll(string, replacement.value, replWith);
        } else if (typeof replWith == "string") {
            if (isArrayReference(replWith)) {
                replWith = replWith.substring(6);
                var split = replWith.split(".");
                var replacementValue;
                split.forEach(splitV => { replacementValue = data[splitV] })

                if (replacementValue == null) return;
                string = replaceAll(string, replacement.value, replacementValue);
            }
        } else if (typeof replWith == "object") {

            if (isMale != null && replWith.male && replWith.female) {

                var replacementArr = isMale ? replWith.male : replWith.female;
                if (replacementArr[0] && isArrayReference(replacementArr[0]))
                    replacementArr = data[replacementArr[0].split(".")[1]];
                string = replaceAll(string, replacement.value, replacementArr);
            }
        }
    });
    return string;
    function isArrayReference(string) {
        return string.substring(0, 5) == "$this";
    }
}