WIP
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const download = (data: string, name: string, ext: string) => {
|
||||
const download = (data: string | Blob, name: string, ext: string) => {
|
||||
const url = typeof data === "string" ? data : URL.createObjectURL(data);
|
||||
|
||||
const link = document.createElement("a");
|
||||
|
||||
40
src/utils/formatters.ts
Normal file
40
src/utils/formatters.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
const MONTHS = [
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December",
|
||||
];
|
||||
|
||||
const formatDate = (date: string) => {
|
||||
const [y, m, d] = date.split(".").map(Number);
|
||||
|
||||
const month = Number.isNaN(m) ? null : MONTHS[m - 1];
|
||||
const day = Number.isNaN(d) || month === null ? null : d;
|
||||
const year = Number.isNaN(y) ? null : y;
|
||||
|
||||
return month && day && year
|
||||
? `${month} ${day}, ${year}`
|
||||
: month && year
|
||||
? `${month} ${year}`
|
||||
: year
|
||||
? String(year)
|
||||
: "";
|
||||
};
|
||||
|
||||
const formatName = (name: string) => {
|
||||
return name
|
||||
.split(",")
|
||||
.map((x) => x.trim())
|
||||
.reverse()
|
||||
.join(" ");
|
||||
};
|
||||
|
||||
export { formatDate, formatName };
|
||||
15
src/utils/readFile.ts
Normal file
15
src/utils/readFile.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
const readFile = (file: Blob): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onload = () => {
|
||||
resolve(reader.result as string);
|
||||
};
|
||||
|
||||
reader.onerror = reject;
|
||||
|
||||
reader.readAsText(file);
|
||||
});
|
||||
};
|
||||
|
||||
export default readFile;
|
||||
Reference in New Issue
Block a user