26 lines
786 B
TypeScript
26 lines
786 B
TypeScript
|
import { readFile } from "fs/promises";
|
||
|
|
||
|
export type MenuItem = {
|
||
|
name: string;
|
||
|
HOT: number | null;
|
||
|
COLD: number | null;
|
||
|
category: string;
|
||
|
};
|
||
|
|
||
|
export const readMenu = async () => {
|
||
|
const file = await readFile('public/menu.csv', 'utf-8');
|
||
|
const [headersRaw, ...rows] = file.split('\n').map(row => row.trim()).filter(row => row.length > 0);
|
||
|
const headers = headersRaw.split(',').map(header => header.trim());
|
||
|
|
||
|
const data = rows.map(row => {
|
||
|
const items = row.split(',');
|
||
|
return {
|
||
|
name: items[0].trim(),
|
||
|
HOT: Number.parseFloat(items[1].trim()) || null,
|
||
|
COLD: Number.parseFloat(items[2].trim()) || null,
|
||
|
category: items[3].trim(),
|
||
|
} satisfies MenuItem;
|
||
|
});
|
||
|
return data;
|
||
|
};
|