UNPKG

@js-thing/http-status-codes

Version:

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

28 lines 1.08 kB
import { HttpStatusCodes } from '../HttpStatusCodes'; import { HttpReasonPhrases } from '../HttpReasonPhrases'; /** * Get the status code for a given reason phrase. * Optionally pass a second parameter to ignore case. * * @param reasonPhrase - e.g. OK * @param ignoreCase - ignore case while comparing, default: false * @returns - The corresponding status code as `number` for the given input `undefined` otherwise */ export default (function (reasonPhrase, ignoreCase) { if (ignoreCase === void 0) { ignoreCase = false; } if (!reasonPhrase) { return undefined; } var foundReasonKeyVal = Object.entries(HttpReasonPhrases).find(function (reasonKeyVal) { if (ignoreCase) { return reasonKeyVal[1].toLowerCase() === reasonPhrase.toLowerCase(); } return reasonKeyVal[1] === reasonPhrase; }); if (!foundReasonKeyVal) { return undefined; } // eslint-disable-next-line @typescript-eslint/no-explicit-any return HttpStatusCodes[foundReasonKeyVal[0]]; }); //# sourceMappingURL=getStatusCode.js.map