<commit_before>//This is a simple command line todo list app
//Features
//-create todo item
//-list todo item
//-check todo item off list
//-delete todo item

var fs = require('fs');
var chroma = require('@v3rse/chroma');
var moment = require('moment');

//constants
var TASK_JSON_PATH = "./.database.json";


function init() {
	//create file if it's present.
	if (!fs.existsSync(TASK_JSON_PATH)) {
		console.log("Initialising storage.\n Creating `.database.json` file");
		setData({
			uncompleted: [],
			completed: []
		});
	}

}

function getData() {
	//read file contents
	var contents = fs.readFileSync(TASK_JSON_PATH);

	//parse contents
	var data = JSON.parse(contents);

	return data;
}


function setData(data) {
	//strigify JSON
	var dataString = JSON.stringify(data);

	//write to  file

	fs.writeFileSync(TASK_JSON_PATH, dataString);
}

//display usage
function usage() {
	console.log("Usage: done [add|check|delete|help] [task]");
	console.log("`task` is only a string when using `add` and a number\nfor all other commands.");
	console.log("Using the `done` without arguments lists all tasks");
}

//add task
function add(task) {
	//get data
	var data = getData();

	//add item to uncompleted
	data.uncompleted.push({
		task: task,
		dateCreated: Date.now()
	});

	//set data
	setData(data);

	//list
	list();
}

//check task
function check(task) {
	//get data
	var data = getData();

	//modify the data
	data.uncompleted[task].dateCompleted = Date.now();

	//add to completed tasks
	data.completed.push(
		data.uncompleted[task]
	);

	//remove from uncompleted
	data.uncompleted.splice(task, task + 1);

	//set data
	setData(data);

	//list
	list();
}

//delete task
function del(task) {
	//get data
	var data = getData();

	//delete item
	data.uncompleted.splice(task, task + 1);

	//set data
	setData(data);

	//list
	list();
}

//list all tasks
function list() {

	//data
	var data = getData();

	if (data.uncompleted.length || data.completed.length) {

		if (data.uncompleted.length) {
			//print the uncompleted list. using ANSI colors and formating
			console.log(chroma.underline.lyellow("Uncompleted Task list:"));
			data.uncompleted.forEach(function (task, index) {
				console.log(chroma.lyellow(index + 1 + "."), task.task + "\t" + chroma.italics.bgblue("Added " + moment(task.dateCreated).fromNow()));
			});<commit_msg>Clean up comments and make code more ADHD readable through spacing<commit_after>var fs = require('fs');
var chroma = require('@v3rse/chroma');
var moment = require('moment');
//Path to task json file
var TASK_JSON_PATH = "./.database.json";



//Creates a file for keeping track of tasks
function init() {
	//create file if it's present.
	if (!fs.existsSync(TASK_JSON_PATH)) {
		console.log("Initialising storage.\n Creating `.database.json` file");
		setData({
			uncompleted: [],
			completed: []
		});
	}

}



//Used to read some data from the JSON file
function getData() {
	//read file contents
	var contents = fs.readFileSync(TASK_JSON_PATH);

	//parse contents
	var data = JSON.parse(contents);

	return data;
}



//Used to write data to the JSON file
function setData(data) {
	// makes the object a JSON string
	var dataString = JSON.stringify(data);

	//write to  file
	fs.writeFileSync(TASK_JSON_PATH, dataString);
}



//Displays usage
function usage() {
	console.log("Usage: done [add|check|delete|help] [task]");
	console.log("`task` is only a string when using `add` and a number\nfor all other commands.");
	console.log("Using the `done` without arguments lists all tasks");
}



//Adds a task
function add(task) {
	//get data
	var data = getData();

	//add item to uncompleted
	data.uncompleted.push({
		task: task,
		dateCreated: Date.now()
	});

	//set data
	setData(data);

	//list
	list();
}



//Moves task from uncompleted task list to completed task list
function check(task) {
	//get data
	var data = getData();

	//modify the data
	data.uncompleted[task].dateCompleted = Date.now();

	//move to completed tasks
	data.completed.push(
		data.uncompleted[task]
	);

	//remove from uncompleted
	data.uncompleted.splice(task, task + 1);

	//set data
	setData(data);

	//list
	list();
}



//Remove uncompleted task from the list.
function del(task) {
	//get data
	var data = getData();

	//delete item
	data.uncompleted.splice(task, task + 1);

	//set data
	setData(data);

	//list
	list();
}




//Lists all tasks
function list() {

	//data
	var data = getData();

	if (data.uncompleted.length || data.completed.length) {

		if (data.uncompleted.length) {
			//print the uncompleted list. using ANSI colors and formating
			console.log(chroma.underline.lyellow("Uncompleted Task list:"));
			data.uncompleted.forEach(function (task, index) {
				console.log(chroma.lyellow(index + 1 + "."), task.task + "\t" + chroma.italics.bgblue("Added " + moment(task.dateCreated).fromNow()));
			});
{'fraction_non_alphanumeric': 0.1492383696994648, 'fraction_numerical': 0.0016467682173734047, 'mean_word_length': 3.6232159847764036, 'pattern_counts': {'":': 0, '<': 3, '<?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': '687359', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1608, 'n_words': 470}