fetch-to-curl-ts
Version:
Convert fetch HTTP request to curl
26 lines (25 loc) • 773 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMethod = exports.HTTP_METHODS = void 0;
const assert_1 = __importDefault(require("assert"));
exports.HTTP_METHODS = {
GET: "GET",
POST: "POST",
PUT: "PUT",
PATCH: "PATCH",
DELETE: "DELETE",
HEAD: "HEAD",
OPTIONS: "OPTIONS",
};
function assertMethod(method) {
assert_1.default.ok(method in exports.HTTP_METHODS, `Invalid method: ${method}`);
}
const getMethod = (method) => {
const index = method.toUpperCase();
assertMethod(index);
return exports.HTTP_METHODS[index];
};
exports.getMethod = getMethod;