MCPcopy Index your code
hub / github.com/CopilotKit/OpenTag / isBalanced

Function isBalanced

e2e/slack-api.ts:241–264  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

239 * language line) but no closer.
240 */
241export function isBalanced(text: string): boolean {
242 if (!text) return true;
243
244 // ── Fences ─────────────────────────────────────────────────────
245 const fences = (text.match(/```/g) || []).length;
246 if (fences % 2 !== 0) {
247 const lastFenceIdx = text.lastIndexOf("```");
248 const tail = text.slice(lastFenceIdx + 3);
249 const nl = tail.indexOf("\n");
250 const codeBody = nl >= 0 ? tail.slice(nl + 1) : "";
251 if (/\S/.test(codeBody)) return false; // real content past the lang line
252 // else: just-opened fence; treat as balanced
253 }
254
255 // ── Inline backticks (outside fences) ──────────────────────────
256 const noFence = text.replace(/```[\s\S]*?```/g, "");
257 const inline = (noFence.match(/`/g) || []).length;
258 if (inline % 2 !== 0) {
259 const lastBt = noFence.lastIndexOf("`");
260 const after = noFence.slice(lastBt + 1);
261 if (/\S/.test(after)) return false; // real content past the open backtick
262 }
263 return true;
264}

Callers 6

runExpectationsFunction · 0.70
onSampleFunction · 0.70
runCaseFunction · 0.70
runExpectationsFunction · 0.70
onSampleFunction · 0.70
runCaseFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected