update(media-typer): version 1.1 (#44279)

* update(media-typer): version 1.1

- add new `test` method
- missing docs comments
- version bump to 1.1
- v0 created for compatibility
- maintainer added

https://github.com/jshttp/media-typer/compare/v0.3.0...v1.1.0
https://github.com/jshttp/media-typer#typerteststring

Thanks!

* Update types/media-typer/index.d.ts

thx to @sandersn

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>

* Update types/media-typer/index.d.ts

thx to @sandersn

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz) 2020-05-12 21:55:24 +02:00 committed by GitHub
parent e29f31c140
commit a08ce5ef58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 96 additions and 5 deletions

View File

@ -1,13 +1,44 @@
// Type definitions for media-typer 0.3
// Type definitions for media-typer 1.1
// Project: https://github.com/jshttp/media-typer
// Definitions by: BendingBender <https://github.com/BendingBender>
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* Simple RFC 6838 media type parser.
* This module will parse a given media type into its component parts, like type, subtype, and suffix.
* A formatter is also provided to put them back together and the two can be combined to normalize media types into a canonical form.
* If you are looking to parse the string that represents a media type and its parameters in HTTP (for example, the Content-Type header), use the content-type module
*/
/**
* Parse a media type string
* @throws TypeError If the given type string is invalid
*/
export function parse(mediaType: string): MediaType;
/**
* Format an object into a media type string.
* This will return a string of the mime type for the given object
* @throws TypeError If any of the given object values are invalid
*/
export function format(mediaTypeDescriptor: MediaType): string;
/**
* Validate a media type string
*/
export function test(mediaType: string): boolean;
export interface MediaType {
/**
* The type of the media type (always lower case). Example: `image`
*/
type: string;
/**
* The subtype of the media type (always lower case). Example: `svg`
*/
subtype: string;
/**
* The suffix of the media type (always lower case). Example: `xml`
*/
suffix?: string;
}

View File

@ -1,4 +1,4 @@
import * as typer from 'media-typer';
import typer = require('media-typer');
const obj = typer.parse('image/svg+xml');
// $ExpectType MediaType
@ -11,5 +11,8 @@ obj.subtype;
obj.suffix;
// $ExpectType string
typer.format({type: 'image', subtype: 'svg', suffix: 'xml'});
typer.format({type: 'image', subtype: 'svg'});
typer.format({ type: 'image', subtype: 'svg', suffix: 'xml' });
typer.format({ type: 'image', subtype: 'svg' });
// $ExpectType boolean
const valid = typer.test('image/svg+xml');

View File

@ -20,4 +20,4 @@
"index.d.ts",
"media-typer-tests.ts"
]
}
}

13
types/media-typer/v0/index.d.ts vendored Normal file
View File

@ -0,0 +1,13 @@
// Type definitions for media-typer 0.3
// Project: https://github.com/jshttp/media-typer
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export function parse(mediaType: string): MediaType;
export function format(mediaTypeDescriptor: MediaType): string;
export interface MediaType {
type: string;
subtype: string;
suffix?: string;
}

View File

@ -0,0 +1,15 @@
import * as typer from 'media-typer';
const obj = typer.parse('image/svg+xml');
// $ExpectType MediaType
obj;
// $ExpectType string
obj.type;
// $ExpectType string
obj.subtype;
// $ExpectType string | undefined
obj.suffix;
// $ExpectType string
typer.format({type: 'image', subtype: 'svg', suffix: 'xml'});
typer.format({type: 'image', subtype: 'svg'});

View File

@ -0,0 +1,28 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../../",
"typeRoots": [
"../../"
],
"paths": {
"media-typer": [
"media-typer/v0"
]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"media-typer-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }