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

Function formatLoonJsonArgument

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

Source from the content-addressed store, hash-verified

2147}
2148
2149function formatLoonJsonArgument(str, renameMap = argumentKeyRenameMap) {
2150 const objectBody = unwrapJsonArgument(str, 'loon-plugin')
2151 .replace(/["']([^"']+)["']\s*:/g, '$1:')
2152 .replace(/:\s*["']?\{\{\{([^{}]+)\}\}\}["']?/g, ':$1')
2153 .replace(/:\s*["']?\{\{([^{}]+)\}\}["']?/g, ':$1')
2154 .replace(/:\s*["']?\{([^{}]+)\}["']?/g, ':$1')
2155 .replace(/^\s*\{|\}\s*$/g, '')
2156 return splitTopLevel(objectBody, ',')
2157 .filter(Boolean)
2158 .map(item => {
2159 const [key, value] = splitFirstTopLevel(item, ':')
2160 const scriptKey = stripWrapQuote(key).replace(/^\\+|\\+$/g, '')
2161 const templateKey = stripWrapQuote(value).replace(/^\{+|\}+$/g, '').replace(/^\\+|\\+$/g, '')
2162 if (templateKey && scriptKey) renameMap.set(templateKey, scriptKey)
2163 return `{${scriptKey}}`
2164 })
2165 .join(',')
2166}
2167
2168function collectArgumentKeyRenameMap(box) {
2169 for (let i = 0; i < box.length; i++) {

Callers 2

normalizeScriptArgumentFunction · 0.85

Calls 4

unwrapJsonArgumentFunction · 0.85
splitTopLevelFunction · 0.85
splitFirstTopLevelFunction · 0.85
stripWrapQuoteFunction · 0.85

Tested by

no test coverage detected