Add whatwg-mimetype definition.

This commit is contained in:
Pete Johanson
2018-04-06 13:39:02 -04:00
parent 26b07e5960
commit 5f2ef68fae
4 changed files with 70 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
// Type definitions for whatwg-mimetype 2.1
// Project: https://github.com/jsdom/whatwg-mimetype#readme
// Definitions by: Pete Johanson <https://github.com/petejohanson>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = MIMEType;
declare class MIMEType {
type: string;
subtype: string;
readonly essence: string;
readonly parameters: Map<string, string>;
static parse(s: string): MIMEType | null;
constructor(s: string);
isHTML(): boolean;
isXML(): boolean;
isJavaScript(opts?: { allowParameters?: boolean }): boolean;
}
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"whatwg-mimetype-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
@@ -0,0 +1,24 @@
/// <reference types="node" />
import assert = require("assert");
import MIMEType = require('whatwg-mimetype');
const mt = MIMEType.parse("text/plain");
assert(mt !== null);
if (mt) {
assert(mt.type === "text");
assert(mt.subtype === "plain");
assert(mt.essence === "text/plain");
assert(mt.parameters.size === 0);
assert(!mt.isXML());
assert(!mt.isHTML());
assert(!mt.isJavaScript());
}
const mt2 = new MIMEType("application/javascript; charset=utf8");
assert(mt2.type === "text");
assert(mt2.subtype === "plain");
assert(mt2.essence === "text/plain");
assert(mt2.parameters.get("charset") === "utf8");
assert(mt2.isJavaScript({ allowParameters: true }));