common.ts 849 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import * as fs from "fs";
  2. import * as readline from "readline";
  3. import * as util from "util";
  4. export async function LoadInput(dayNumber: number): Promise<string[]> {
  5. const contents = [];
  6. const stream = fs.createReadStream(`./inputs/${dayNumber}.txt`, "utf8");
  7. const rl = readline.createInterface({
  8. input: stream,
  9. crlfDelay: Infinity,
  10. });
  11. for await (const line of rl) {
  12. contents.push(line);
  13. }
  14. return contents;
  15. }
  16. /**
  17. * Inspect a variable in the console
  18. *
  19. * @param {any} value A value to inspect
  20. */
  21. export function Inspect(value: any): void {
  22. console.log(util.inspect(value, { breakLength: Infinity, colors: true, depth: 256 }));
  23. }
  24. /**
  25. * Deep clone any input
  26. *
  27. * @param {any} value A value to clone
  28. * @returns A clone of the input
  29. */
  30. export function DeepClone(value: any): any {
  31. return JSON.parse(JSON.stringify(value));
  32. }