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

Function normalizeScriptArgument

Rewrite-Parser.beta.js:2254–2269  ·  view source on GitHub ↗
(jsarg, targetApp)

Source from the content-addressed store, hash-verified

2252}
2253
2254function normalizeScriptArgument(jsarg, targetApp) {
2255 if (!jsarg) return jsarg
2256 const loonKeys = getLoonArgumentKeys(jsarg)
2257 if ((targetApp == 'surge-module' || targetApp == 'shadowrocket-module') && loonKeys.length > 0) {
2258 return loonKeys.map(key => `${key}="{{{${key}}}}"`).join('&')
2259 }
2260 if (targetApp == 'loon-plugin') {
2261 if (isJsonObjectArgument(jsarg)) return `[${formatLoonJsonArgument(jsarg)}]`
2262 const surgeListKeys = getSurgeTemplateArgumentListKeys(jsarg)
2263 if (surgeListKeys.length > 0) return `[${surgeListKeys.map(key => `{${key}}`).join(',')}]`
2264 const surgeKeys = getSurgeTemplateArgumentKeys(jsarg)
2265 if (surgeKeys.length > 0) return `[${surgeKeys.map(key => `{${key}}`).join(',')}]`
2266 }
2267 if (targetApp == 'loon-plugin') return normalizeTemplateValue(jsarg, targetApp)
2268 return jsarg
2269}
2270
2271function takeLeadingTemplate(str) {
2272 const matched = `${str ?? ''}`.match(/^(\s*)\{\{\{([^{}]+)\}\}\}\s*(.*)$/)

Callers 1

Calls 6

getLoonArgumentKeysFunction · 0.85
isJsonObjectArgumentFunction · 0.85
formatLoonJsonArgumentFunction · 0.85
normalizeTemplateValueFunction · 0.85

Tested by

no test coverage detected