<commit_before>"use strict";

const _ = require( "lodash" );
const fs = require( "fs" );
const path = require( "path" );

const builtIn = getAdapters();

function defaultConstraint( config ) {
	return function levelConstraint( data ) {
		return data.level <= config.level;
	};
}

function getAdapters() {
	const adapterPath = path.resolve( __dirname, "./adapters" );
	const files = fs.readdirSync( adapterPath );
	return _.reduce( files, function( acc, file ) {
		acc[ file.split( "." )[ 0 ] ] = path.join( adapterPath, file );
		return acc;
	}, {} );
}

function timeFormatter( config, data ) {
	const time = config.timestamp;
	if ( time ) {
		if ( time.local ) {
			data.utc.local();
		}
		return data.utc.format( time.format || "YYYY-MM-DDTHH:mm:ss.SSSZ" );
	}
	return data.timestamp;

	// return config.timeformat ? data.raw.format( config.format ) : data.timestamp;
}

function wireUp( adapterFsm, config, channel, adapter ) {
	let init,
		topics;
	let handler = adapter.onLog;

	if ( _.isFunction( adapter.init ) ) {
		init = adapter.init();

		if ( init && init.then ) {
			adapterFsm.register( adapter, init );
			handler = adapterFsm.onLog.bind( adapterFsm, adapter );
		}
	}

	if ( config.topic && _.isArray( config.topic ) ) {
		topics = config.topic;
	} else {
		topics = ( config.topic || "#" ).split( "," );
	}
	const subscriptions = _.map( topics, function( topic ) {
		return channel
			.subscribe( topic, handler )
			.constraint( adapter.constraint || defaultConstraint( config ) );<commit_msg>Respond to pr review items<commit_after>"use strict";

const _ = require( "lodash" );
const fs = require( "fs" );
const path = require( "path" );

const builtIn = getAdapters();

function defaultConstraint( config ) {
	return function levelConstraint( data ) {
		return data.level <= config.level;
	};
}

function getAdapters() {
	const adapterPath = path.resolve( __dirname, "./adapters" );
	const files = fs.readdirSync( adapterPath );
	return _.reduce( files, function( acc, file ) {
		acc[ file.split( "." )[ 0 ] ] = path.join( adapterPath, file );
		return acc;
	}, {} );
}

function timeFormatter( config, data ) {
	const time = config.timestamp;
	if ( time ) {
		if ( time.local ) {
			data.utc.local();
		}
		return data.utc.format( time.format || "YYYY-MM-DDTHH:mm:ss.SSSZ" );
	}
	return data.timestamp;
}

function wireUp( adapterFsm, config, channel, adapter ) {
	let init, topics;
	let handler = adapter.onLog;

	if ( _.isFunction( adapter.init ) ) {
		init = adapter.init();

		if ( init && init.then ) {
			adapterFsm.register( adapter, init );
			handler = adapterFsm.onLog.bind( adapterFsm, adapter );
		}
	}

	if ( config.topic && _.isArray( config.topic ) ) {
		topics = config.topic;
	} else {
		topics = ( config.topic || "#" ).split( "," );
	}
	const subscriptions = _.map( topics, function( topic ) {
		return channel
			.subscribe( topic, handler )
			.constraint( adapter.constraint || defaultConstraint( config ) );
{'fraction_non_alphanumeric': 0.1565040650406504, 'fraction_numerical': 0.0006775067750677507, 'mean_word_length': 3.5782945736434106, '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': '3784662', 'n_tokens_mistral': 1039, 'n_tokens_neox': 973, 'n_words': 251}