UNPKG

@twocaretcat/astro-snapshot

Version:

An Astro integration for generating screenshots of your pages automatically at build time. Perfect for creating social images, content previews, dynamic icons, and more!

73 lines 2.67 kB
import type { Format } from './types.js'; import type { AstroIntegrationLogger } from 'astro'; /** * Extracts and normalizes the image format from a given file path. * * Determines the file extension following the last period (".") in the path, * ensuring it is part of the filename (not a directory). The function * normalizes certain extensions (e.g., `"jpg"` → `"jpeg"`) and validates * that the format is supported. * * @param path - The file path to extract the format from. * @returns The normalized image format as a {@link Format}. * * @throws {Error} If no valid file extension is found or the extension is unsupported. * * @example * ```ts * getFormat('/images/photo.jpg'); // 'jpeg' * getFormat('C:\\assets\\icon.webp'); // 'webp' * getFormat('file.png'); // 'png' * ``` */ export declare function getFormat(path: string): Format; /** * Checks if a file exists at the given path. * * @param path - The file path to check. * @returns A promise that resolves to `true` if the file exists, `false` otherwise. * * @example * ```ts * if (await fileExists('/path/to/file.png')) { * console.log('File exists'); * } * ``` */ export declare function fileExists(path: string): Promise<boolean>; /** * Logs a status message showing input/output file paths with optional warning. * * @param logger - The Astro integration logger instance to use for output * @param inputPath - The source file path to display * @param outputPath - The destination file path to display * @param warningLabel - Optional warning text to append. If provided, logs as warning in yellow; otherwise logs as info in green * * @example * ```ts * logStatus(logger, 'src/input.ts', 'dist/output.js'); * // Outputs (green): ▶ src/input.ts → dist/output.js * * logStatus(logger, 'src/input.ts', 'dist/output.js', 'skipped'); * // Outputs (yellow): ▶ src/input.ts → dist/output.js (skipped) * ``` */ export declare function logStatus(logger: AstroIntegrationLogger, inputPath: string, outputPath: string, warningLabel?: string): void; /** * Formats a duration in milliseconds as a human-readable string. * * Values under 1000ms are displayed as whole milliseconds (e.g., "53ms"). * Values 1000ms and above are displayed as seconds with one decimal place (e.g., "1.4s"). * * @param ms - The duration in milliseconds to format * @returns A formatted duration string with appropriate unit suffix * * @example * ```ts * formatDuration(53); // "53ms" * formatDuration(1400); // "1.4s" * formatDuration(5230); // "5.2s" * ``` */ export declare function formatDuration(ms: number): string; //# sourceMappingURL=utils.d.ts.map