MCPcopy Create free account
hub / github.com/Noumena-Network/code / extractArrayBodyFromAnchor

Function extractArrayBodyFromAnchor

scripts/run_runtime_dynamic_probe.mjs:12–27  ·  view source on GitHub ↗
(source, anchor)

Source from the content-addressed store, hash-verified

10const buildSource = await readFile(buildScriptPath, 'utf8')
11
12function extractArrayBodyFromAnchor(source, anchor) {
13 const anchorIndex = source.indexOf(anchor)
14 if (anchorIndex === -1) throw new Error(`Unable to find anchor: ${anchor}`)
15 const bracketStart = source.indexOf('[', anchorIndex + anchor.length)
16 if (bracketStart === -1) throw new Error(`Unable to find array start for anchor: ${anchor}`)
17 let depth = 0
18 for (let i = bracketStart; i < source.length; i += 1) {
19 const char = source[i]
20 if (char === '[') depth += 1
21 if (char === ']') {
22 depth -= 1
23 if (depth === 0) return source.slice(bracketStart + 1, i)
24 }
25 }
26 throw new Error(`Unable to parse array body for anchor: ${anchor}`)
27}
28
29function parseBuildFeatures(source) {
30 return [...extractArrayBodyFromAnchor(source, 'const buildFeatures =').matchAll(/'([^']+)'/g)]

Callers 1

parseBuildFeaturesFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected