inquirerer 0.10.1 → 0.11.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 +21 -5
- package/package.json +2 -2
- package/prompt.js +21 -5
package/esm/prompt.js
CHANGED
|
@@ -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();
|
|
@@ -374,16 +374,32 @@ export class Inquirerer {
|
|
|
374
374
|
});
|
|
375
375
|
}
|
|
376
376
|
filterOptions(options, input) {
|
|
377
|
+
input = input.toLowerCase(); // Normalize input for case-insensitive comparison
|
|
378
|
+
// Fuzzy matching: Check if all characters of the input can be found in the option name in order
|
|
379
|
+
const fuzzyMatch = (option, input) => {
|
|
380
|
+
const length = input.length;
|
|
381
|
+
let position = 0; // Position in the input string
|
|
382
|
+
// Iterate over each character in the option name
|
|
383
|
+
for (let i = 0; i < option.length; i++) {
|
|
384
|
+
if (option[i] === input[position]) {
|
|
385
|
+
position++; // Move to the next character in the input
|
|
386
|
+
if (position === length) { // Check if we've matched all characters
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return false;
|
|
392
|
+
};
|
|
377
393
|
return options
|
|
378
|
-
.filter(option => option.name.toLowerCase()
|
|
394
|
+
.filter(option => fuzzyMatch(option.name.toLowerCase(), input))
|
|
379
395
|
.sort((a, b) => {
|
|
380
396
|
if (a.name < b.name) {
|
|
381
|
-
return -1;
|
|
397
|
+
return -1;
|
|
382
398
|
}
|
|
383
399
|
if (a.name > b.name) {
|
|
384
|
-
return 1;
|
|
400
|
+
return 1;
|
|
385
401
|
}
|
|
386
|
-
return 0;
|
|
402
|
+
return 0;
|
|
387
403
|
});
|
|
388
404
|
}
|
|
389
405
|
getMaxLines(question, defaultLength) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inquirerer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.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": "b99717ce3268eb9a2b14484976041c986629c36b"
|
|
39
39
|
}
|
package/prompt.js
CHANGED
|
@@ -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();
|
|
@@ -380,16 +380,32 @@ class Inquirerer {
|
|
|
380
380
|
});
|
|
381
381
|
}
|
|
382
382
|
filterOptions(options, input) {
|
|
383
|
+
input = input.toLowerCase(); // Normalize input for case-insensitive comparison
|
|
384
|
+
// Fuzzy matching: Check if all characters of the input can be found in the option name in order
|
|
385
|
+
const fuzzyMatch = (option, input) => {
|
|
386
|
+
const length = input.length;
|
|
387
|
+
let position = 0; // Position in the input string
|
|
388
|
+
// Iterate over each character in the option name
|
|
389
|
+
for (let i = 0; i < option.length; i++) {
|
|
390
|
+
if (option[i] === input[position]) {
|
|
391
|
+
position++; // Move to the next character in the input
|
|
392
|
+
if (position === length) { // Check if we've matched all characters
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return false;
|
|
398
|
+
};
|
|
383
399
|
return options
|
|
384
|
-
.filter(option => option.name.toLowerCase()
|
|
400
|
+
.filter(option => fuzzyMatch(option.name.toLowerCase(), input))
|
|
385
401
|
.sort((a, b) => {
|
|
386
402
|
if (a.name < b.name) {
|
|
387
|
-
return -1;
|
|
403
|
+
return -1;
|
|
388
404
|
}
|
|
389
405
|
if (a.name > b.name) {
|
|
390
|
-
return 1;
|
|
406
|
+
return 1;
|
|
391
407
|
}
|
|
392
|
-
return 0;
|
|
408
|
+
return 0;
|
|
393
409
|
});
|
|
394
410
|
}
|
|
395
411
|
getMaxLines(question, defaultLength) {
|