<commit_before>function ajax(obj) {
    return new Promise(function (resolve, reject) {
        var data;
        var xhr = new XMLHttpRequest();

        obj.type = obj.type || 'GET';

        xhr.open(obj.type, obj.url, true);

        xhr.onreadystatechange = function() {
            if (this.readyState === 4) {
                if (this.status >= 200 && this.status < 400) {
                    resolve(JSON.parse(this.responseText));
                } else {
                    reject(this);
                }
            }
        };

        if (obj.type === 'POST') {
            xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
            data = JSON.stringify(obj.data);
            xhr.send(data);
        } else {
            xhr.send();
        }
    });
}

export default ajax;<commit_msg>Ajax util allows setting request headers<commit_after>function ajax(obj) {
    return new Promise((resolve, reject) => {
        var data;
        var xhr = new XMLHttpRequest();
        var headers = obj.headers || {};
        var header;

        obj.type = obj.type || 'GET';

        xhr.open(obj.type, obj.url, true);

        for (header in headers) {
            if (headers.hasOwnProperty(header)) {
                xhr.setRequestHeader(header, headers[header]);
            }
        }

        xhr.onreadystatechange = function() {
            if (this.readyState === 4) {
                if (this.status >= 200 && this.status < 400) {
                    resolve(JSON.parse(this.responseText));
                } else {
                    reject(this);
                }
            }
        };

        if (obj.type === 'POST') {
            xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
            data = JSON.stringify(obj.data);
            xhr.send(data);
        } else {
            xhr.send();
        }
    });
}

export default ajax;
{'fraction_non_alphanumeric': 0.13479623824451412, 'fraction_numerical': 0.008359456635318705, 'mean_word_length': 1.4741602067183464, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '757732', 'n_tokens_mistral': 567, 'n_tokens_neox': 524, 'n_words': 108}