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

Function replaceValidReferencesAsync

apps/sim/executor/variables/resolver.ts:76–93  ·  view source on GitHub ↗
(
  template: string,
  replacer: (match: string, index: number, template: string) => Promise<string>
)

Source from the content-addressed store, hash-verified

74}
75
76async function replaceValidReferencesAsync(
77 template: string,
78 replacer: (match: string, index: number, template: string) => Promise<string>
79): Promise<string> {
80 const pattern = createReferencePattern()
81 let cursor = 0
82 let result = ''
83 for (const match of template.matchAll(pattern)) {
84 const fullMatch = match[0]
85 const index = match.index ?? 0
86 result += template.slice(cursor, index)
87 result += isLikelyReferenceSegment(fullMatch)
88 ? await replacer(fullMatch, index, template)
89 : fullMatch
90 cursor = index + fullMatch.length
91 }
92 return result + template.slice(cursor)
93}
94
95async function replaceEnvVarsAsync(
96 template: string,

Calls 2

createReferencePatternFunction · 0.90
isLikelyReferenceSegmentFunction · 0.90

Tested by

no test coverage detected