<commit_before>import EventTarget from './EventTarget';


/**
 * removes angulars hashKey property from an object
 *
 * @param {Object} object the object to operate on
 *
 * @return {Object} the initial object
 */
let stripHashKey = function(object){
    if (Array.isArray(object)) {
        object = object.map(stripHashKey);

    } else {
        object = JSON.parse(JSON.stringify(object));

        Object.keys(object).forEach((key) => {
            if (key == '$$hashKey') {
                delete object[key];
            }else if (typeof object[key] === 'object' ) {
                object[key] = stripHashKey(object[key]);
            }
        });
    }

    return object;
};

/**
 * @lends module:NetworkRequest.NetworkRequest#
 */
let NetworkRequest = {
    /**
     * @private
     * @type {Object}
     */
    _body : {},

    /**
     * @private
     * @type {Object}
     */
    _headers : null,

    /**
     * @type {string}
     */
    type : '',

    /**
     * @type {string}
     */
    method : '',

    /**
     * @type {string}
     */
    url : '',

    /**
     * @type {function[]}
     * @private
     */
    _listeners : null,

	/**
	 * The constructor for the NetworkRequest. It simply sets up the properties.
	 *
	 * @constructs
	 *
	 * @param {string} url the url this request should be made to
	 * @param {Object} config addintional configuartion for the request
	 *
	 * @return {NetworkRequest} the request it self
	 */
    constructor (url, { method = 'GET', type = 'none' } = {}) {
        this.type = type;
        this.method = method;
        this._headers = {};
        this.url = url;
        this._listeners = [];

        return this;
    },

    /**
     * [_make description]
     *
     * @deprecated use the constructor
     * @param  {[type]} args [description]
     * @return {[type]}      [description]
     */
    _make(...args) {
        return this.constructor(...args);
    },

	/**
	 * this method will set the given object as the request body.
	 *
	 * @param {Object} data body data for this request
	 *
	 * @return {NetworkRequest} the request it self
	 */
    body : function(data){
        this._body = data;

        return this;
    },

	/**
	 * This method will set the request headers, in case custom headers are required.
	 *
	 * @param {Object} headers a object with all header properties for this request
	 *
	 * @return {NetworkRequest} the request it self
	 */
    headers : function(headers) {
        this._headers = headers;

        return this;
    },

    /**
     * Sets a single header for this request.
     *
     * @param {string} key the header key
     * @param {string} value the header value
     *
     * @return {NetworkRequest} the request it self
     */
    setHeader : function(key, value) {
        this._headers[key] = value;

        return this;
    },

    /**
     * sets a callback for when the request is ready
     *
     * @param {function} fn a callback function as soon as the data is ready
     *
     * @return {void}
     */
    onReady : function(fn){
        this._listeners.push(fn);
    },

	/**
	 * This will actually create the network connection and initiate the request.
	 *
	 * @return {Promise} resolves when the request is done
	 */
    send() {
        let self = this;
        let xhr = new XMLHttpRequest();

        if (this.method === 'GET' && this._body) {
            this.url += '?' + Object.keys(this._body).map((key) => {
                return `${key}=${self._body[key]}`;
            }).join('&');
        }

        xhr.open(this.method, this.url, true);

        let promise = new Promise((success, failure) => {
            xhr.onreadystatechange = () => {
                if (xhr.readyState === 4) {
                    if (xhr.status >= 200 && xhr.status < 300) {
                        let response = xhr.response;

                        if (xhr.getResponseHeader('Content-Type').indexOf('application/json') > -1 && typeof response  === 'string') {
                            response = JSON.parse(response);
                        }

                        this._listeners.forEach(fn => fn(xhr));

                        success(response);
                    } else {
                        failure(xhr);
                    }<commit_msg>add completed flag<commit_after>import EventTarget from './EventTarget';


/**
 * removes angulars hashKey property from an object
 *
 * @param {Object} object the object to operate on
 *
 * @return {Object} the initial object
 */
let stripHashKey = function(object){
    if (Array.isArray(object)) {
        object = object.map(stripHashKey);

    } else {
        object = JSON.parse(JSON.stringify(object));

        Object.keys(object).forEach((key) => {
            if (key == '$$hashKey') {
                delete object[key];
            }else if (typeof object[key] === 'object' ) {
                object[key] = stripHashKey(object[key]);
            }
        });
    }

    return object;
};

/**
 * @class
 * @augments EventTarget
 */
const NetworkRequest = {
    /**
     * @private
     * @type {Object}
     */
    _body : {},

    /**
     * @private
     * @type {Object}
     */
    _headers : null,

    /**
     * @type {string}
     */
    type : '',

    /**
     * @type {string}
     */
    method : '',

    /**
     * @type {string}
     */
    url : '',

    /**
     * @type {function[]}
     * @private
     */
    _listeners : null,

    /**
     * [completed description]
     *
     * @type {Boolean}
     */
    completed: false,

    /**
     * The constructor for the NetworkRequest. It simply sets up the properties.
     *
     * @constructs
     *
     * @param {string} url the url this request should be made to
     * @param {Object} config addintional configuartion for the request
     *
     * @return {NetworkRequest} the request it self
     */
    constructor (url, { method = 'GET', type = 'none' } = {}) {
        this.type = type;
        this.method = method;
        this._headers = {};
        this.url = url;
        this._listeners = [];

        return this;
    },

    /**
     * [_make description]
     *
     * @deprecated use the constructor
     * @param  {[type]} args [description]
     * @return {[type]}      [description]
     */
    _make(...args) {
        return this.constructor(...args);
    },

    /**
     * this method will set the given object as the request body.
     *
     * @param {Object} data body data for this request
     *
     * @return {NetworkRequest} the request it self
     */
    body : function(data){
        this._body = data;

        return this;
    },

    /**
     * This method will set the request headers, in case custom headers are required.
     *
     * @param {Object} headers a object with all header properties for this request
     *
     * @return {NetworkRequest} the request it self
     */
    headers : function(headers) {
        this._headers = headers;

        return this;
    },

    /**
     * Sets a single header for this request.
     *
     * @param {string} key the header key
     * @param {string} value the header value
     *
     * @return {NetworkRequest} the request it self
     */
    setHeader : function(key, value) {
        this._headers[key] = value;

        return this;
    },

    /**
     * sets a callback for when the request is ready
     *
     * @param {function} fn a callback function as soon as the data is ready
     *
     * @return {void}
     */
    onReady : function(fn){
        this._listeners.push(fn);
    },

    /**
     * This will actually create the network connection and initiate the request.
     *
     * @return {Promise} resolves when the request is done
     */
    send() {
        let self = this;
        let xhr = new XMLHttpRequest();

        if (this.method === 'GET' && this._body) {
            this.url += '?' + Object.keys(this._body).map((key) => {
                return `${key}=${self._body[key]}`;
            }).join('&');
        }

        xhr.open(this.method, this.url, true);

        let promise = new Promise((success, failure) => {
            xhr.onreadystatechange = () => {
                if (xhr.readyState === 4) {
                    if (xhr.status >= 200 && xhr.status < 300) {
                        let response = xhr.response;

                        if (xhr.getResponseHeader('Content-Type').indexOf('application/json') > -1 && typeof response  === 'string') {
                            response = JSON.parse(response);
                        }

                        this._listeners.forEach(fn => fn(xhr));

                        success(response);
                    } else {
                        failure(xhr);
                    }

                    this.completed = true;
{'fraction_non_alphanumeric': 0.13346228239845262, 'fraction_numerical': 0.0018204573899192173, 'mean_word_length': 1.6823314006713457, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '7112142', 'n_tokens_mistral': 2554, 'n_tokens_neox': 2428, 'n_words': 693}