MCPcopy
hub / github.com/bombshell-dev/clack / constructor

Method constructor

packages/core/src/prompts/select-key.ts:12–40  ·  view source on GitHub ↗
(opts: SelectKeyOptions<T>)

Source from the content-addressed store, hash-verified

10 cursor = 0;
11
12 constructor(opts: SelectKeyOptions<T>) {
13 super(opts, false);
14
15 this.options = opts.options;
16 const caseSensitive = opts.caseSensitive === true;
17 const keys = this.options.map(({ value: [initial] }) => {
18 return caseSensitive ? initial : initial?.toLowerCase();
19 });
20 this.cursor = Math.max(keys.indexOf(opts.initialValue), 0);
21
22 this.on('key', (key) => {
23 if (!key) {
24 return;
25 }
26 const casedKey = caseSensitive ? key : key.toLowerCase();
27 if (!keys.includes(casedKey)) {
28 return;
29 }
30
31 const value = this.options.find(({ value: [initial] }) => {
32 return caseSensitive ? initial === casedKey : initial?.toLowerCase() === casedKey;
33 });
34 if (value) {
35 this.value = value.value;
36 this.state = 'submit';
37 this.emit('submit');
38 }
39 });
40 }
41}

Callers

nothing calls this directly

Calls 2

onMethod · 0.80
emitMethod · 0.80

Tested by

no test coverage detected