-
Notifications
You must be signed in to change notification settings - Fork 3
/
tools.ts
42 lines (42 loc) · 1.27 KB
/
tools.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { format } from "https://deno.land/std@0.117.0/datetime/mod.ts";
const meta = {
timestamp: ''
};
export const log = (...anything: any): string => {
if(meta.timestamp === ''){
meta.timestamp = format(new Date(), "HH:mm:ss");
console.log(meta.timestamp, '====================================');
}
if (anything.length > 2) {
console.log(anything[0], anything[1], anything[2]);
} else if (anything.length > 1) {
console.log(anything[0], anything[1]);
}else if(typeof anything[0] === "object" && anything[0].length > 100){
console.log(anything[0].slice(0, 10));
} else {
console.log(anything[0]);
}
return meta.timestamp;
};
export const logList = (list: any[]): string => {
const timestamp = format(new Date(), "HH:mm:ss");
console.log(timestamp);
list.forEach((item, index) => console.log(`[${index}]`, item));
return timestamp;
};
export const intval = (text_number: string): number => {
return parseInt(text_number);
};
export async function getPuzzleInput(): Promise<string | boolean> {
const input_filepath = "./input.txt";
try {
const saved_text = await Deno.readTextFile(input_filepath);
return saved_text;
} catch (error) {
console.log(error);
return false;
}
}
export function getEntriesFromInput(input: string): string[] {
return input.split("\n");
}