UNPKG

apache-autoindex-parse

Version:
84 lines (83 loc) 3.04 kB
import { r as Entry, t as AutoIndexFormat } from "./index-CbQgiR6n.js"; //#region src/test-utils.d.ts interface GenerateHtmlOptions { /** * The title of the directory listing * @default "Index of /" */ title?: string; /** * Whether to include a parent directory link * @default true */ includeParent?: boolean; /** * Custom header content to include (like in unicode.org example) */ headerContent?: string; } /** * Generates HTML content for Apache-style directory index listings. * * This function creates HTML that mimics Apache's autoindex module output, * supporting different format types (F0, F1, F2) that correspond to different * Apache autoindex display styles. * * @param {Entry[]} entries - Array of directory entries to display in the listing * @param {AutoIndexFormat} format - The Apache autoindex format type ("F0", "F1", or "F2") * - F0: Simple unordered list format * - F1: Preformatted text with columns and icons * - F2: HTML table format with sortable columns * @param {GenerateHtmlOptions} options - Configuration options for the HTML generation * @returns {string} Complete HTML document string representing the directory index * * @example * ```typescript * import { generateAutoIndexHtml } from "apache-autoindex-parse/test-utils"; * * const entries = [ * { type: "directory", name: "docs", path: "docs/", lastModified: Date.now() }, * { type: "file", name: "README.md", path: "README.md", lastModified: Date.now() } * ]; * * const html = generateAutoIndexHtml(entries, "F1", { * title: "Index of /mydir", * includeParent: true * }); * ``` */ declare function generateAutoIndexHtml(entries: Entry[], format: AutoIndexFormat, options?: GenerateHtmlOptions): string; /** * Creates a sample array of directory entries for testing purposes. * * This utility function generates a predefined set of entries that includes * both directories and files with realistic timestamps. It's useful for * testing the Apache autoindex parsing functionality or generating sample * HTML outputs. * * @returns {Entry[]} An array of sample entries containing: * - Two directories: "docs" and "src" * - Two files: "README.md" and "package.json" * Each entry includes appropriate timestamps set to different times in the past * * @example * ```typescript * import { createSampleEntries, generateAutoIndexHtml } from "apache-autoindex-parse/test-utils"; * * const entries = createSampleEntries(); * const html = generateAutoIndexHtml(entries, "F1"); * console.log(html); // Outputs HTML with sample directory listing * ``` * * @example * ```typescript * // Use for testing parsing functionality * import { createSampleEntries } from "apache-autoindex-parse/test-utils"; * * const sampleData = createSampleEntries(); * // sampleData contains predefined entries for consistent testing * ``` */ declare function createSampleEntries(): Entry[]; //#endregion export { GenerateHtmlOptions, createSampleEntries, generateAutoIndexHtml };