rekwest
Version:
The robust request library that humanity deserves 🌐
26 lines (25 loc) • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validation = void 0;
var _nodeHttp = _interopRequireDefault(require("node:http2"));
var _constants = require("./constants");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const {
HTTP2_METHOD_GET,
HTTP2_METHOD_HEAD
} = _nodeHttp.default.constants;
const validation = (options = {}) => {
if (options.body && [HTTP2_METHOD_GET, HTTP2_METHOD_HEAD].includes(options.method)) {
throw new TypeError(`Request with ${HTTP2_METHOD_GET}/${HTTP2_METHOD_HEAD} method cannot have body.`);
}
if (!Object.values(_constants.requestCredentials).includes(options.credentials)) {
throw new TypeError(`Failed to read the 'credentials' property from 'options': The provided value '${options.credentials}' is not a valid enum value.`);
}
if (!Reflect.has(_constants.requestRedirect, options.redirect)) {
throw new TypeError(`Failed to read the 'redirect' property from 'options': The provided value '${options.redirect}' is not a valid enum value.`);
}
return options;
};
exports.validation = validation;