@types/whatwg-mimetype
Advanced tools
Comparing version 2.1.1 to 3.0.0
@@ -1,4 +0,5 @@ | ||
// Type definitions for whatwg-mimetype 2.1 | ||
// Type definitions for whatwg-mimetype 3.0 | ||
// Project: https://github.com/jsdom/whatwg-mimetype#readme | ||
// Definitions by: Pete Johanson <https://github.com/petejohanson> | ||
// BendingBender <https://github.com/BendingBender> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
@@ -8,16 +9,122 @@ | ||
/** | ||
* This class will parse [MIME types](https://mimesniff.spec.whatwg.org/#understanding-mime-types) into a | ||
* structured format, which can then be manipulated and serialized. | ||
* | ||
* @example | ||
* import MIMEType = require("whatwg-mimetype"); | ||
* | ||
* const mimeType = new MIMEType(`Text/HTML;Charset="utf-8"`); | ||
* | ||
* console.assert(mimeType.toString() === "text/html;charset=utf-8"); | ||
* | ||
* console.assert(mimeType.type === "text"); | ||
* console.assert(mimeType.subtype === "html"); | ||
* console.assert(mimeType.essence === "text/html"); | ||
* console.assert(mimeType.parameters.get("charset") === "utf-8"); | ||
* | ||
* mimeType.parameters.set("charset", "windows-1252"); | ||
* console.assert(mimeType.parameters.get("charset") === "windows-1252"); | ||
* console.assert(mimeType.toString() === "text/html;charset=windows-1252"); | ||
* | ||
* console.assert(mimeType.isHTML() === true); | ||
* console.assert(mimeType.isXML() === false); | ||
*/ | ||
declare class MIMEType { | ||
type: string; | ||
subtype: string; | ||
/** | ||
* the MIME type's [type](https://mimesniff.spec.whatwg.org/#mime-type-type), e.g. `"text"` | ||
*/ | ||
type: string; | ||
/** | ||
* the MIME type's [subtype](https://mimesniff.spec.whatwg.org/#mime-type-subtype), e.g. `"html"` | ||
*/ | ||
subtype: string; | ||
readonly essence: string; | ||
readonly parameters: Map<string, string>; | ||
/** | ||
* the MIME type's [essence](https://mimesniff.spec.whatwg.org/#mime-type-essence), e.g. `"text/html"` | ||
*/ | ||
readonly essence: string; | ||
/** | ||
* an instance of `MIMETypeParameters`, containing this MIME type's | ||
* [parameters](https://mimesniff.spec.whatwg.org/#mime-type-parameters) | ||
*/ | ||
readonly parameters: MIMEType.MIMETypeParameters; | ||
static parse(s: string): MIMEType | null; | ||
/** | ||
* As an alternative to the constructor, you can use `MIMEType.parse(string)`. The only difference | ||
* is that `parse()` will return `null` on failed parsing, whereas the constructor will throw. | ||
* It thus makes the most sense to use the constructor in cases where unparseable MIME types would | ||
* be exceptional, and use `parse()` when dealing with input from some unconstrained source. | ||
*/ | ||
static parse(s: string): MIMEType | null; | ||
constructor(s: string); | ||
/** | ||
* Attempts to parse the input into a MIME type; if parsing fails, an `Error` will be thrown. | ||
*/ | ||
constructor(s: string); | ||
isHTML(): boolean; | ||
isXML(): boolean; | ||
isJavaScript(opts?: { allowParameters?: boolean | undefined }): boolean; | ||
/** | ||
* @returns `true` if this instance represents [a HTML MIME type](https://mimesniff.spec.whatwg.org/#html-mime-type) | ||
*/ | ||
isHTML(): boolean; | ||
/** | ||
* @returns `true` if this instance represents [an XML MIME type](https://mimesniff.spec.whatwg.org/#xml-mime-type) | ||
*/ | ||
isXML(): boolean; | ||
/** | ||
* @returns `true` if this instance represents | ||
* [a JavaScript MIME type](https://html.spec.whatwg.org/multipage/scripting.html#javascript-mime-type). | ||
* | ||
* @param opts.prohibitParameters can be set to `true` to disallow any parameters, i.e. to test if the | ||
* MIME type's serialization is a | ||
* [JavaScript MIME type essence match](https://mimesniff.spec.whatwg.org/#javascript-mime-type-essence-match). | ||
*/ | ||
isJavaScript(opts?: { prohibitParameters?: boolean | undefined }): boolean; | ||
} | ||
declare namespace MIMEType { | ||
/** | ||
* The `MIMETypeParameters` class, instances of which are returned by `mimeType.parameters`, has equivalent | ||
* surface API to a [JavaScript `Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map). | ||
* | ||
* However, `MIMETypeParameters` methods will always interpret their arguments as appropriate for MIME types, | ||
* so e.g. parameter names will be lowercased, and attempting to set invalid characters will throw. | ||
* | ||
* @example | ||
* import MIMEType = require("whatwg-mimetype"); | ||
* const mimeType = new MIMEType(`x/x;a=b;c=D;E="F"`); | ||
* | ||
* // Logs: | ||
* // a b | ||
* // c D | ||
* // e F | ||
* for (const [name, value] of mimeType.parameters) { | ||
* console.log(name, value); | ||
* } | ||
* | ||
* console.assert(mimeType.parameters.has("a")); | ||
* console.assert(mimeType.parameters.has("A")); | ||
* console.assert(mimeType.parameters.get("A") === "b"); | ||
* | ||
* mimeType.parameters.set("Q", "X"); | ||
* console.assert(mimeType.parameters.get("q") === "X"); | ||
* console.assert(mimeType.toString() === "x/x;a=b;c=d;e=F;q=X"); | ||
* | ||
* // Throws: | ||
* mimeType.parameters.set("@", "x"); | ||
*/ | ||
interface MIMETypeParameters { | ||
readonly size: number; | ||
get(key: string): string | undefined; | ||
has(key: string): boolean; | ||
set(key: string, value: string): this; | ||
clear(): void; | ||
delete(key: string): boolean; | ||
forEach(callbackfn: (value: string, key: string, map: Map<string, string>) => void, thisArg?: any): void; | ||
keys(): IterableIterator<string>; | ||
values(): IterableIterator<string>; | ||
entries(): IterableIterator<[string, string]>; | ||
[Symbol.iterator](): IterableIterator<[string, string]>; | ||
} | ||
} |
{ | ||
"name": "@types/whatwg-mimetype", | ||
"version": "2.1.1", | ||
"version": "3.0.0", | ||
"description": "TypeScript definitions for whatwg-mimetype", | ||
@@ -12,2 +12,7 @@ "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/whatwg-mimetype", | ||
"githubUsername": "petejohanson" | ||
}, | ||
{ | ||
"name": "BendingBender", | ||
"url": "https://github.com/BendingBender", | ||
"githubUsername": "BendingBender" | ||
} | ||
@@ -24,4 +29,4 @@ ], | ||
"dependencies": {}, | ||
"typesPublisherContentHash": "1773c9700df35045d5fa552cee75f3234657d9f11a9e3e30f29812496a331465", | ||
"typeScriptVersion": "3.6" | ||
"typesPublisherContentHash": "59cd2183f982ae39f9a5d24c225c022a64bcae704d28ddbc1b1b4e4bf86a5ff3", | ||
"typeScriptVersion": "4.1" | ||
} |
@@ -9,31 +9,5 @@ # Installation | ||
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/whatwg-mimetype. | ||
## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/whatwg-mimetype/index.d.ts) | ||
````ts | ||
// 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 | undefined }): boolean; | ||
} | ||
```` | ||
### Additional Details | ||
* Last updated: Fri, 02 Jul 2021 18:05:36 GMT | ||
* Last updated: Tue, 13 Sep 2022 19:02:57 GMT | ||
* Dependencies: none | ||
@@ -43,2 +17,2 @@ * Global values: none | ||
# Credits | ||
These definitions were written by [Pete Johanson](https://github.com/petejohanson). | ||
These definitions were written by [Pete Johanson](https://github.com/petejohanson), and [BendingBender](https://github.com/BendingBender). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7887
121
17