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

Function parseMetadata

scripts/generate_slash_command_appendix.mjs:275–299  ·  view source on GitHub ↗
(source)

Source from the content-addressed store, hash-verified

273}
274
275function parseMetadata(source) {
276 const firstMatch = pattern => source.match(pattern)?.[1] ?? ''
277 const name = firstMatch(/name:\s*'([^']+)'/)
278 const type = firstMatch(/type:\s*'([^']+)'/)
279 const description = firstMatch(/description:\s*`([^`]+)`/) || firstMatch(/description:\s*'([^']+)'/)
280 const argumentHint = firstMatch(/argumentHint:\s*'([^']+)'/)
281 const aliases = parseSimpleStringArray(source, 'aliases')
282 const availability = parseSimpleStringArray(source, 'availability')
283 const immediate = source.match(/immediate:\s*(true|false)/)?.[1] ?? ''
284 const hiddenKind =
285 source.match(/isHidden:\s*(true|false)/)?.[1] ??
286 (source.includes('get isHidden()') ? 'getter' : '')
287 const hasIsEnabled = source.includes('isEnabled:')
288 return {
289 name,
290 type,
291 description,
292 argumentHint,
293 aliases,
294 availability,
295 immediate,
296 hiddenKind,
297 hasIsEnabled,
298 }
299}
300
301function parseBooleanField(source, fieldName) {
302 return source.match(new RegExp(`${fieldName}:\\s*(true|false)`))?.[1] ?? ''

Calls 2

firstMatchFunction · 0.85
parseSimpleStringArrayFunction · 0.85

Tested by

no test coverage detected