MCPcopy Create free account
hub / github.com/Script-Hub-Org/Script-Hub / parseSurgeTemplateArgumentPairs

Function parseSurgeTemplateArgumentPairs

Rewrite-Parser.beta.js:2234–2248  ·  view source on GitHub ↗
(str, renameMap = argumentKeyRenameMap)

Source from the content-addressed store, hash-verified

2232}
2233
2234function parseSurgeTemplateArgumentPairs(str, renameMap = argumentKeyRenameMap) {
2235 str = stripWrapQuote(str)
2236 if (!/(\{\{\{[^{}]+\}\}\}|\{[^{}]+\})/.test(str) || !/&/.test(str) && !/^\s*[^=\s]+\s*=/.test(str)) return []
2237 const items = splitTopLevel(str, '&')
2238 const pairs = []
2239 for (let i = 0; i < items.length; i++) {
2240 const matched = items[i].match(/^\s*([^=\s]+)\s*=\s*["']?(?:\{\{\{([^{}]+)\}\}\}|\{([^{}]+)\})["']?\s*$/)
2241 if (!matched) return []
2242 const scriptKey = matched[1].trim()
2243 const templateKey = (matched[2] || matched[3] || '').trim()
2244 if (scriptKey && templateKey) renameMap.set(templateKey, scriptKey)
2245 pairs.push({ scriptKey, templateKey })
2246 }
2247 return pairs
2248}
2249
2250function getSurgeTemplateArgumentListKeys(str) {
2251 return parseSurgeTemplateArgumentPairs(str).map(item => item.scriptKey)

Callers 2

Calls 2

stripWrapQuoteFunction · 0.85
splitTopLevelFunction · 0.85

Tested by

no test coverage detected