MCPcopy Create free account
hub / github.com/Maksandre/w3wallets / parseExtensionTarget

Function parseExtensionTarget

packages/w3wallets/src/scripts/download.js:135–179  ·  view source on GitHub ↗

* Parse extension ID from various input formats: * - Known alias (case-insensitive): "metamask", "MetaMask", "MM" * - Direct extension ID: "nkbihfbeogaeaoehlefnkodbefgpgknn" * - Chrome Web Store URL: "https://chromewebstore.google.com/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn"

(input)

Source from the content-addressed store, hash-verified

133 * - Chrome Web Store URL: "https://chromewebstore.google.com/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn"
134 */
135function parseExtensionTarget(input) {
136 // Check for known alias (case-insensitive)
137 const normalizedInput = input.toLowerCase();
138 if (EXTENSION_REGISTRY[normalizedInput]) {
139 const id = EXTENSION_REGISTRY[normalizedInput];
140 // Find canonical alias name for directory
141 const alias = CANONICAL_ALIASES.find((a) => a.id === id);
142 return {
143 id,
144 name: EXTENSION_NAMES[id] || normalizedInput,
145 dirName: alias ? alias.name : id,
146 };
147 }
148
149 // Check if it's a Chrome Web Store URL
150 const urlPatterns = [
151 /chromewebstore\.google\.com\/detail\/[^/]+\/([a-z]{32})/i,
152 /chrome\.google\.com\/webstore\/detail\/[^/]+\/([a-z]{32})/i,
153 ];
154 for (const pattern of urlPatterns) {
155 const match = input.match(pattern);
156 if (match) {
157 const id = match[1].toLowerCase();
158 const alias = CANONICAL_ALIASES.find((a) => a.id === id);
159 return {
160 id,
161 name: EXTENSION_NAMES[id] || id,
162 dirName: alias ? alias.name : id,
163 };
164 }
165 }
166
167 // Check if it's a direct extension ID (32 lowercase letters)
168 if (/^[a-z]{32}$/i.test(input)) {
169 const id = input.toLowerCase();
170 const alias = CANONICAL_ALIASES.find((a) => a.id === id);
171 return {
172 id,
173 name: EXTENSION_NAMES[id] || id,
174 dirName: alias ? alias.name : id,
175 };
176 }
177
178 return null;
179}
180
181function parseArgs(args) {
182 let i = 0;

Callers 1

parseArgsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected