MCPcopy
hub / github.com/ChromeDevTools/chrome-devtools-mcp / parseKey

Function parseKey

src/utils/keyboard.ts:280–305  ·  view source on GitHub ↗
(keyInput: string)

Source from the content-addressed store, hash-verified

278 * Returns the primary key, followed by modifiers in original order.
279 */
280export function parseKey(keyInput: string): [KeyInput, ...KeyInput[]] {
281 let key = '';
282 const result: KeyInput[] = [];
283 for (const ch of keyInput) {
284 // Handle cases like Shift++.
285 if (ch === '+' && key) {
286 result.push(throwIfInvalidKey(key));
287 key = '';
288 } else {
289 key += ch;
290 }
291 }
292 if (key) {
293 result.push(throwIfInvalidKey(key));
294 }
295
296 if (result.length === 0) {
297 throw new Error(`Key ${keyInput} could not be parsed.`);
298 }
299
300 if (new Set(result).size !== result.length) {
301 throw new Error(`Key ${keyInput} contains duplicate keys.`);
302 }
303
304 return [result.at(-1), ...result.slice(0, -1)] as [KeyInput, ...KeyInput[]];
305}

Callers 2

input.tsFile · 0.85
input.test.tsFile · 0.85

Calls 2

throwIfInvalidKeyFunction · 0.85
sliceMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…