Skip to content

Commit

Permalink
Updated documentation and definition for getStatusCode
Browse files Browse the repository at this point in the history
  • Loading branch information
o0Ignition0o committed Mar 16, 2019
1 parent 391e119 commit cd5b6c8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ response
error: HttpStatus.getStatusText(HttpStatus.INTERNAL_SERVER_ERROR)
});

response.status(HttpStatus.getStatusCode('No Content'))
.send();
response
.status(HttpStatus.getStatusCode('Server Error'))
.send({
error: 'Server Error'
});
```

## Codes
Expand Down Expand Up @@ -112,8 +115,10 @@ response
})

response
.status(getStatusCode('No Content')
.send()
.status(HttpStatus.getStatusCode('Server Error'))
.send({
error: 'Server Error'
})
```

Option 2: Selective import
Expand All @@ -126,6 +131,6 @@ response
.send(getStatusText(OK))

response
.status(getStatusCode('No Content')
.send()
.status(getStatusCode('Server Error')
.send('Server Error')
```
11 changes: 6 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,9 @@ export declare enum HTTP_STATUS {
export declare function getStatusText(statusCode: number): string;

/**
* Convert the status code title to its appropriate numeric value
* @param statusText One of the available status texts in this package
* @returns {Number} The associated status code of the passed status text
* @throws {Error} The status text does not exist
export declare function getStatusCode(statusText: string): number;
* Convert the status reason phrase to its appropriate numeric value
* @param statusText 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
*/
export declare function getStatusCode(reasonPhrase: string): number;
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ exports.getStatusText = function(statusCode) {
}
};

exports.getStatusCode = function(statusText) {
exports.getStatusCode = function(reasonPhrase) {
for (key in statusCodes) {
if (statusCodes[key] === statusText) {
if (statusCodes[key] === reasonPhrase) {
return parseInt(key, 10);
}
}
throw new Error("Status text does not exist: " + statusText);
throw new Error("Reason phrase does not exist: " + reasonPhrase);
};

0 comments on commit cd5b6c8

Please sign in to comment.