content-disposition
Version:
Create and parse Content-Disposition header
73 lines (72 loc) • 2.11 kB
TypeScript
/*!
* content-disposition
* Copyright(c) 2014-2017 Douglas Christopher Wilson
* MIT Licensed
*/
export interface ContentDisposition {
/**
* Content-Disposition type, such as "attachment" or "inline"
*/
type: string;
/**
* Content-Disposition parameters, such as "filename"
*/
parameters: Record<string, string>;
}
export interface CreateOptions {
/**
* Content-Disposition type, defaults to "attachment"
* @default "attachment"
*/
type?: string;
/**
* Fallback filename for non-US-ASCII strings. If true, a fallback will be generated by replacing non-US-ASCII characters with "?". If false, no fallback will be generated.
* @default true
*/
fallback?: string | boolean;
}
/**
* Create an attachment Content-Disposition header.
*/
export declare function create(filename?: string, options?: CreateOptions): string;
export interface ParseOptions {
/**
* Whether to decode RFC 8187 encoded parameters.
* @default true
*/
extended?: boolean;
/**
* Parse parameters as sent by browsers in `multipart/form-data`.
* @default false
*/
multipart?: boolean;
}
/**
* Parse Content-Disposition header string.
*/
export declare function parse(header: string, options?: ParseOptions): ContentDisposition;
/**
* Decode a RFC 8187 field value (gracefully).
*/
export declare function decodeExtended(str: string): string | undefined;
export interface FormatOptions {
/**
* Whether to use extended parameter encoding for non-ISO-8859-1 strings.
* If false, an error will be thrown when formatting such strings.
* @default true
*/
extended?: boolean;
/**
* Format parameters as sent by browsers in `multipart/form-data`.
* @default false
*/
multipart?: boolean;
}
/**
* Format object to Content-Disposition header.
*/
export declare function format(obj: Partial<ContentDisposition>, options?: FormatOptions): string;
/**
* Encode a Unicode string for HTTP (RFC 5987).
*/
export declare function encodeExtended(str: string): string;