apache-autoindex-parse
Version:
parse apache's autoindex html files
39 lines (37 loc) • 1.29 kB
text/typescript
interface FileEntry {
type: "file";
name: string;
path: string;
lastModified?: number;
}
interface DirectoryEntry {
type: "directory";
name: string;
path: string;
lastModified?: number;
children: Entry[];
}
type Entry = FileEntry | DirectoryEntry;
interface RootEntry {
type: "directory";
path: string;
children: Entry[];
}
type AutoIndexFormat = "F0" | "F1" | "F2";
/**
* Parses HTML content of an auto-indexed directory listing into a structured format.
*
* @param {string} html - The HTML content of the auto-indexed directory page to parse
* @param {AutoIndexFormat?} format - Optional format specification of the auto-index page (will be inferred if not provided)
* @returns {RootEntry | undefined} A RootEntry object representing the parsed directory structure, or null if parsing fails
*
* @example
* ```ts
* const html = await fetch('http://example.com/files/').then(res => res.text());
* const root = parse(html);
* console.log(root.path); // '/files/'
* console.log(root.children); // Array of file and directory entries
* ```
*/
declare function parse(html: string, format?: AutoIndexFormat): RootEntry | null;
export { type AutoIndexFormat, type DirectoryEntry, type Entry, type FileEntry, type RootEntry, parse };