<commit_before>"use strict";

const TimeEvent = require("./timeEvent.js");
const uuidV4    = require('uuid/v4');
const globalRef = typeof window !== 'undefined' ? window : global;

module.exports = globalRef._purrrf =
function init(options) {
    
    /*
      option defaults
    */
    options = options || {};
    
    /*
      private
    */
    var push;
    var getMap;
    var getTime;
    var getTimeDiff;
    var setStart;
    var getStart;
    
    var purrrfQueueMap      = {};
    var openGroupMap        = {};
    var purrrfOrderedQueue  = [];
    
    var offset = 0;
    
    /*
      methods
    */
    push = function(name, group) {
        var newTime = new TimeEvent(name, group);
            
        purrrfQueueMap[name] = newTime;
        purrrfOrderedQueue.push(newTime);
        
        // if a group is passed and already exists in the group map, return the time difference from the last event pushed of the same group name
        if (typeof openGroupMap[group] !== 'undefined') {
            var eventReference = openGroupMap[group];
            openGroupMap[group] = name;
            
            return getTimeDiff(name, eventReference);
        }        
        if (typeof group !== 'undefined') {
            openGroupMap[group] = name;
        }
        
        return newTime.getTime() - offset;
    }
    
    setStart = function() {
        return offset = new TimeEvent().getTime();     
    }
    
    getStart = function() {
        return offset;
    }
    
    /* 
        Gets the execution time difference between event and event reference.
        If event reference is not passed OR is not in the map, the internal _start reference is used.
        
        @param event | type string | event name 
        @param eventReference | type string | event name of the reference
        
        return | type number | the float value in ms of the time difference between the events
    */
    getTimeDiff = function(event, eventReference) {
        if (typeof purrrfQueueMap[event] === 'undefined') { return false }    
        if (typeof purrrfQueueMap[eventReference] === 'undefined') { 
            // no reference passed, so simply return relative to the start reference
            return purrrfQueueMap[event].getTime() - offset;
        }
        
        return purrrfQueueMap[event].getTimeDiff(purrrfQueueMap[eventReference]);
    }
    
    getTime = function(event) {
        // if passed an array of time events
        if (typeof event === 'object' && typeof event.length !== 'undefined') {
            var len = event.length;
            var returnArr = [];
            
            for (var i = 0; i < len; i++) {
                if (typeof purrrfQueueMap[event[i]] === 'undefined') {
                    returnArr.push(false);
                }
                else {
                    returnArr.push(purrrfQueueMap[event[i]].getTime());
                }
            }
            
            return returnArr;    
        }
        
        // otherwise assume single time event
        if (typeof purrrfQueueMap[event] === 'undefined') { return false }
        
        return purrrfQueueMap[event].getTime() - offset;
    }
    
    
    /**
     * ### .assert(expression, message, negateMessage, expected, actual, showDiff)
     *
     * Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
     *
     * @name assert
     * @param {Philosophical} expression to be tested
     * @param {String|Function} message or function that returns message to display if expression fails
     * @param {Boolean} showDiff (optional) when set to `true`, assert will display a diff in addition to the message if expression fails
     * @api private
     */
    getMap = function(options) {
        
        if (options && options.ordered) {
            return purrrfOrderedQueue;
        }
        
        // special configs to return
        purrrfQueueMap['_config'] = {
            offset: offset
        };
        
        return purrrfQueueMap;
    }
    
    return {
        _id         : uuidV4(),
        push        : push,
        getMap      : getMap,
        getTime     : getTime,
        getTimeDiff : getTimeDiff,
        setStart    : setStart,
        getStart    : getStart
    }   
}();
<commit_msg>add jsdoc comments to purrrf functions<commit_after>"use strict";

const TimeEvent = require("./timeEvent.js");
const uuidV4    = require('uuid/v4');
const globalRef = typeof window !== 'undefined' ? window : global;

module.exports = globalRef._purrrf =
function init(options) {
    
    /*
      option defaults
    */
    options = options || {};
    
    /*
      private
    */
    var push;
    var getMap;
    var getTime;
    var getTimeDiff;
    var setStart;
    var getStart;
    
    var purrrfQueueMap      = {};
    var openGroupMap        = {};
    var purrrfOrderedQueue  = [];
    
    var offset = 0;
    
    
    /**
     * Pushes a new event to the master list
     * @param {String} name event name
     * @param {String} group group name used for grouping events of a similar type
     * @return {Number} Returns time since reference start of the event just created. If group is passed and it has been used on a previous pushed event, returns the time difference in ms between this event and the most recent event with the same group. If this is first time this group is passed, returns time in ms since reference start.
     */
    push = function(name, group) {
        var newTime = new TimeEvent(name, group);
            
        purrrfQueueMap[name] = newTime;
        purrrfOrderedQueue.push(newTime);
        
        // if a group is passed and already exists in the group map, return the time difference from the last event pushed of the same group name
        if (typeof openGroupMap[group] !== 'undefined') {
            var eventReference = openGroupMap[group];
            openGroupMap[group] = name;
            
            return getTimeDiff(name, eventReference);
        }        
        if (typeof group !== 'undefined') {
            openGroupMap[group] = name;
        }
        
        return newTime.getTime() - offset;
    }


    /**
     * Sets start reference time to now
     * @return {Number} Returns the start reference time in ms that was just set.
     */
    setStart = function() {
        return offset = new TimeEvent().getTime();     
    }


    /**
     * Gets current start reference time. Default is 0
     * @return {Number} Returns the current start reference time in ms.
     */
    getStart = function() {
        return offset;
    }
    

    /**
     * Gets the time difference in ms between event and event reference.
     * @param {String} event event name
     * @param {String} eventReference event name of the reference. If not passed, start reference is used
     * @return {Number|Boolean} Returns the time difference in ms between the events. Negative value indicates event occurred before eventReference. If event is not found in the master map, returns false.
     */
    getTimeDiff = function(event, eventReference) {
        if (typeof purrrfQueueMap[event] === 'undefined') { return false }    
        if (typeof purrrfQueueMap[eventReference] === 'undefined') { 
            // no reference passed, so simply return relative to the start reference
            return purrrfQueueMap[event].getTime() - offset;
        }
        
        return purrrfQueueMap[event].getTimeDiff(purrrfQueueMap[eventReference]);
    }


    /**
     * Gets time since reference start of an event 
     * @param {String|Array} event name of a single event || array of event names
     * @return {Number|Array|Boolean} Returns time in ms since reference start for a single event. If array is passed, returns array of times instead. If a single event is passed and is not in the master map, returns false.
     */
    getTime = function(event) {
        // if passed an array of time events
        if (typeof event === 'object' && typeof event.length !== 'undefined') {
            var len = event.length;
            var returnArr = [];
            
            for (var i = 0; i < len; i++) {
                if (typeof purrrfQueueMap[event[i]] === 'undefined') {
                    returnArr.push(false);
                }
                else {
                    returnArr.push(purrrfQueueMap[event[i]].getTime());
                }
            }
            
            return returnArr;    
        }
        
        // otherwise assume single time event
        if (typeof purrrfQueueMap[event] === 'undefined') { return false }
        
        return purrrfQueueMap[event].getTime() - offset;
    }
    
    
    /**
     * Gets the object map of all pushed events
     * @param {Object} options options to pass in
     * @return {Object|Array} Returns object map with event names as keys. If options.ordered is passed, returns an ordered array instead.
     */
    getMap = function(options) {
        
        if (options && options.ordered) {
            return purrrfOrderedQueue;
        }
        
        // special configs to return
        purrrfQueueMap['_config'] = {
            offset: offset
        };
        
        return purrrfQueueMap;
    }
    
    
    return {
        _id         : uuidV4(),
        push        : push,
        getMap      : getMap,
        getTime     : getTime,
        getTimeDiff : getTimeDiff,
        setStart    : setStart,
        getStart    : getStart
    }   
}();

{'fraction_non_alphanumeric': 0.08950682056663169, 'fraction_numerical': 0.001154249737670514, 'mean_word_length': 1.8561582259514533, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7167666', 'n_tokens_mistral': 2519, 'n_tokens_neox': 2493, 'n_words': 850}