@inquirer/confirm 6.4.0 → 6.4.1

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 (2) hide show
  1. package/dist/index.js +27 -7
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -1,5 +1,9 @@
1
1
  import { createPrompt, useState, useKeypress, isEnterKey, isTabKey, usePrefix, makeTheme, } from '@inquirer/core';
2
2
  import { styleText } from 'node:util';
3
+ const segmenter = new Intl.Segmenter();
4
+ function keywordInitial(keyword) {
5
+ return segmenter.segment(keyword).containing(0)?.segment.toLowerCase() ?? '';
6
+ }
3
7
  const confirmTheme = {
4
8
  keywords: {
5
9
  yes: 'Yes',
@@ -8,11 +12,10 @@ const confirmTheme = {
8
12
  },
9
13
  style: {
10
14
  confirmDefault: (text) => {
11
- const first = text[0] ?? '';
12
- if (first.toLowerCase() === first.toUpperCase()) {
15
+ if (text.toLowerCase() === text.toUpperCase()) {
13
16
  return styleText('cyan', text);
14
17
  }
15
- return first.toUpperCase() + text.slice(1);
18
+ return text.toUpperCase();
16
19
  },
17
20
  },
18
21
  };
@@ -25,8 +28,8 @@ export default createPrompt((config, done) => {
25
28
  const { yes, no } = theme.keywords;
26
29
  // The hint shows the first character of each label, lowercased; the default
27
30
  // side is then uppercased (or colored) by `confirmDefault`.
28
- const yesHint = (yes[0] ?? '').toLowerCase();
29
- const noHint = (no[0] ?? '').toLowerCase();
31
+ const yesHint = keywordInitial(yes);
32
+ const noHint = keywordInitial(no);
30
33
  const hint = config.default === false
31
34
  ? `${yesHint}/${theme.style.confirmDefault(noHint)}`
32
35
  : `${theme.style.confirmDefault(yesHint)}/${noHint}`;
@@ -42,9 +45,26 @@ export default createPrompt((config, done) => {
42
45
  // Empty input selects the default answer (the one highlighted in the hint).
43
46
  if (v === '')
44
47
  return config.default !== false;
45
- if (yes.toLowerCase().startsWith(v))
48
+ const yesKeyword = yes.toLowerCase();
49
+ const noKeyword = no.toLowerCase();
50
+ // Exact matches first, so typing the full no-keyword never answers yes
51
+ // just because the yes-keyword happens to start the same way (e.g.
52
+ // yes: "Nope-not", no: "No").
53
+ if (v === yesKeyword)
46
54
  return true;
47
- if (no.toLowerCase().startsWith(v))
55
+ if (v === noKeyword)
56
+ return false;
57
+ // The built-in English short answers come before prefix matching: a
58
+ // single `n` must answer no even when the yes-keyword starts with `n`
59
+ // (e.g. yes: "Nai").
60
+ if (v === 'y' || v === 'yes')
61
+ return true;
62
+ if (v === 'n' || v === 'no')
63
+ return false;
64
+ // Prefix matching, keywords before built-ins.
65
+ if (yesKeyword.startsWith(v))
66
+ return true;
67
+ if (noKeyword.startsWith(v))
48
68
  return false;
49
69
  if ('yes'.startsWith(v))
50
70
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/confirm",
3
- "version": "6.4.0",
3
+ "version": "6.4.1",
4
4
  "description": "Inquirer confirm prompt",
5
5
  "keywords": [
6
6
  "answer",
@@ -67,8 +67,8 @@
67
67
  "tsc": "tsc"
68
68
  },
69
69
  "dependencies": {
70
- "@inquirer/core": "^12.1.0",
71
- "@inquirer/type": "4.3.0"
70
+ "@inquirer/core": "^12.1.1",
71
+ "@inquirer/type": "4.3.1"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@repo/tsconfig": "0.1.0",
@@ -83,9 +83,9 @@
83
83
  }
84
84
  },
85
85
  "engines": {
86
- "node": "^22.22.2 || ^24.15.0 || >=26.0.0"
86
+ "node": ">=23.5.0 || ^22.13.0 || ^20.17.0"
87
87
  },
88
88
  "main": "./dist/index.js",
89
89
  "types": "./dist/index.d.ts",
90
- "gitHead": "00ded073f80523aaeaf8a903bbfb535994990475"
90
+ "gitHead": "6570b8e4d5e33a00dad2b55fa5f5fa5d148a245b"
91
91
  }