Add functions for loading the data and generating the date string.
This commit is contained in:
parent
bffd0dd6e0
commit
8c41b1832d
1 changed files with 41 additions and 0 deletions
41
src/utils.ts
Normal file
41
src/utils.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
//
|
||||||
|
// utils.ts
|
||||||
|
//
|
||||||
|
// Written by: Tyler Akins (2020/01/06)
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
import { readFileSync, writeFileSync } from "fs"
|
||||||
|
import { DATAFILE } from "./constants";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export const GET_FORMATTED_DATE = () => {
|
||||||
|
let date = new Date();
|
||||||
|
|
||||||
|
let year = date.getFullYear();
|
||||||
|
let month = date.getMonth() + 1;
|
||||||
|
let day = date.getDate();
|
||||||
|
|
||||||
|
return `${year}`
|
||||||
|
+ `-${month < 10 ? `0${month}` : month}`
|
||||||
|
+ `-${day < 10 ? `0${day}` : day}`
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export const LOAD_DATA = (): data => {
|
||||||
|
let buffer = readFileSync(DATAFILE);
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
return JSON.parse(buffer);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export const WRITE_DATA = (data: data) => {
|
||||||
|
writeFileSync(
|
||||||
|
DATAFILE,
|
||||||
|
JSON.stringify(data)
|
||||||
|
);
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue