-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[content-type_v1.x.x] Add definitions (#3675)
- Loading branch information
1 parent
01cfe94
commit 65e0953
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
definitions/npm/content-type_v1.x.x/flow_v0.84.x-/content-type_v1.x.x.js
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,22 @@ | ||
declare module 'content-type' { | ||
declare type contentType$OutputParsedContentType = {| | ||
type: string, | ||
parameters: {| [string]: string |}, | ||
|}; | ||
|
||
declare type contentType$InputParsedContentType = {| | ||
+type: string, | ||
+parameters?: { [string]: string | number, ... }, | ||
|}; | ||
|
||
declare function parse( | ||
string | http$IncomingMessage<> | http$ServerResponse | ||
): contentType$OutputParsedContentType; | ||
|
||
declare function format(contentType$InputParsedContentType): string; | ||
|
||
declare module.exports: {| | ||
+parse: typeof parse, | ||
+format: typeof format, | ||
|}; | ||
} |
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,49 @@ | ||
import { describe, it } from 'flow-typed-test'; | ||
const contentType = require('content-type'); | ||
|
||
describe('content-type', () => { | ||
it('parse normal usage', () => { | ||
const parsedValue = contentType.parse('application/json'); | ||
(parsedValue.type: string); | ||
(parsedValue.parameters.foo: string); | ||
(parsedValue.parameters['foo']: string); | ||
}); | ||
|
||
it('format normal usage', () => { | ||
const typeValue = contentType.format({ | ||
type: 'application/json', | ||
parameters: { version: '1.0' }, | ||
}); | ||
|
||
(typeValue: string); | ||
|
||
contentType.format({ | ||
type: 'application/json', | ||
parameters: { version: 1 }, | ||
}); | ||
|
||
contentType.format({ | ||
type: 'application/json', | ||
}); | ||
|
||
const parameters = {}; | ||
parameters['charset'] = 'utf-8'; | ||
parameters['version'] = 8; | ||
contentType.format({ | ||
type: 'application/json', | ||
parameters, | ||
}); | ||
}); | ||
|
||
it('finds errors when we miss the type property', () => { | ||
// $ExpectError | ||
contentType.format({ | ||
foo: 'bar', | ||
}); | ||
|
||
// $ExpectError | ||
contentType.format({ | ||
parameters: { version: '1.0' } | ||
}); | ||
}); | ||
}); |