<commit_before>'use strict';

function timeToMillis(timeString) {

	var matched = new RegExp('(\\d+)(.*)').exec(timeString),
		num = matched[1],
		period = matched[2] || 'ms',
		value = 0;

	switch(period) {
		case "ms":
			value = parseInt(num);
			break;
		case "s":
			value = parseInt(num)*1000;
			break;
		case "m":
			value = parseInt(num)*1000*60;
			break;
		case "h":
			value = parseInt(num)*1000*60*60;
			break;
		case "d":
			value = parseInt(num)*1000*60*60*24;
			break;
		default:
			value = parseInt(num);
	}

	return value;

}

function cacheKeytoStatsd(key) {
	key = key.replace(/\./g,'_');
	key = key.replace(/-/g,'_');
	key = key.replace(/:/g,'_');
	key = key.replace(/\//g,'_');
	return key;
}

function urlToCacheKey(url) {
	url = url.replace('http://','');
	url = cacheKeytoStatsd(url);
	return url;
}


module.exports = {
	timeToMillis: timeToMillis,
	urlToCacheKey: urlToCacheKey,
	cacheKeytoStatsd: cacheKeytoStatsd
};<commit_msg>Refactored helper function out into utils<commit_after>'use strict';

var _ = require('lodash');

function timeToMillis(timeString) {

	var matched = new RegExp('(\\d+)(.*)').exec(timeString),
		num = matched[1],
		period = matched[2] || 'ms',
		value = 0;

	switch(period) {
		case "ms":
			value = parseInt(num);
			break;
		case "s":
			value = parseInt(num)*1000;
			break;
		case "m":
			value = parseInt(num)*1000*60;
			break;
		case "h":
			value = parseInt(num)*1000*60*60;
			break;
		case "d":
			value = parseInt(num)*1000*60*60*24;
			break;
		default:
			value = parseInt(num);
	}

	return value;

}

function cacheKeytoStatsd(key) {
	key = key.replace(/\./g,'_');
	key = key.replace(/-/g,'_');
	key = key.replace(/:/g,'_');
	key = key.replace(/\//g,'_');
	return key;
}

function urlToCacheKey(url) {
	url = url.replace('http://','');
	url = cacheKeytoStatsd(url);
	return url;
}

function createTag(tagname, attribs) {
    var attribArray = [], attribLength = attribs.length, attribCounter = 0;
    _.forIn(attribs, function(value, key) {
        attribCounter++;
        attribArray.push(" " + key + "=\"" + value + "\"");
    });
    return ["<",tagname,(attribLength > 0 ? " " : "")].concat(attribArray).concat([">"]).join("");
}

module.exports = {
	timeToMillis: timeToMillis,
	urlToCacheKey: urlToCacheKey,
	cacheKeytoStatsd: cacheKeytoStatsd,
	createTag: createTag
};
{'fraction_non_alphanumeric': 0.194633730834753, 'fraction_numerical': 0.027257240204429302, 'mean_word_length': 3.7550607287449393, 'pattern_counts': {'":': 10, '<': 4, '<?xml version=': 0, '>': 5, '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': '2915203', 'n_tokens_mistral': 998, 'n_tokens_neox': 904, 'n_words': 175}