UNPKG

4.62 kBTypeScriptView Raw
1// Type definitions for accepts 1.3
2// Project: https://github.com/jshttp/accepts
3// Definitions by: Stefan Reichel <https://github.com/bomret>
4// Brice BERNARD <https://github.com/brikou>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6
7/// <reference types="node" />
8
9import { IncomingMessage } from "http";
10
11declare namespace accepts {
12 interface Accepts {
13 /**
14 * Return the first accepted charset. If nothing in `charsets` is accepted, then `false` is returned.
15 * If no charsets are supplied, all accepted charsets are returned, in the order of the client's preference
16 * (most preferred first).
17 */
18 charset(): string[];
19 charset(charsets: string[]): string | false;
20 charset(...charsets: string[]): string | false;
21
22 /**
23 * Return the first accepted charset. If nothing in `charsets` is accepted, then `false` is returned.
24 * If no charsets are supplied, all accepted charsets are returned, in the order of the client's preference
25 * (most preferred first).
26 */
27 charsets(): string[];
28 charsets(charsets: string[]): string | false;
29 charsets(...charsets: string[]): string | false;
30
31 /**
32 * Return the first accepted encoding. If nothing in `encodings` is accepted, then `false` is returned.
33 * If no encodings are supplied, all accepted encodings are returned, in the order of the client's preference
34 * (most preferred first).
35 */
36 encoding(): string[];
37 encoding(encodings: string[]): string | false;
38 encoding(...encodings: string[]): string | false;
39
40 /**
41 * Return the first accepted encoding. If nothing in `encodings` is accepted, then `false` is returned.
42 * If no encodings are supplied, all accepted encodings are returned, in the order of the client's preference
43 * (most preferred first).
44 */
45 encodings(): string[];
46 encodings(encodings: string[]): string | false;
47 encodings(...encodings: string[]): string | false;
48
49 /**
50 * Return the first accepted language. If nothing in `languages` is accepted, then `false` is returned.
51 * If no languaes are supplied, all accepted languages are returned, in the order of the client's preference
52 * (most preferred first).
53 */
54 language(): string[];
55 language(languages: string[]): string | false;
56 language(...languages: string[]): string | false;
57
58 /**
59 * Return the first accepted language. If nothing in `languages` is accepted, then `false` is returned.
60 * If no languaes are supplied, all accepted languages are returned, in the order of the client's preference
61 * (most preferred first).
62 */
63 languages(): string[];
64 languages(languages: string[]): string | false;
65 languages(...languages: string[]): string | false;
66
67 /**
68 * Return the first accepted language. If nothing in `languages` is accepted, then `false` is returned.
69 * If no languaes are supplied, all accepted languages are returned, in the order of the client's preference
70 * (most preferred first).
71 */
72 lang(): string[];
73 lang(languages: string[]): string | false;
74 lang(...languages: string[]): string | false;
75
76 /**
77 * Return the first accepted language. If nothing in `languages` is accepted, then `false` is returned.
78 * If no languaes are supplied, all accepted languages are returned, in the order of the client's preference
79 * (most preferred first).
80 */
81 langs(): string[];
82 langs(languages: string[]): string | false;
83 langs(...languages: string[]): string | false;
84
85 /**
86 * 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.
87 * If no types are supplied, return the entire set of acceptable types.
88 *
89 * 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`.
90 */
91 type(types: string[]): string[] | string | false;
92 type(...types: string[]): string[] | string | false;
93 types(types: string[]): string[] | string | false;
94 types(...types: string[]): string[] | string | false;
95 }
96}
97
98declare function accepts(req: IncomingMessage): accepts.Accepts;
99
100export = accepts;