UNPKG

@stellar/stellar-sdk

Version:

A library for working with the Stellar network, including communication with the Horizon and Soroban RPC servers.

32 lines (30 loc) 925 B
function stringifyTemplateValue(value) { return Array.isArray(value) ? value.join(",") : value.toString(); } function expandUriTemplate(template, variables, baseUrl) { const queryNames = []; const withoutQueryTemplate = template.replace( /\{\?([^}]+)\}/g, (_match, names) => { queryNames.push(...names.split(",")); return ""; } ); const expanded = withoutQueryTemplate.replace( /\{([^?][^}]*)\}/g, (_match, name) => { const value = variables[name]; return typeof value === "undefined" ? "" : encodeURIComponent(stringifyTemplateValue(value)); } ); const url = new URL(expanded, baseUrl); queryNames.forEach((name) => { const value = variables[name]; if (typeof value !== "undefined") { url.searchParams.set(name, stringifyTemplateValue(value)); } }); return url.toString(); } export { expandUriTemplate }; //# sourceMappingURL=url.js.map