Skip to content

Commit

Permalink
[http-status-codes_v1.x.x] Add getStatusCode definition (#3617)
Browse files Browse the repository at this point in the history
  • Loading branch information
kogai authored and pascalduez committed Oct 29, 2019
1 parent 4486f05 commit 3fcdaf0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,11 @@ declare module 'http-status-codes' {
* @returns {String} The associated title of the passed status code
*/
declare function getStatusText(statusCode: number): string;
/**
* Convert the status reason phrase to its appropriate numeric value
* @param reasonPhrase One of the available reason phrases in this package
* @returns {Number} The associated status code of the passed reason phrase
* @throws {Error} The reason phrase does not exist
*/
declare function getStatusCode(reasonPhrase: string): number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { describe, it } from 'flow-typed-test';

import {
OK,
getStatusText
getStatusText,
getStatusCode
} from 'http-status-codes';

describe('http-status-codes', () => {
Expand All @@ -12,11 +13,19 @@ describe('http-status-codes', () => {
(OK: 201);
});

it('status by code', () => {
it('status text by code', () => {
(getStatusText(200): string);
// $ExpectError
(getStatusText(200): boolean);
// $ExpectError
getStatusText("200");
});

it('code by status text', () => {
(getStatusCode("OK"): number);
// $ExpectError
(getStatusCode("OK"): boolean);
// $ExpectError
getStatusCode(200);
});
});

0 comments on commit 3fcdaf0

Please sign in to comment.