UNPKG

@js-thing/http-status-codes

Version:

Contains properly documented HTTP status code enums, reason phrases and helpers as defined in RFC

55 lines 2.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isClientErrorStatus = exports.isClientErrorReasonPhrase = exports.is4xxClientErrorStatusCode = exports.isClientErrorStatusCode = void 0; var HttpStatusCodes_1 = require("../HttpStatusCodes"); var HttpReasonPhrases_1 = require("../HttpReasonPhrases"); /** * Checks whether the status code belongs to `HttpClientErrorStatusCodes` enum. * The range is all standard code between [400 - 499] * * To check the entire 4xx range use `is4xxClientErrorStatusCode(code: number)` instead. * @param statusCode - The integer status code. e.g. 100 * @returns `true` if matches `false` otherwise */ var isClientErrorStatusCode = function (statusCode) { return HttpStatusCodes_1.HttpClientErrorStatusCodes[statusCode] !== undefined; }; exports.isClientErrorStatusCode = isClientErrorStatusCode; /** * Checks whether the status code belongs to 4xx family of status codes. * * @param statusCode - The integer status code. e.g. 100 * @returns `true` if matches `false` otherwise */ var is4xxClientErrorStatusCode = function (statusCode) { return statusCode >= 400 && statusCode <= 499; }; exports.is4xxClientErrorStatusCode = is4xxClientErrorStatusCode; /** * Checks whether the input string belongs to `HttpClientErrorReasonPhrases` enum. * * The match is case sensitive * * @param reasonPhrase - The reason phrase. e.g. 'Ok' * @returns `true` if matches `false` otherwise */ var isClientErrorReasonPhrase = function (reasonPhrase) { return Object.values(HttpReasonPhrases_1.HttpClientErrorReasonPhrases).includes(reasonPhrase) === true; }; exports.isClientErrorReasonPhrase = isClientErrorReasonPhrase; /** * Checks whether the input integer or string belongs to * `HttpClientErrorStatusCodes` or `HttpClientErrorReasonPhrases` enum. * For integer input, the range is all standard code between [400 - 499]. * For string input, the match is case sensitive. * * To check the entire 4xx range use `is4xxClientErrorStatusCode(code: number)` instead. * @param status - e.g. 'Ok' or 200 * @returns `true` if matches `false` otherwise */ var isClientErrorStatus = function (status) { return exports.isClientErrorStatusCode(status) || exports.isClientErrorReasonPhrase(status); }; exports.isClientErrorStatus = isClientErrorStatus; //# sourceMappingURL=isClientErrorStatus.js.map