UNPKG

4.34 kBTypeScriptView Raw
1/// <reference types="node" />
2
3import { IncomingMessage } from "http";
4
5declare namespace accepts {
6 interface Accepts {
7 /**
8 * Return the first accepted charset. If nothing in `charsets` is accepted, then `false` is returned.
9 * If no charsets are supplied, all accepted charsets are returned, in the order of the client's preference
10 * (most preferred first).
11 */
12 charset(): string[];
13 charset(charsets: string[]): string | false;
14 charset(...charsets: string[]): string | false;
15
16 /**
17 * Return the first accepted charset. If nothing in `charsets` is accepted, then `false` is returned.
18 * If no charsets are supplied, all accepted charsets are returned, in the order of the client's preference
19 * (most preferred first).
20 */
21 charsets(): string[];
22 charsets(charsets: string[]): string | false;
23 charsets(...charsets: string[]): string | false;
24
25 /**
26 * Return the first accepted encoding. If nothing in `encodings` is accepted, then `false` is returned.
27 * If no encodings are supplied, all accepted encodings are returned, in the order of the client's preference
28 * (most preferred first).
29 */
30 encoding(): string[];
31 encoding(encodings: string[]): string | false;
32 encoding(...encodings: string[]): string | false;
33
34 /**
35 * Return the first accepted encoding. If nothing in `encodings` is accepted, then `false` is returned.
36 * If no encodings are supplied, all accepted encodings are returned, in the order of the client's preference
37 * (most preferred first).
38 */
39 encodings(): string[];
40 encodings(encodings: string[]): string | false;
41 encodings(...encodings: string[]): string | false;
42
43 /**
44 * Return the first accepted language. If nothing in `languages` is accepted, then `false` is returned.
45 * If no languaes are supplied, all accepted languages are returned, in the order of the client's preference
46 * (most preferred first).
47 */
48 language(): string[];
49 language(languages: string[]): string | false;
50 language(...languages: string[]): string | false;
51
52 /**
53 * Return the first accepted language. If nothing in `languages` is accepted, then `false` is returned.
54 * If no languaes are supplied, all accepted languages are returned, in the order of the client's preference
55 * (most preferred first).
56 */
57 languages(): string[];
58 languages(languages: string[]): string | false;
59 languages(...languages: string[]): string | false;
60
61 /**
62 * Return the first accepted language. If nothing in `languages` is accepted, then `false` is returned.
63 * If no languaes are supplied, all accepted languages are returned, in the order of the client's preference
64 * (most preferred first).
65 */
66 lang(): string[];
67 lang(languages: string[]): string | false;
68 lang(...languages: string[]): string | false;
69
70 /**
71 * Return the first accepted language. If nothing in `languages` is accepted, then `false` is returned.
72 * If no languaes are supplied, all accepted languages are returned, in the order of the client's preference
73 * (most preferred first).
74 */
75 langs(): string[];
76 langs(languages: string[]): string | false;
77 langs(...languages: string[]): string | false;
78
79 /**
80 * Return the first accepted type (and it is returned as the same text as what appears in the `types` array). If nothing in `types` is accepted, then `false` is returned.
81 * If no types are supplied, return the entire set of acceptable types.
82 *
83 * The `types` array can contain full MIME types or file extensions. Any value that is not a full MIME types is passed to `require('mime-types').lookup`.
84 */
85 type(types: string[]): string[] | string | false;
86 type(...types: string[]): string[] | string | false;
87 types(types: string[]): string[] | string | false;
88 types(...types: string[]): string[] | string | false;
89 }
90}
91
92declare function accepts(req: IncomingMessage): accepts.Accepts;
93
94export = accepts;