MCPcopy Create free account
hub / github.com/ForestHubAI/edge-agents / wrapStringTemplate

Function wrapStringTemplate

ts/workflow-core/src/expression/parser.ts:350–365  ·  view source on GitHub ↗

* Wrap bare text in a string-type expression into quoted string literals for jsep. * Splits by variable placeholders (__varN__), quotes text segments, joins with +. * E.g. `hello __var0__` → `"hello " + __var0__`

(expr: string)

Source from the content-addressed store, hash-verified

348 if (from === "image") return false;
349 if (to === "string") return true;
350 return false;
351}
352
353/**
354 * Wrap bare text in a string-type expression into quoted string literals for jsep.
355 * Splits by variable placeholders (__varN__), quotes text segments, joins with +.
356 * E.g. `hello __var0__` → `"hello " + __var0__`
357 */
358function wrapStringTemplate(expr: string): string {
359 // Split by __varN__ placeholders but keep them as delimiters
360 const parts = expr.split(/(__var\d+__)/);
361 const segments: string[] = [];
362
363 for (const part of parts) {
364 if (/^__var\d+__$/.test(part)) {
365 segments.push(part);
366 } else if (part !== "") {
367 const escaped = part.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
368 segments.push(`"${escaped}"`);

Callers 1

parseExpressionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected