-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR-URL: #46502 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
- Loading branch information
1 parent
66a24ce
commit e9b64ea
Showing
17 changed files
with
225 additions
and
1,608 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# MIME Type Parsing | ||
|
||
## `MIMEType` interface | ||
|
||
* **type** `string` | ||
* **subtype** `string` | ||
* **parameters** `Map<string, string>` | ||
* **essence** `string` | ||
|
||
## `parseMIMEType(input)` | ||
|
||
Implements [parse a MIME type](https://mimesniff.spec.whatwg.org/#parse-a-mime-type). | ||
|
||
Parses a MIME type, returning its type, subtype, and any associated parameters. If the parser can't parse an input it returns the string literal `'failure'`. | ||
|
||
```js | ||
import { parseMIMEType } from 'undici' | ||
|
||
parseMIMEType('text/html; charset=gbk') | ||
// { | ||
// type: 'text', | ||
// subtype: 'html', | ||
// parameters: Map(1) { 'charset' => 'gbk' }, | ||
// essence: 'text/html' | ||
// } | ||
``` | ||
|
||
Arguments: | ||
|
||
* **input** `string` | ||
|
||
Returns: `MIMEType|'failure'` | ||
|
||
## `serializeAMimeType(input)` | ||
|
||
Implements [serialize a MIME type](https://mimesniff.spec.whatwg.org/#serialize-a-mime-type). | ||
|
||
Serializes a MIMEType object. | ||
|
||
```js | ||
import { serializeAMimeType } from 'undici' | ||
|
||
serializeAMimeType({ | ||
type: 'text', | ||
subtype: 'html', | ||
parameters: new Map([['charset', 'gbk']]), | ||
essence: 'text/html' | ||
}) | ||
// text/html;charset=gbk | ||
|
||
``` | ||
|
||
Arguments: | ||
|
||
* **mimeType** `MIMEType` | ||
|
||
Returns: `string` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/// <reference types="node" /> | ||
|
||
interface MIMEType { | ||
type: string | ||
subtype: string | ||
parameters: Map<string, string> | ||
essence: string | ||
} | ||
|
||
/** | ||
* Parse a string to a {@link MIMEType} object. Returns `failure` if the string | ||
* couldn't be parsed. | ||
* @see https://mimesniff.spec.whatwg.org/#parse-a-mime-type | ||
*/ | ||
export function parseMIMEType (input: string): 'failure' | MIMEType | ||
|
||
/** | ||
* Convert a MIMEType object to a string. | ||
* @see https://mimesniff.spec.whatwg.org/#serialize-a-mime-type | ||
*/ | ||
export function serializeAMimeType (mimeType: MIMEType): string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.