UNPKG

@clickup/rest-client

Version:

A syntax sugar tool around Node fetch() API, tailored to work with TypeScript and response validators

24 lines 840 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Allows to use URLs like /some/:abc/other and pass { abc: "xyz" } as one of * body parameters. Such body parameters will be excluded from the body before * sending the request (so they're "moved" into the URL). */ function substituteParams(url, body) { if (!body || typeof body !== "object") { return [url, body]; } url = url.replace(/:([a-z0-9_]+)/gi, (match, param) => { const value = body[param]; if (typeof value === "string" || typeof value === "number") { body = { ...body }; delete body[param]; return encodeURIComponent(value); } return match; }); return [url, body]; } exports.default = substituteParams; //# sourceMappingURL=substituteParams.js.map