MCPcopy Index your code
hub / github.com/simstudioai/sim / replacePathParams

Function replacePathParams

apps/sim/lib/api/client/request.ts:37–60  ·  view source on GitHub ↗
(path: string, params: unknown)

Source from the content-addressed store, hash-verified

35}
36
37function replacePathParams(path: string, params: unknown): string {
38 if (!params || typeof params !== 'object') return path
39
40 const values = params as Record<string, unknown>
41 return path.replace(
42 /\[\[?(\.\.\.)?([^\][]+)\]\]?/g,
43 (match, rest: string | undefined, key: string) => {
44 const value = values[key]
45 const isOptionalCatchAll = match.startsWith('[[...')
46
47 if (rest && Array.isArray(value)) {
48 return value.map((item) => encodeURIComponent(String(item))).join('/')
49 }
50
51 if (value === undefined && isOptionalCatchAll) return ''
52
53 if (typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean') {
54 throw new Error(`Missing route param "${key}"`)
55 }
56
57 return encodeURIComponent(String(value))
58 }
59 )
60}
61
62function appendQuery(path: string, query: unknown): string {
63 if (!query || typeof query !== 'object') return path

Callers 2

requestJsonFunction · 0.85
requestRawFunction · 0.85

Calls 2

joinMethod · 0.80
replaceMethod · 0.65

Tested by

no test coverage detected