@vercel/sdk
Version:
<p align="center"> <a href="https://vercel.com"> <img src="https://assets.vercel.com/image/upload/v1588805858/repositories/vercel/logo.png" height="96"> <h3 align="center">Vercel</h3> </a> <p align="center">Develop. Preview. Ship.</p> </p>
24 lines • 952 B
JavaScript
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
const hasOwn = Object.prototype.hasOwnProperty;
export function pathToFunc(pathPattern, options) {
const paramRE = /\{([a-zA-Z0-9_][a-zA-Z0-9_-]*?)\}/g;
return function buildURLPath(params = {}) {
return pathPattern
.replace(paramRE, function (_, placeholder) {
if (!hasOwn.call(params, placeholder)) {
throw new Error(`Parameter '${placeholder}' is required`);
}
const value = params[placeholder];
if (typeof value !== "string" && typeof value !== "number") {
throw new Error(`Parameter '${placeholder}' must be a string or number`);
}
return options?.charEncoding === "percent"
? encodeURIComponent(`${value}`)
: `${value}`;
})
.replace(/^\/+/, "");
};
}
//# sourceMappingURL=url.js.map