MCPcopy Create free account
hub / github.com/awslabs/llrt / codeToRegex

Function codeToRegex

build.mjs:368–392  ·  view source on GitHub ↗
(fn, includeSignature = false)

Source from the content-addressed store, hash-verified

366 }
367 }
368 return str;
369}
370
371function codeToRegex(fn, includeSignature = false) {
372 return new RegExp(
373 fn
374 .toString()
375 .split("\n")
376 .reduce((acc, line, index, array) => {
377 if (includeSignature || (index > 0 && index < array.length - 1)) {
378 acc.push(line.trim());
379 }
380 return acc;
381 }, [])
382 .join("\n")
383 .replace(/\s+/g, "\\s*")
384 .replace(/\(/g, "\\(")
385 .replace(/\)/g, "\\)")
386 .replace(/\./g, "\\.")
387 .replace(/\?,/g, "\\?")
388 .replace(/\,/g, ",?")
389 .replace(/\$/g, "\\$")
390 .replace(/\{/g, "\\s*{")
391 .replace(/\}/g, "}\\s*")
392 .replace(/\|/g, "\\|"),
393 "g"
394 );
395}

Callers 1

setupFunction · 0.85

Calls 3

joinMethod · 0.80
pushMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected