From a08ce5ef582658f9aa06dde55e24d49e828b62cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20B=C5=82a=C5=BCejewicz=20=28Peter=20Blazejewicz=29?= Date: Tue, 12 May 2020 21:55:24 +0200 Subject: [PATCH] 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> --- types/media-typer/index.d.ts | 33 ++++++++++++++++++++++- types/media-typer/media-typer-tests.ts | 9 ++++--- types/media-typer/tsconfig.json | 2 +- types/media-typer/v0/index.d.ts | 13 +++++++++ types/media-typer/v0/media-typer-tests.ts | 15 +++++++++++ types/media-typer/v0/tsconfig.json | 28 +++++++++++++++++++ types/media-typer/v0/tslint.json | 1 + 7 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 types/media-typer/v0/index.d.ts create mode 100644 types/media-typer/v0/media-typer-tests.ts create mode 100644 types/media-typer/v0/tsconfig.json create mode 100644 types/media-typer/v0/tslint.json diff --git a/types/media-typer/index.d.ts b/types/media-typer/index.d.ts index 68254fdb0c..fdfd8e72b7 100644 --- a/types/media-typer/index.d.ts +++ b/types/media-typer/index.d.ts @@ -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 +// Piotr Błażejewicz // 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; } diff --git a/types/media-typer/media-typer-tests.ts b/types/media-typer/media-typer-tests.ts index de5c744d14..a0bee6d3f0 100644 --- a/types/media-typer/media-typer-tests.ts +++ b/types/media-typer/media-typer-tests.ts @@ -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'); diff --git a/types/media-typer/tsconfig.json b/types/media-typer/tsconfig.json index fe5268288d..f7975d9a73 100644 --- a/types/media-typer/tsconfig.json +++ b/types/media-typer/tsconfig.json @@ -20,4 +20,4 @@ "index.d.ts", "media-typer-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/media-typer/v0/index.d.ts b/types/media-typer/v0/index.d.ts new file mode 100644 index 0000000000..68254fdb0c --- /dev/null +++ b/types/media-typer/v0/index.d.ts @@ -0,0 +1,13 @@ +// Type definitions for media-typer 0.3 +// Project: https://github.com/jshttp/media-typer +// Definitions by: 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; +} diff --git a/types/media-typer/v0/media-typer-tests.ts b/types/media-typer/v0/media-typer-tests.ts new file mode 100644 index 0000000000..de5c744d14 --- /dev/null +++ b/types/media-typer/v0/media-typer-tests.ts @@ -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'}); diff --git a/types/media-typer/v0/tsconfig.json b/types/media-typer/v0/tsconfig.json new file mode 100644 index 0000000000..eed77891e0 --- /dev/null +++ b/types/media-typer/v0/tsconfig.json @@ -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" + ] +} diff --git a/types/media-typer/v0/tslint.json b/types/media-typer/v0/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/media-typer/v0/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }