@js-thing/http-status-codes
Version:
Contains properly documented HTTP status code enums, reason phrases and helpers as defined in RFC
56 lines • 2.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isSuccessStatus = exports.isSuccessReasonPhrase = exports.is2xxSuccessStatusCode = exports.isSuccessStatusCode = void 0;
var HttpStatusCodes_1 = require("../HttpStatusCodes");
var HttpReasonPhrases_1 = require("../HttpReasonPhrases");
/**
* Checks whether the status code belongs to `HttpSuccessStatusCodes` enum.
* The range is all standard code between [200 - 299]
*
* To check the entire 2xx range use `is2xxSuccessStatusCode(code: number)` instead.
* @param statusCode - The integer status code. e.g. 100
* @returns `true` if matches `false` otherwise
*/
var isSuccessStatusCode = function (statusCode) {
return HttpStatusCodes_1.HttpSuccessStatusCodes[statusCode] !== undefined;
};
exports.isSuccessStatusCode = isSuccessStatusCode;
/**
* Checks whether the status code belongs to 2xx family of status codes.
*
* @param statusCode - The integer status code. e.g. 100
* @returns `true` if matches `false` otherwise
*/
var is2xxSuccessStatusCode = function (statusCode) {
return statusCode >= 200 && statusCode <= 299;
};
exports.is2xxSuccessStatusCode = is2xxSuccessStatusCode;
/**
* Checks whether the input string belongs to `HttpSuccessReasonPhrases` enum.
*
* The match is case sensitive
*
* @param reasonPhrase - The reason phrase. e.g. 'OK'
* @returns `true` if matches `false` otherwise
*/
var isSuccessReasonPhrase = function (reasonPhrase) {
return Object.values(HttpReasonPhrases_1.HttpSuccessReasonPhrases).includes(reasonPhrase) === true;
};
exports.isSuccessReasonPhrase = isSuccessReasonPhrase;
/**
* Checks whether the input integer or string belongs to
* `HttpSuccessStatusCodes` or `HttpSuccessReasonPhrases` enum.
* For integer input, the range is all standard code between [200 - 299].
* For string input, the match is case sensitive.
*
* To check the entire 2xx range use `is2xxSuccessStatusCode(code: number)` instead.
* @param status - e.g. 'Ok' or 200
* @returns `true` if matches `false` otherwise
*/
var isSuccessStatus = function (status) {
return exports.isSuccessStatusCode(status) ||
exports.isSuccessReasonPhrase(status);
};
exports.isSuccessStatus = isSuccessStatus;
exports.default = exports.isSuccessStatus;
//# sourceMappingURL=isSuccessStatus.js.map