MCPcopy
hub / github.com/ZToolsCenter/ZTools / normalizeCommandAliases

Function normalizeCommandAliases

src/shared/commandShared.ts:76–106  ·  view source on GitHub ↗
(
  store: CommandAliasStore | null | undefined
)

Source from the content-addressed store, hash-verified

74 * 4. 移除归一化后为空的 commandId bucket
75 */
76export function normalizeCommandAliases(
77 store: CommandAliasStore | null | undefined
78): CommandAliasStore {
79 const normalized: CommandAliasStore = {}
80
81 for (const [commandId, aliases] of Object.entries(store || {})) {
82 const nextAliases = Array.from(
83 new Map(
84 ((aliases || []) as Array<string | CommandAliasEntry>)
85 .map((aliasEntry) => {
86 if (typeof aliasEntry === 'string') {
87 return { alias: aliasEntry.trim(), icon: undefined }
88 }
89
90 return {
91 alias: (aliasEntry?.alias || '').trim(),
92 icon: aliasEntry?.icon || undefined
93 }
94 })
95 .filter((aliasEntry) => Boolean(aliasEntry.alias))
96 .map((aliasEntry) => [aliasEntry.alias, aliasEntry] as const)
97 ).values()
98 )
99
100 if (nextAliases.length > 0) {
101 normalized[commandId] = nextAliases
102 }
103 }
104
105 return normalized
106}

Callers 2

loadCommandAliasesFunction · 0.90
setupIPCMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected