<commit_before>var fs = require('fs');
var parse = require('fast-plist').parse;

var musicLibrayXmlFilename = process.argv[2];

if(!musicLibrayXmlFilename){
	console.error("usage: " + process.argv[0] + " " + process.argv[1] + ' <path to "iTunes Music Library.xml">');
	process.exit(1);
}

function escapeQuotes(s){
	return s.replace(/'/g, "''");
}

function formatOptional(track, keyName, isString){
	var value = track[keyName];
	if(!value){
		return 'NULL';
	}
	if(isString){
		return `'${escapeQuotes(value)}'`;
	}
	return value;
}

function formatLocation(location){
	return escapeQuotes(decodeURI(location).replace(/^.*iTunes Music\//g, ''));
}

function trackToSql(track){
	var trackTable = "tracks";
	var composer = formatOptional(track, 'Composer', true);
	var artist = formatOptional(track, 'Artist', true);

	return `INSERT INTO ${trackTable}(name, artist, file_size, total_time, year, composer, file_location) VALUES ('${escapeQuotes(track.Name)}', ${artist}, ${track["Size"]}, ${track["Total Time"]}, ${track["Year"]}, ${composer}, ${formatLocation(track.Location)});`;
}

function printKeys(obj){
	function formatKey(s){
		return `'\${track["${s}"]}'`
	}
	console.log(Object.keys(obj).map(formatKey).join(', '));
}

function printKinds(tracks){<commit_msg>Add function to format required values and refactor format optional function to use it<commit_after>var fs = require('fs');
var parse = require('fast-plist').parse;

var musicLibrayXmlFilename = process.argv[2];

if(!musicLibrayXmlFilename){
	console.error("usage: " + process.argv[0] + " " + process.argv[1] + ' <path to "iTunes Music Library.xml">');
	process.exit(1);
}

function escapeQuotes(s){
	return s.replace(/'/g, "''");
}

function formatRequired(value, isString){
	if(isString){
		return `'${escapeQuotes(value)}'`;
	}
	return value;
}

function formatOptional(track, keyName, isString){
	var value = track[keyName];
	if(!value){
		return 'NULL';
	}
	return formatRequired(value, isString);
}

function formatLocation(location){
	return escapeQuotes(decodeURI(location).replace(/^.*iTunes Music\//g, ''));
}

function trackToSql(track){
	var trackTable = "tracks";
	var composer = formatOptional(track, 'Composer', true);
	var artist = formatOptional(track, 'Artist', true);

	return `INSERT INTO ${trackTable}(name, artist, file_size, total_time, year, composer, file_location) VALUES ('${escapeQuotes(track.Name)}', ${artist}, ${track["Size"]}, ${track["Total Time"]}, ${track["Year"]}, ${composer}, ${formatLocation(track.Location)});`;
}

function printKeys(obj){
	function formatKey(s){
		return `'\${track["${s}"]}'`
	}
	console.log(Object.keys(obj).map(formatKey).join(', '));
}

function printKinds(tracks){
{'fraction_non_alphanumeric': 0.19480519480519481, 'fraction_numerical': 0.002968460111317254, 'mean_word_length': 6.50974930362117, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2420160', 'n_tokens_mistral': 925, 'n_tokens_neox': 902, 'n_words': 190}