inquirerer 0.10.0 → 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.
Files changed (3) hide show
  1. package/esm/prompt.js +22 -9
  2. package/package.json +2 -2
  3. package/prompt.js +22 -9
package/esm/prompt.js CHANGED
@@ -6,11 +6,8 @@ function generatePromptMessage(question, ctx) {
6
6
  let promptMessage = '';
7
7
  if (question.message) {
8
8
  promptMessage = chalk.whiteBright(question.message) + '\n';
9
- promptMessage += `${chalk.white('[')}${chalk.green('--' + question.name)}${chalk.white(']:')}\n`;
10
- }
11
- else {
12
- promptMessage = `${chalk.white('[')}${chalk.green('--' + question.name)}${chalk.white(']:')}\n`;
13
9
  }
10
+ promptMessage += `${chalk.white('[')}${chalk.green('--' + question.name)}${chalk.white(']:')}\n`;
14
11
  if (ctx.numTries > 0 && question.required) {
15
12
  promptMessage = requiredMessage(question) + promptMessage;
16
13
  }
@@ -195,7 +192,7 @@ export class Inquirerer {
195
192
  const maxLines = this.getMaxLines(question, options.length); // Use provided max or total options
196
193
  const selections = new Array(options.length).fill(false);
197
194
  const updateFilteredOptions = () => {
198
- filteredOptions = options.filter(option => option.name.toLowerCase().includes(input.toLowerCase()));
195
+ filteredOptions = this.filterOptions(options, input);
199
196
  };
200
197
  const display = () => {
201
198
  this.clearScreen();
@@ -377,16 +374,32 @@ export class Inquirerer {
377
374
  });
378
375
  }
379
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
+ };
380
393
  return options
381
- .filter(option => option.name.toLowerCase().startsWith(input.toLowerCase()))
394
+ .filter(option => fuzzyMatch(option.name.toLowerCase(), input))
382
395
  .sort((a, b) => {
383
396
  if (a.name < b.name) {
384
- return -1; // b first
397
+ return -1;
385
398
  }
386
399
  if (a.name > b.name) {
387
- return 1; // a is first
400
+ return 1;
388
401
  }
389
- return 0; // equal
402
+ return 0;
390
403
  });
391
404
  }
392
405
  getMaxLines(question, defaultLength) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inquirerer",
3
- "version": "0.10.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": "b95bf2e5c0dbabf5def8da9d1486faa097defd3e"
38
+ "gitHead": "b99717ce3268eb9a2b14484976041c986629c36b"
39
39
  }
package/prompt.js CHANGED
@@ -12,11 +12,8 @@ function generatePromptMessage(question, ctx) {
12
12
  let promptMessage = '';
13
13
  if (question.message) {
14
14
  promptMessage = chalk_1.default.whiteBright(question.message) + '\n';
15
- promptMessage += `${chalk_1.default.white('[')}${chalk_1.default.green('--' + question.name)}${chalk_1.default.white(']:')}\n`;
16
- }
17
- else {
18
- promptMessage = `${chalk_1.default.white('[')}${chalk_1.default.green('--' + question.name)}${chalk_1.default.white(']:')}\n`;
19
15
  }
16
+ promptMessage += `${chalk_1.default.white('[')}${chalk_1.default.green('--' + question.name)}${chalk_1.default.white(']:')}\n`;
20
17
  if (ctx.numTries > 0 && question.required) {
21
18
  promptMessage = requiredMessage(question) + promptMessage;
22
19
  }
@@ -201,7 +198,7 @@ class Inquirerer {
201
198
  const maxLines = this.getMaxLines(question, options.length); // Use provided max or total options
202
199
  const selections = new Array(options.length).fill(false);
203
200
  const updateFilteredOptions = () => {
204
- filteredOptions = options.filter(option => option.name.toLowerCase().includes(input.toLowerCase()));
201
+ filteredOptions = this.filterOptions(options, input);
205
202
  };
206
203
  const display = () => {
207
204
  this.clearScreen();
@@ -383,16 +380,32 @@ class Inquirerer {
383
380
  });
384
381
  }
385
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
+ };
386
399
  return options
387
- .filter(option => option.name.toLowerCase().startsWith(input.toLowerCase()))
400
+ .filter(option => fuzzyMatch(option.name.toLowerCase(), input))
388
401
  .sort((a, b) => {
389
402
  if (a.name < b.name) {
390
- return -1; // b first
403
+ return -1;
391
404
  }
392
405
  if (a.name > b.name) {
393
- return 1; // a is first
406
+ return 1;
394
407
  }
395
- return 0; // equal
408
+ return 0;
396
409
  });
397
410
  }
398
411
  getMaxLines(question, defaultLength) {