<commit_before>/** Minimal EventEmitter interface that is molded against the Node.js
 * EventEmitter interface. converted to typescript from https://github.com/primus/eventemitter3*/
class EventEmitter {

    /** Holds the assigned EventEmitters by name*/
    private _events = null;

    off = null;
    addListener = null;

    constructor() {
        // Alias methods names because people roll like that.
        this.off = this.removeListener;
        this.addListener = this.on;

    }

    /** Emit an event to all registered event listeners. */
    emit(event:string, a1:any, a2:any, a3:any, a4:any, a5:any):boolean {

        if (!this._events || !this._events[event]) return false;

        var listeners = this._events[event], len = arguments.length, args, i;

        if ('function' === typeof listeners.fn) {
            if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);

            if (len === 1) return listeners.fn.call(listeners.context), true;
            else if (len === 2) return listeners.fn.call(listeners.context, a1), true;
            else if (len === 3) return listeners.fn.call(listeners.context, a1, a2), true;
            else if (len === 4) return listeners.fn.call(listeners.context, a1, a2, a3), true;
            else if (len === 5) return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
            else if (len === 6) return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;

            for (i = 1, args = new Array(len - 1); i < len; i++) { args[i - 1] = arguments[i]; }

            listeners.fn.apply(listeners.context, args);
        } else {
            var length = listeners.length, j;

            for (i = 0; i < length; i++) {
                if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);

                if (len === 1) listeners[i].fn.call(listeners[i].context);
                if (len === 2) listeners[i].fn.call(listeners[i].context, a1);
                if (len === 3) listeners[i].fn.call(listeners[i].context, a1, a2);
                else if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) {
                    args[j - 1] = arguments[j];
                }

                listeners[i].fn.apply(listeners[i].context, args);
            }
        }

        return true;
    }

    /** Return a list of assigned event listeners.
     * @param event The events that should be listed.
     * @param exists We only need to know if there are listeners.
     */
    listeners(event:string, exists:boolean):Array<any> | boolean {
        var available:any = this._events && this._events[event];

        if (exists) return !!available;
        if (!available) return [];
        if (available.fn) return [available.fn];

        for (var i = 0, l = available.length, ee = new Array(l); i < l; i++) {
            ee[i] = available[i].fn;
        }

        return ee;
    }

    /**
     * Register a new EventListener for the given event.
     * @param event Name of the event.
     * @param fn Callback function.
     * @param [context=this] The context of the function.
     */
    on(event:string, fn:Function, context:any) {
        var listener = new EE(fn, context || this);

        if (!this._events) this._events = Object.create(null);
        if (!this._events[event]) this._events[event] = listener;
        else {
            if (!this._events[event].fn) this._events[event].push(listener);
            else this._events[event] = [this._events[event], listener];
        }

        return this;
    }

    /** Add an EventListener that's only called once.
     * @param event Name of the event.
     * @param {Function} fn Callback function.
     * @param [context=this] The context of the function.
     */
    once(event:string, fn, context:any) {
        var listener = new EE(fn, context || this, true);

        if (!this._events) this._events = Object.create(null);
        if (!this._events[event]) this._events[event] = listener;
        else {
            if (!this._events[event].fn) this._events[event].push(listener);
            else this._events[event] = [
                this._events[event], listener
            ];
        }

        return this;
    }

    /** Remove event listeners.
     * @param {String} event The event we want to remove.
     * @param {Function} fn The listener that we need to find.
     * @param context Only remove listeners matching this context.
     * @param {Boolean} once Only remove once listeners.
     */
    removeListener(event, fn, context:any, once) {

        if (!this._events || !this._events[event]) return this;

        var listeners = this._events[event]
            , events = [];

        if (fn) {
            if (listeners.fn) {
                if (
                    listeners.fn !== fn
                    || (once && !listeners.once)
                    || (context && listeners.context !== context)
                ) {
                    events.push(listeners);
                }
            } else {
                for (var i = 0, length = listeners.length; i < length; i++) {
                    if (
                        listeners[i].fn !== fn
                        || (once && !listeners[i].once)
                        || (context && listeners[i].context !== context)
                    ) {
                        events.push(listeners[i]);
                    }
                }
            }
        }

        // Reset the array, or remove it completely if we have no more listeners.
        if (events.length) this._events[event] = events.length === 1 ? events[0] : events;
        else delete this._events[event];

        return this;
    }

    /** Remove all listeners or only the listeners for the specified event.
     * @param {String} event The event want to remove all listeners for.
     */
    removeAllListeners(event:string) {
        if (!this._events) return this;

        if (event) delete this._events[event];
        else this._events = Object.create(null);

        return this;
    }


}

/** Representation of a single EventEmitter function. */
class EE {
    fn = null;
    context = null;
    once = false;

    constructor(fn:Function, context:any, once?:boolean){
        this.fn = fn;
        this.context = context;
        this.once = once || false;
    }
}

