//@ts-check import { isNotNull } from "./isNotNull.mjs"; /** * parses a filelist string. That's a string that looks like * ```md * name dd-mm-yyyy link name * name dd-mm-yyyy * name linkname * name * ``` * * @param {string} lines */ export const parseFileList = (lines) => // @ts-ignore lines .trim() .split(`\n`) .map((line, index) => { const today = new Date().toISOString().split("T")[0]; const result = line.match( /(?.+)\.(?\w{2,3})(?:\s+(?[\d-]+)?(?.+))?/ ); if (!result) { console.error(`could not parse line number ${index}`); return null; } const { // @ts-ignore groups: { name, ext, date = today, title = name }, } = result; const href = `/${name}.${ext}`; const date_unix = new Date(date).getTime(); return { name, href, date, title, date_unix, index }; }) .filter(isNotNull); export default parseFileList;