MCPcopy Create free account
hub / github.com/testing-library/user-event / parseKeyDef

Function parseKeyDef

src/keyboard/parseKeyDef.ts:14–51  ·  view source on GitHub ↗
(keyboardMap: keyboardKey[], text: string)

Source from the content-addressed store, hash-verified

12 * You can then release the key per `{key>3/}` or keep it pressed and continue with the next key.
13 */
14export function parseKeyDef(keyboardMap: keyboardKey[], text: string) {
15 const defs: Array<{
16 keyDef: keyboardKey
17 releasePrevious: boolean
18 releaseSelf: boolean
19 repeat: number
20 }> = []
21
22 do {
23 const {
24 type,
25 descriptor,
26 consumedLength,
27 releasePrevious,
28 releaseSelf = true,
29 repeat,
30 } = readNextDescriptor(text, 'keyboard')
31
32 const keyDef = keyboardMap.find(def => {
33 if (type === '[') {
34 return def.code?.toLowerCase() === descriptor.toLowerCase()
35 } else if (type === '{') {
36 return def.key?.toLowerCase() === descriptor.toLowerCase()
37 }
38 return def.key === descriptor
39 }) ?? {
40 key: 'Unknown',
41 code: 'Unknown',
42 [type === '[' ? 'code' : 'key']: descriptor,
43 }
44
45 defs.push({keyDef, releasePrevious, releaseSelf, repeat})
46
47 text = text.slice(consumedLength)
48 } while (text)
49
50 return defs
51}

Callers 1

keyboardFunction · 0.90

Calls 1

readNextDescriptorFunction · 0.90

Tested by

no test coverage detected