export = EventEmitter;<commit_msg>condense emitter code<commit_after>/** Minimal EventEmitter interface that is molded against the Node.js
 * EventEmitter interface. converted to typescript from https://github.com/primus/eventemitter3*/
class EventEmitter {
    /** Holds the assigned EventEmitters by name*/
    private _events = null;

    off = null;
    addListener = null;

    constructor() {
        // Alias methods names because people roll like that.
        this.off = this.removeListener;
        this.addListener = this.on;
    }

    /** Emit an event to all registered event listeners. */
    emit(event:string, a1:any, a2:any, a3:any, a4:any, a5:any):boolean {
        if (!this._events || !this._events[event]) return false;
        var listeners = this._events[event], len = arguments.length, args, i;
        if ('function' === typeof listeners.fn) {
            if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
            if (len === 1) return listeners.fn.call(listeners.context), true;
            else if (len === 2) return listeners.fn.call(listeners.context, a1), true;
            else if (len === 3) return listeners.fn.call(listeners.context, a1, a2), true;
            else if (len === 4) return listeners.fn.call(listeners.context, a1, a2, a3), true;
            else if (len === 5) return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
            else if (len === 6) return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
            for (i = 1, args = new Array(len - 1); i < len; i++) { args[i - 1] = arguments[i]; }
            listeners.fn.apply(listeners.context, args);
        } else {
            var length = listeners.length, j;
            for (i = 0; i < length; i++) {
                if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
                if (len === 1) listeners[i].fn.call(listeners[i].context);
                if (len === 2) listeners[i].fn.call(listeners[i].context, a1);
                if (len === 3) listeners[i].fn.call(listeners[i].context, a1, a2);
                else if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) { args[j - 1] = arguments[j]; }
                listeners[i].fn.apply(listeners[i].context, args);
            }
        }
        return true;
    }

    /** Return a list of assigned event listeners. event: The events that should be listed. exists: We only need to know if there are listeners. */
    listeners(event:string, exists:boolean):Array<any> | boolean {
        var available:any = this._events && this._events[event];
        if (exists) return !!available;
        if (!available) return [];
        if (available.fn) return [available.fn];
        for (var i = 0, l = available.length, ee = new Array(l); i < l; i++) {ee[i] = available[i].fn; }
        return ee;
    }

    /** Register a new EventListener for the given event. event: Name of the event. fn: Callback function. [context=this] The context of the function. */
    on(event:string, fn:Function, context:any) {
        var listener = new EE(fn, context || this);
        if (!this._events) this._events = Object.create(null);
        if (!this._events[event]) this._events[event] = listener;
        else {
            if (!this._events[event].fn) this._events[event].push(listener);
            else this._events[event] = [this._events[event], listener];
        }
        return this;
    }

    /** Add an EventListener that's only called once. event: Name of the event. fn: Callback function. [context=this] The context of the function. */
    once(event:string, fn:Function, context:any) {
        var listener = new EE(fn, context || this, true);
        if (!this._events) this._events = Object.create(null);
        if (!this._events[event]) this._events[event] = listener;
        else {
            if (!this._events[event].fn) this._events[event].push(listener);
            else this._events[event] = [this._events[event], listener];
        }
        return this;
    }

    /** Remove event listeners. event: The event we want to remove.   fn: The listener that we need to find.
     * cntxt: Only remove listeners matching this context.   once: Only remove once listeners.  */
    removeListener(event:string, fn:Function, cntxt:any, once:boolean) {
        if (!this._events || !this._events[event]) return this;
        var lstnrs = this._events[event], events = [];
        if (fn) {
            if (lstnrs.fn) {
                if (lstnrs.fn !== fn || (once && !lstnrs.once) || (cntxt && lstnrs.context !== cntxt)) events.push(lstnrs);
            } else {
                for (var i = 0, length = lstnrs.length; i < length; i++) {
                    if (lstnrs[i].fn !== fn || (once && !lstnrs[i].once) || (cntxt && lstnrs[i].context !== cntxt)) events.push(lstnrs[i]);
                }
            }
        }
        // Reset the array, or remove it completely if we have no more listeners.
        if (events.length) this._events[event] = events.length === 1 ? events[0] : events;
        else delete this._events[event];
        return this;
    }

    /** Remove all listeners or only the listeners for the specified event. event: The event want to remove all listeners for. */
    removeAllListeners(event:string) {
        if (!this._events) return this;
        if (event) delete this._events[event];
        else this._events = Object.create(null);
        return this;
    }
}

/** Representation of a single EventEmitter function. */
class EE {
    fn:Function = null; context:any = null; once:boolean = false;
    constructor(fn:Function, context:any, once?:boolean) {
        this.fn = fn; this.context = context; this.once = once || false;
    }
}
export = EventEmitter;
{'fraction_non_alphanumeric': 0.1343664990520155, 'fraction_numerical': 0.007254142280108812, 'mean_word_length': 2.1511688311688313, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3680305', 'n_tokens_mistral': 3572, 'n_tokens_neox': 3465, 'n_words': 1059}