Releases: Skillnter/http-response-status-code
Introduce Utility Toolset
Toolset Overview
1. Get Status Code
Returns the HTTP status code from status code name.
Parameters
name(String): The name of the status code.
Returns
code(number): The code number of the status if successful.Error: An error object if something goes wrong, containing details about the issue.
Example (Stackblitz)
var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.getStatusCode("IM_A_TEAPOT")); // 4182. Get Status Name
Returns the HTTP status code name from status code.
Parameters
code(number): The code number of the status.
Returns
name(String): The name of the status code if successful.Error: An error object if something goes wrong, containing details about the issue.
Example (Stackblitz)
var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.getStatusName(418)); // "IM_A_TEAPOT"3. Get Status Description
Returns the status description from HTTP status code.
Parameters
code(number): The code number of the status.
Returns
name(String): The description of the status code if successful.Error: An error object if something goes wrong, containing details about the issue.
Example (Stackblitz)
var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.getStatusDescription(500)); // "Internal Server Error"4. Informational Code Check
Determines whether the specified status code represents an informational status.
Parameters
code(number): The code number of the status.
Returns
result(boolean): True if the status code is informational, false otherwise.Error: An error object if something goes wrong, containing details about the issue.
Example (Stackblitz)
var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.isInformational(100)); // True
console.log(STATUS_CODES.isInformational(200)); // False5. List Informational Codes
Returns all the informational HTTP status codes.
Returns
result(number[]): An array of all the informational HTTP status codes.
Example (Stackblitz)
var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.getInformationalCodes()); // [100, 101, ...]6. Success Code Check
Determines whether the specified status code represents a success status.
Parameters
code(number): The code number of the status.
Returns
result(boolean): True if the status code is success status, false otherwise.Error: An error object if something goes wrong, containing details about the issue.
Example (Stackblitz)
var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.isSuccess(200)); // True
console.log(STATUS_CODES.isSuccess(100)); // False7. List Success Codes
Returns all the success HTTP status codes.
Returns
result(number[]): An array of all the success HTTP status codes.
Example (Stackblitz)
var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.getSuccessCodes()); // [200, 201, ...]8. Redirectional Code Check
Determines whether the specified status code represents a redirectional status.
Parameters
code(number): The code number of the status.
Returns
result(boolean): True if the status code is redirectional status, false otherwise.Error: An error object if something goes wrong, containing details about the issue.
Example (Stackblitz)
var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.isRedirectional(300)); // True
console.log(STATUS_CODES.isRedirectional(100)); // False9. List Redirectional Codes
Returns all the redirectional HTTP status codes.
Returns
result(number[]): An array of all the redirectional HTTP status codes.
Example (Stackblitz)
var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.getRedirectionalCodes()); // [300, 301, ...]10. Client Error Code Check
Determines whether the specified status code represents a client side error status.
Parameters
code(number): The code number of the status.
Returns
result(boolean): True if the status code is client side error status, false otherwise.Error: An error object if something goes wrong, containing details about the issue.
Example (Stackblitz)
var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.isClientError(400)); // True
console.log(STATUS_CODES.isClientError(100)); // False11. List Client Side Error Codes
Returns all the client side error HTTP status codes.
Returns
result(number[]): An array of all the client side error HTTP status codes.
Example (Stackblitz)
var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.getClientErrorCodes()); // [400, 401, ...]12. Server Error Code Check
Determines whether the specified status code represents a server side error status.
Parameters
code(number): The code number of the status.
Returns
result(boolean): True if the status code is server side error status, false otherwise.Error: An error object if something goes wrong, containing details about the issue.
Example (Stackblitz)
var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.isServerError(500)); // True
console.log(STATUS_CODES.isServerError(100)); // False13. List Server Side Error Codes
Returns all the server side error HTTP status codes.
Returns
result(number[]): An array of all the server side error HTTP status codes.
Example (Stackblitz)
var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.getServerErrorCodes()); // [500, 501, ...]14. Valid Code Check
Validates whether the provided status code is recognized as valid.
Parameters
code(number): The code number of the status.
Returns
result(boolean): True if the status code is valid status, false otherwise.Error: An error object if something goes wrong, containing details about the issue.
Example (Stackblitz)
var STATUS_CODES = require('http-response-status-code');
console.log(STATUS_CODES.isValidStatusCode(500)); // True
console.log(STATUS_CODES.isValidStatusCode(999)); // Falseversion 1.6.1
SANITIZE CODE AND REMOVE UNNECESSARY FILES
-
Removed
release-package.ymlfile -
Added
CODE_OF_CONDUCT.mdfile -
Updated
README.mdfile to fix the typo in code snippet -
Replaced single quotes with double quotes in files
index.ts&
index-spec.js -
Updated version number to
1.6.1
v.1.6.0
What's Changed
- ADD BUG REPORT AND FEATURE REQUEST TEMPLATE by @Skillnter in #8
- ADD .NPMRC TO .GITIGNORE AND FIX TYPO IN README by @Skillnter in #11
- ADD COVERAGE, UPDATE TEST AND UPDATE README FOR ISSUES by @Skillnter in #12
- UPDATE FIXES FOR CODE STYLE IN TEST FILE by @Skillnter in #13
- Update README.md by @Skillnter in #14
- Readme by @Skillnter in #15
- Version 1.6.0 by @Skillnter in #16
- ADD YML FOR PACKAGE RELEASE AND UPDATE PUBLISH CONFIG by @Skillnter in #18
Full Changelog: 1.5.3...1.6.0