docs/ext/extensionRepos/attrs.ts
16 lines · 513 bytes
1 symbol in this file
1export function parseExtRepoAttrs(text: string): Record<string, string> {
2 const match = text.match(/\{([^}]*)\}/)
3 if (!match) return {}
4 const attrs: Record<string, string> = {}
5 for (const token of match[1].split(/[\s,]+/).filter(Boolean)) {
6 const eq = token.indexOf('=')
7 if (eq < 0) {
8 attrs[token] = 'true'
9 continue
10 }
11 const key = token.slice(0, eq)
12 const value = token.slice(eq + 1)
13 if (key && value) attrs[key] = value.replace(/^["']|["']$/g, '')
14 }
15 return attrs
16}