apache-autoindex-parse
Version:
parse apache's autoindex html files
45 lines • 1.68 kB
text/typescript
//#region src/index.d.ts
interface FileEntry {
type: "file";
name: string;
path: string;
lastModified?: number;
}
interface DirectoryEntry {
type: "directory";
name: string;
path: string;
lastModified?: number;
}
type Entry = FileEntry | DirectoryEntry;
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 {Entry[]} An array of entries representing the parsed directory structure, or empty array if parsing fails
*
* @example
* ```ts
* import { parse } from 'apache-autoindex-parse';
*
* const html = await fetch('http://example.com/files/').then(res => res.text());
* const result = parse(html);
* console.log(result); // Array of file and directory entries
* ```
*/
declare function parse(html: string, format?: AutoIndexFormat): Entry[];
/**
* Infers the AutoIndexFormat from HTML content.
*
* This function examines the links on the page to determine the format
* of an Apache AutoIndex page. It looks for URL parameters that indicate
* the format (e.g., "F=2" in "?C=N;O=D;F=2").
*
* @param {string} html - The HTML content to analyze
* @returns {AutoIndexFormat} The inferred format as an AutoIndexFormat string (e.g., "F0", "F1", "F2", etc.)
*/
declare function inferFormat(html: string): AutoIndexFormat;
//#endregion
export { inferFormat as a, FileEntry as i, DirectoryEntry as n, parse as o, Entry as r, AutoIndexFormat as t };