/** * Lightweight content negotiation utilities. * Replaces the `accepts` and `type-is` npm packages. * * Implements RFC 7231 quality-value parsing for Accept, Accept-Charset, * Accept-Encoding, and Accept-Language headers. */ export interface MediaType { type: string; subtype: string; quality: number; params: Record; } /** * Parse an Accept-style header into an array of {value, quality} pairs, * sorted by quality descending. * * Handles: * - `text/html, application/json;q=0.9` * - `gzip, deflate;q=0.5, *;q=0.1` * - `en-US, en;q=0.9, fr;q=0.8` */ export declare function parseAcceptHeader(header: string): Array<{ value: string; quality: number; params: Record; }>; /** * Parse a MIME type string into type and subtype. * * "application/json" → { type: "application", subtype: "json" } * "text/*" → { type: "text", subtype: "*" } */ export declare function parseMediaType(mediaType: string): { type: string; subtype: string; } | null; /** * Check if two MIME types match, supporting wildcards. * * matchMimeType("text/html", "text/*") → true * matchMimeType("application/json", "*​/*") → true * matchMimeType("text/html", "application/json") → false */ export declare function matchMimeType(actual: string, pattern: string): boolean; export declare function normalizeType(type: string): string; /** * Extract the base MIME type from a Content-Type header value. * * "application/json; charset=utf-8" → "application/json" */ export declare function extractMimeType(contentType: string): string; /** * Best-match content negotiation for Accept header. * * Given a list of types the server can produce, returns the best match * against the client's Accept header, or false if no match. * * accepts(acceptHeader, ["json", "html"]) → "json" | "html" | false */ export declare function negotiateAccept(acceptHeader: string | undefined, types: string[]): string | false; /** * Best-match negotiation for simple header values (charset, encoding, language). * * negotiateSimple(header, candidates) → best match or false */ export declare function negotiateSimple(header: string | undefined, candidates: string[], matchFn?: (candidate: string, entry: string) => boolean): string | false; /** * Language range matching (RFC 4647 basic filtering). * "en" matches "en", "en-US", "en-GB" * "en-US" matches "en-US" only */ export declare function languageMatch(candidate: string, entry: string): boolean; /** * Check if a Content-Type matches any of the given type patterns. * Implements type-is behavior. * * typeIs("application/json", ["json"]) → "json" * typeIs("text/html", ["html", "json"]) → "html" * typeIs("application/json", ["text/*"]) → false * typeIs(null, ["json"]) → false */ export declare function typeIs(contentType: string | undefined, types: string[]): string | false; //# sourceMappingURL=content-negotiation.d.ts.map