inquirerer 0.10.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/prompt.js +38 -15
- package/package.json +2 -2
- package/prompt.d.ts +2 -1
- package/prompt.js +38 -15
package/esm/prompt.js
CHANGED
|
@@ -184,7 +184,7 @@ export class Inquirerer {
|
|
|
184
184
|
if (this.noTty || !this.rl)
|
|
185
185
|
return question.default ?? []; // Return default if non-interactive
|
|
186
186
|
this.keypress.resume();
|
|
187
|
-
const options =
|
|
187
|
+
const options = this.sanitizeOptions(question);
|
|
188
188
|
let input = ''; // Search input
|
|
189
189
|
let filteredOptions = options;
|
|
190
190
|
let selectedIndex = 0;
|
|
@@ -192,7 +192,7 @@ export class Inquirerer {
|
|
|
192
192
|
const maxLines = this.getMaxLines(question, options.length); // Use provided max or total options
|
|
193
193
|
const selections = new Array(options.length).fill(false);
|
|
194
194
|
const updateFilteredOptions = () => {
|
|
195
|
-
filteredOptions =
|
|
195
|
+
filteredOptions = this.filterOptions(options, input);
|
|
196
196
|
};
|
|
197
197
|
const display = () => {
|
|
198
198
|
this.clearScreen();
|
|
@@ -281,19 +281,11 @@ export class Inquirerer {
|
|
|
281
281
|
});
|
|
282
282
|
});
|
|
283
283
|
}
|
|
284
|
-
getOptionValue(option) {
|
|
285
|
-
if (typeof option === 'string') {
|
|
286
|
-
return { name: option, value: option };
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
return { name: option.name, value: option.value };
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
284
|
async autocomplete(question, ctx) {
|
|
293
285
|
if (this.noTty || !this.rl)
|
|
294
286
|
return question.default ?? false; // Return default if non-interactive
|
|
295
287
|
this.keypress.resume();
|
|
296
|
-
const options =
|
|
288
|
+
const options = this.sanitizeOptions(question);
|
|
297
289
|
let input = '';
|
|
298
290
|
let filteredOptions = options;
|
|
299
291
|
let selectedIndex = 0;
|
|
@@ -373,17 +365,48 @@ export class Inquirerer {
|
|
|
373
365
|
});
|
|
374
366
|
});
|
|
375
367
|
}
|
|
368
|
+
getOptionValue(option) {
|
|
369
|
+
if (typeof option === 'string') {
|
|
370
|
+
return { name: option, value: option };
|
|
371
|
+
}
|
|
372
|
+
else if (typeof option === 'object' && 'name' in option) {
|
|
373
|
+
return { name: option.name, value: option.value };
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
return undefined;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
sanitizeOptions(question) {
|
|
380
|
+
const options = (question.options ?? []).map(option => this.getOptionValue(option));
|
|
381
|
+
return options.filter(Boolean);
|
|
382
|
+
}
|
|
376
383
|
filterOptions(options, input) {
|
|
384
|
+
input = input.toLowerCase(); // Normalize input for case-insensitive comparison
|
|
385
|
+
// Fuzzy matching: Check if all characters of the input can be found in the option name in order
|
|
386
|
+
const fuzzyMatch = (option, input) => {
|
|
387
|
+
const length = input.length;
|
|
388
|
+
let position = 0; // Position in the input string
|
|
389
|
+
// Iterate over each character in the option name
|
|
390
|
+
for (let i = 0; i < option.length; i++) {
|
|
391
|
+
if (option[i] === input[position]) {
|
|
392
|
+
position++; // Move to the next character in the input
|
|
393
|
+
if (position === length) { // Check if we've matched all characters
|
|
394
|
+
return true;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return false;
|
|
399
|
+
};
|
|
377
400
|
return options
|
|
378
|
-
.filter(option => option.name.toLowerCase()
|
|
401
|
+
.filter(option => fuzzyMatch(option.name.toLowerCase(), input))
|
|
379
402
|
.sort((a, b) => {
|
|
380
403
|
if (a.name < b.name) {
|
|
381
|
-
return -1;
|
|
404
|
+
return -1;
|
|
382
405
|
}
|
|
383
406
|
if (a.name > b.name) {
|
|
384
|
-
return 1;
|
|
407
|
+
return 1;
|
|
385
408
|
}
|
|
386
|
-
return 0;
|
|
409
|
+
return 0;
|
|
387
410
|
});
|
|
388
411
|
}
|
|
389
412
|
getMaxLines(question, defaultLength) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inquirerer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
5
|
"description": "inquirerer",
|
|
6
6
|
"main": "index.js",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"minimist": "^1.2.8"
|
|
36
36
|
},
|
|
37
37
|
"keywords": [],
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "181e8fae97cb71bee0678a110d0b81d06f618f02"
|
|
39
39
|
}
|
package/prompt.d.ts
CHANGED
|
@@ -30,8 +30,9 @@ export declare class Inquirerer {
|
|
|
30
30
|
confirm(question: ConfirmQuestion, ctx: PromptContext): Promise<boolean>;
|
|
31
31
|
text(question: TextQuestion, ctx: PromptContext): Promise<string | null>;
|
|
32
32
|
checkbox(question: CheckboxQuestion, ctx: PromptContext): Promise<OptionValue[]>;
|
|
33
|
-
private getOptionValue;
|
|
34
33
|
autocomplete(question: AutocompleteQuestion, ctx: PromptContext): Promise<any>;
|
|
34
|
+
private getOptionValue;
|
|
35
|
+
private sanitizeOptions;
|
|
35
36
|
filterOptions(options: OptionValue[], input: string): OptionValue[];
|
|
36
37
|
getMaxLines(question: {
|
|
37
38
|
maxDisplayLines?: number;
|
package/prompt.js
CHANGED
|
@@ -190,7 +190,7 @@ class Inquirerer {
|
|
|
190
190
|
if (this.noTty || !this.rl)
|
|
191
191
|
return question.default ?? []; // Return default if non-interactive
|
|
192
192
|
this.keypress.resume();
|
|
193
|
-
const options =
|
|
193
|
+
const options = this.sanitizeOptions(question);
|
|
194
194
|
let input = ''; // Search input
|
|
195
195
|
let filteredOptions = options;
|
|
196
196
|
let selectedIndex = 0;
|
|
@@ -198,7 +198,7 @@ class Inquirerer {
|
|
|
198
198
|
const maxLines = this.getMaxLines(question, options.length); // Use provided max or total options
|
|
199
199
|
const selections = new Array(options.length).fill(false);
|
|
200
200
|
const updateFilteredOptions = () => {
|
|
201
|
-
filteredOptions =
|
|
201
|
+
filteredOptions = this.filterOptions(options, input);
|
|
202
202
|
};
|
|
203
203
|
const display = () => {
|
|
204
204
|
this.clearScreen();
|
|
@@ -287,19 +287,11 @@ class Inquirerer {
|
|
|
287
287
|
});
|
|
288
288
|
});
|
|
289
289
|
}
|
|
290
|
-
getOptionValue(option) {
|
|
291
|
-
if (typeof option === 'string') {
|
|
292
|
-
return { name: option, value: option };
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
return { name: option.name, value: option.value };
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
290
|
async autocomplete(question, ctx) {
|
|
299
291
|
if (this.noTty || !this.rl)
|
|
300
292
|
return question.default ?? false; // Return default if non-interactive
|
|
301
293
|
this.keypress.resume();
|
|
302
|
-
const options =
|
|
294
|
+
const options = this.sanitizeOptions(question);
|
|
303
295
|
let input = '';
|
|
304
296
|
let filteredOptions = options;
|
|
305
297
|
let selectedIndex = 0;
|
|
@@ -379,17 +371,48 @@ class Inquirerer {
|
|
|
379
371
|
});
|
|
380
372
|
});
|
|
381
373
|
}
|
|
374
|
+
getOptionValue(option) {
|
|
375
|
+
if (typeof option === 'string') {
|
|
376
|
+
return { name: option, value: option };
|
|
377
|
+
}
|
|
378
|
+
else if (typeof option === 'object' && 'name' in option) {
|
|
379
|
+
return { name: option.name, value: option.value };
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
return undefined;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
sanitizeOptions(question) {
|
|
386
|
+
const options = (question.options ?? []).map(option => this.getOptionValue(option));
|
|
387
|
+
return options.filter(Boolean);
|
|
388
|
+
}
|
|
382
389
|
filterOptions(options, input) {
|
|
390
|
+
input = input.toLowerCase(); // Normalize input for case-insensitive comparison
|
|
391
|
+
// Fuzzy matching: Check if all characters of the input can be found in the option name in order
|
|
392
|
+
const fuzzyMatch = (option, input) => {
|
|
393
|
+
const length = input.length;
|
|
394
|
+
let position = 0; // Position in the input string
|
|
395
|
+
// Iterate over each character in the option name
|
|
396
|
+
for (let i = 0; i < option.length; i++) {
|
|
397
|
+
if (option[i] === input[position]) {
|
|
398
|
+
position++; // Move to the next character in the input
|
|
399
|
+
if (position === length) { // Check if we've matched all characters
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return false;
|
|
405
|
+
};
|
|
383
406
|
return options
|
|
384
|
-
.filter(option => option.name.toLowerCase()
|
|
407
|
+
.filter(option => fuzzyMatch(option.name.toLowerCase(), input))
|
|
385
408
|
.sort((a, b) => {
|
|
386
409
|
if (a.name < b.name) {
|
|
387
|
-
return -1;
|
|
410
|
+
return -1;
|
|
388
411
|
}
|
|
389
412
|
if (a.name > b.name) {
|
|
390
|
-
return 1;
|
|
413
|
+
return 1;
|
|
391
414
|
}
|
|
392
|
-
return 0;
|
|
415
|
+
return 0;
|
|
393
416
|
});
|
|
394
417
|
}
|
|
395
418
|
getMaxLines(question, defaultLength) {
|