-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.d.ts
134 lines (107 loc) · 3.43 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Declare our own interface to mime-db data
declare namespace MimeDb {
type MimeSource = 'iana' | 'apache' | 'nginx';
interface MimeEntry {
/**
* String with identifier for the source of the data.
*/
source?: MimeSource;
/**
* Array of strings with possible lowercased file extensions, without the
* dot.
*/
extensions?: ReadonlyArray<string>;
/**
* Boolean that indicates if the contents is likely to become smaller if
* gzip or similar compression is applied.
*/
compressible?: boolean;
/**
* Charset for type.
*/
charset?: string;
}
}
// Helpers
type NoInfer<T> = [T][T extends any ? 0 : never];
export class MimosEntry {
/**
* String with the content-type.
*/
type: string;
/**
* String with identifier for the source of the data.
*/
source: MimeDb.MimeSource | 'mime-db' | 'mimos';
/**
* Array of strings with possible lowercased file extensions, without the
* dot.
*/
extensions: ReadonlyArray<string>;
/**
* Boolean that indicates if the contents is likely to become smaller if
* gzip or similar compression is applied.
*/
compressible: boolean;
/**
* Optional charset for type.
*/
charset?: string;
private constructor();
}
export interface MimosDeclaration<P extends object = {}> extends MimeDb.MimeEntry {
/**
* The `type` value of result objects, defaults to `key`.
*/
type?: string;
/**
* Method with signature `function(mime)`.
*
* When this mime type is found in the database, this function will run.
* This allows you make customizations to `mime` based on developer criteria.
*/
predicate?: (mime: MimosEntry & P) => MimosEntry;
}
export interface MimosOptions<P extends object = {}> {
/**
* An object hash that is merged into the built-in mime information from
* {@link https://github.com/jshttp/mime-db}.
*
* Each key value pair represents a single mime object override.
*
* Each override entry should follow this schema:
* * The key is the lower-cased correct mime-type. (Ex. "application/javascript").
* * The value should be an object following the structure from
* {@link https://github.com/jshttp/mime-db#data-structure} with additional
* optional values:
* * type - Specify the `type` value of result objects, defaults to `key`.
* * predicate - Method that is called with mime entry on lookup, that
* must return an entry. This allows you make customizations to `mime`
* based on developer criteria.
*/
override?: {
[type: string]: MimosDeclaration<P> & P;
};
}
export class Mimos<P extends object = {}> {
/**
* Create a Mimos object for mime lookups.
*/
constructor(options?: MimosOptions<NoInfer<P>>);
/**
* Extract extension from file path and lookup mime information.
*
* @param path - Path to file
*
* @return Found mime object, or {} if no match.
*/
path(path: string): (Readonly<MimosEntry & Partial<P>>) | {};
/**
* Lookup mime information.
*
* @param type - The content-type to find mime information about.
*
* @return Mime object for provided type.
*/
type(type: string): Readonly<MimosEntry & Partial<P>>;
}