<commit_before>//Loads Image and Audio assets that have been added.
function Loader() {
    'use strict';
    var assets = [];
    var loaded = 0;

    var files = [];

    var add = function(asset) {
        assets.push(asset);
    };

    /* parse
        Parses text to supported file type based on given file path.

        Supported types
            json - jQuery.parseJSON
            xml - $.xml2json plugin
    */
    var parse = function(filepath, data) {
        var types = {
            "json": $.parseJSON,
            "xml": $.xml2json,
            "oel": $.xml2json
        };

        for (var t in types) {
            var ext = filepath.slice(-t.length);
            if (ext === t) {
                return types[t](data);
            }
        }
    };

    return {
        image: function(src) {
            var newImage = new Image();
            newImage.src = src;
            add(newImage);
            return newImage;
        },

        audio: function(src) {
            var newAudio = new Audio();
            newAudio.src = src;
            add(newAudio);
            return newAudio;
        },

        file: function(id, path, callback) {
            files.push({
                id: id,
                path: path,
                callback: function(data) {
                    return callback(id, path, data);
                }
            });
        },

        //Call this when the document has been loaded. Specify a callback function to continue after the assets have been loaded.
        load: function(callback) {
            var loadComplete = function(cb) {
                loaded++;
                if (loaded >= (assets.length + files.length)) {
                    cb();
                }
            };

            for (var i=0; i<assets.length; i++) {
                if (assets[i] instanceof Image) {
                    $(assets[i]).load(function() {
                        loadComplete(callback);
                    });
                } else if (assets[i] instanceof Audio) {
                    $(assets[i]).on('canplay oncanplaythrough', function() {
                        loadComplete(callback);
                    });
                }
            }

            for (var i in files) {
                $.ajax({
                    url : files[i].path,
                    dataType: "text",
                    beforeSend: function(xhr, settings) {
                        // Store necessary file data in the xhr object
                        xhr.fileData = files[i];
                    }
                }).done(function(data, status, xhr) {
                    // Retrieve file data from xhr, parse loaded data
                    data = parse(xhr.fileData.path, data);
                    xhr.fileData.callback(data);
                    loadComplete(callback);
                });
            }
        }
    };
}
<commit_msg>Parse now returns raw data if filetype not supported<commit_after>//Loads Image and Audio assets that have been added.
function Loader() {
    'use strict';
    var assets = [];
    var loaded = 0;

    var files = [];

    var add = function(asset) {
        assets.push(asset);
    };

    /* parse
        Parses text to supported file type based on given file path.
        If file type not supported, returns plain text.

        Supported types
            json - jQuery.parseJSON
            xml - $.xml2json plugin
    */
    var parse = function(filepath, data) {
        var types = {
            "json": $.parseJSON,
            "xml": $.xml2json,
            "oel": $.xml2json
        };

        for (var t in types) {
            var ext = filepath.slice(-t.length);
            if (ext === t) {
                return types[t](data);
            }
        }
        
        return data;
    };

    return {
        image: function(src) {
            var newImage = new Image();
            newImage.src = src;
            add(newImage);
            return newImage;
        },

        audio: function(src) {
            var newAudio = new Audio();
            newAudio.src = src;
            add(newAudio);
            return newAudio;
        },

        file: function(id, path, callback) {
            files.push({
                id: id,
                path: path,
                callback: function(data) {
                    return callback(id, path, data);
                }
            });
        },

        //Call this when the document has been loaded. Specify a callback function to continue after the assets have been loaded.
        load: function(callback) {
            var loadComplete = function(cb) {
                loaded++;
                if (loaded >= (assets.length + files.length)) {
                    cb();
                }
            };

            for (var i=0; i<assets.length; i++) {
                if (assets[i] instanceof Image) {
                    $(assets[i]).load(function() {
                        loadComplete(callback);
                    });
                } else if (assets[i] instanceof Audio) {
                    $(assets[i]).on('canplay oncanplaythrough', function() {
                        loadComplete(callback);
                    });
                }
            }

            for (var i in files) {
                $.ajax({
                    url : files[i].path,
                    dataType: "text",
                    beforeSend: function(xhr, settings) {
                        // Store necessary file data in the xhr object
                        xhr.fileData = files[i];
                    }
                }).done(function(data, status, xhr) {
                    // Retrieve file data from xhr, parse loaded data
                    data = parse(xhr.fileData.path, data);
                    xhr.fileData.callback(data);
                    loadComplete(callback);
                });
            }
        }
    };
}

{'fraction_non_alphanumeric': 0.10153695225637671, 'fraction_numerical': 0.0016350555918901242, 'mean_word_length': 1.0322259136212624, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1720062', 'n_tokens_mistral': 1558, 'n_tokens_neox': 1425, 'n_words': 410}