diff --git a/types/mime/Mime.d.ts b/types/mime/Mime.d.ts new file mode 100644 index 0000000000..1b31167894 --- /dev/null +++ b/types/mime/Mime.d.ts @@ -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; +} diff --git a/types/mime/index.d.ts b/types/mime/index.d.ts index 7debcca6f3..2ff497ac12 100644 --- a/types/mime/index.d.ts +++ b/types/mime/index.d.ts @@ -1,20 +1,17 @@ -// Type definitions for mime 1.3 +// Type definitions for mime 2.0 // Project: https://github.com/broofa/node-mime // Definitions by: Jeff Goddard +// Daniel Hritzkiv // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// Imported from: https://github.com/soywiz/typescript-node-definitions/mime.d.ts +// Originally imported from: https://github.com/soywiz/typescript-node-definitions/mime.d.ts export as namespace mime; -export function lookup(path: string, fallback?: string): string; -export function extension(mime: string): string; -export function load(filepath: string): void; -export function define(mimes: { [key: string]: any }): void; +export interface TypeMap { [key: string]: string[]; } -export interface Charsets { - lookup(mime: string): string; -} +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; diff --git a/types/mime/mime-tests.ts b/types/mime/mime-tests.ts index ee8b050d0d..185c1840f3 100644 --- a/types/mime/mime-tests.ts +++ b/types/mime/mime-tests.ts @@ -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'); diff --git a/types/mime/tsconfig.json b/types/mime/tsconfig.json index ee63d84106..1bf14a5e7f 100644 --- a/types/mime/tsconfig.json +++ b/types/mime/tsconfig.json @@ -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" ] -} \ No newline at end of file +} diff --git a/types/node-static/node-static-tests.ts b/types/node-static/node-static-tests.ts index 38abd8238d..3d68473e02 100644 --- a/types/node-static/node-static-tests.ts +++ b/types/node-static/node-static-tests.ts @@ -2,6 +2,6 @@ import { Server, version, mime } from 'node-static'; const server = new Server(__dirname); const pathname = server.resolve('./tsconfig.json'); -const mimetype = mime.lookup(pathname, ''); +const mimetype = mime.getType(pathname); const versionNum = version.join('.'); console.log(`The node-static server constructed an instance of itself, fetched the mimetype of ${pathname} (${mimetype}), and has a version of ${versionNum}! The package is working.`);