@remix-run/headers
Version:
A toolkit for working with HTTP headers in JavaScript
75 lines • 2.94 kB
TypeScript
import { type HeaderValue } from './header-value.ts';
export type AcceptInit = Iterable<string | [string, number]> | Record<string, number>;
/**
* The value of a `Accept` HTTP header.
*
* [MDN `Accept` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept)
*
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2)
*/
export declare class Accept implements HeaderValue, Iterable<[string, number]> {
#private;
constructor(init?: string | AcceptInit);
/**
* An array of all media types in the header.
*/
get mediaTypes(): string[];
/**
* An array of all weights (q values) in the header.
*/
get weights(): number[];
/**
* The number of media types in the `Accept` header.
*/
get size(): number;
/**
* Returns `true` if the header matches the given media type (i.e. it is "acceptable").
* @param mediaType The media type to check.
* @returns `true` if the media type is acceptable, `false` otherwise.
*/
accepts(mediaType: string): boolean;
/**
* Gets the weight of a given media type. Also supports wildcards, so e.g. `text/*` will match `text/html`.
* @param mediaType The media type to get the weight of.
* @returns The weight of the media type.
*/
getWeight(mediaType: string): number;
/**
* Returns the most preferred media type from the given list of media types.
* @param mediaTypes The list of media types to choose from.
* @returns The most preferred media type or `null` if none match.
*/
getPreferred(mediaTypes: string[]): string | null;
/**
* Returns the weight of a media type. If it is not in the header verbatim, this returns `null`.
* @param mediaType The media type to get the weight of.
* @returns The weight of the media type, or `null` if it is not in the header.
*/
get(mediaType: string): number | null;
/**
* Sets a media type with the given weight.
* @param mediaType The media type to set.
* @param weight The weight of the media type. Defaults to 1.
*/
set(mediaType: string, weight?: number): void;
/**
* Removes the given media type from the header.
* @param mediaType The media type to remove.
*/
delete(mediaType: string): void;
/**
* Checks if a media type is in the header.
* @param mediaType The media type to check.
* @returns `true` if the media type is in the header (verbatim), `false` otherwise.
*/
has(mediaType: string): boolean;
/**
* Removes all media types from the header.
*/
clear(): void;
entries(): IterableIterator<[string, number]>;
[Symbol.iterator](): IterableIterator<[string, number]>;
forEach(callback: (mediaType: string, weight: number, header: Accept) => void, thisArg?: any): void;
toString(): string;
}
//# sourceMappingURL=accept.d.ts.map