@js-thing/http-status-codes
Version:
Contains properly documented HTTP status code enums, reason phrases and helpers as defined in RFC
48 lines • 1.92 kB
JavaScript
import { HttpInformationStatusCodes } from '../HttpStatusCodes';
import { HttpInformationReasonPhrases } from '../HttpReasonPhrases';
/**
* Checks whether the status code belongs to `HttpInformationStatusCodes` enum.
* The range is all standard code between [100 - 199]
*
* To check the entire 1xx range use `is1xxInformationStatusCode(code: number)` instead.
* @param statusCode - The integer status code. e.g. 100
* @returns `true` if matches `false` otherwise
*/
export var isInformationStatusCode = function (statusCode) {
return HttpInformationStatusCodes[statusCode] !== undefined;
};
/**
* Checks whether the status code belongs to 1xx family of status codes.
*
* @param statusCode - The integer status code. e.g. 100
* @returns `true` if matches `false` otherwise
*/
export var is1xxInformationStatusCode = function (statusCode) {
return statusCode >= 100 && statusCode <= 199;
};
/**
* Checks whether the input string belongs to `HttpInformationReasonPhrases` enum.
*
* The match is case sensitive
*
* @param reasonPhrase - The reason phrase. e.g. 'Ok'
* @returns `true` if matches `false` otherwise
*/
export var isInformationReasonPhrase = function (reasonPhrase) {
return Object.values(HttpInformationReasonPhrases).includes(reasonPhrase) === true;
};
/**
* Checks whether the input integer or string belongs to
* `HttpInformationStatusCodes` or `HttpInformationReasonPhrases` enum.
* For integer input, the range is all standard code between [100 - 199].
* For string input, the match is case sensitive.
*
* To check the entire 1xx range use `is1xxInformationStatusCode(code: number)` instead.
* @param status - e.g. 'Ok' or 200
* @returns `true` if matches `false` otherwise
*/
export var isInformationStatus = function (status) {
return isInformationStatusCode(status) ||
isInformationReasonPhrase(status);
};
//# sourceMappingURL=isInformationStatus.js.map