Better typings for mime module; Fix mime tests

This commit is contained in:
Daniel Hritzkiv
2017-09-14 15:18:39 -04:00
parent b59dee5130
commit 16b590f251
4 changed files with 34 additions and 18 deletions
+9
View File
@@ -0,0 +1,9 @@
import { TypeMap } from "./index";
export default class Mime {
constructor(mimes: TypeMap);
getType(path: string): string | null;
getExtension(mime: string): string | null;
define(mimes: TypeMap, force?: boolean): void;
}
+4 -9
View File
@@ -7,15 +7,10 @@
export as namespace mime;
export function getType(path: string): string;
export function getExtension(mime: string): string;
export function define(mimes: { [key: string]: string[] }, force?: boolean): void;
export interface TypeMap { [key: string]: string[]; }
export interface Charsets {
getType(path: string): string;
getExtension(mime: string): string;
define(mimes: { [key: string]: string[] }, force?: boolean): void;
}
export function getType(path: string): string | null;
export function getExtension(mime: string): string | null;
export function define(mimes: TypeMap, force?: boolean): void;
export const charsets: Charsets;
export const default_type: string;
+18 -7
View File
@@ -1,12 +1,23 @@
import * as mime from "mime";
import Mime from "mime/Mime";
let str: string;
const obj: {} = {};
const fallback = '';
let strOrNul: string | null;
const obj = {
mime: ["ext", "ext2"]
};
const obj2 = {
"text/plain": ["txt"]
};
str = mime.lookup(str, fallback);
str = mime.extension(str);
mime.load(str);
mime.define(obj);
mime.define(obj2, true);
strOrNul = mime.getType("ext");
strOrNul = mime.getType("foo");
strOrNul = mime.getExtension("mime");
strOrNul = mime.getExtension("bar");
str = mime.charsets.lookup(str);
const myMime = new Mime(obj);
strOrNul = myMime.getType("foo");
strOrNul = myMime.getExtension('text/plan');
+3 -2
View File
@@ -6,7 +6,7 @@
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
@@ -17,6 +17,7 @@
},
"files": [
"index.d.ts",
"Mime.d.ts",
"mime-tests.ts"
]
}
}