@inquirer/confirm 0.0.19-alpha.0 → 0.0.22-alpha.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/dist/index.d.ts +8 -0
- package/dist/index.js +28 -0
- package/package.json +14 -6
- package/demo.js +0 -16
- package/index.js +0 -32
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { createPrompt, useState, useKeypress, isEnterKey, usePrefix, } from '@inquirer/core';
|
|
3
|
+
export default createPrompt((config, done) => {
|
|
4
|
+
const [status, setStatus] = useState('pending');
|
|
5
|
+
const [value, setValue] = useState('');
|
|
6
|
+
const prefix = usePrefix();
|
|
7
|
+
useKeypress((key, rl) => {
|
|
8
|
+
if (isEnterKey(key)) {
|
|
9
|
+
const answer = value ? /^y(es)?/i.test(value) : config.default !== false;
|
|
10
|
+
setValue(answer ? 'yes' : 'no');
|
|
11
|
+
setStatus('done');
|
|
12
|
+
done(answer);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
setValue(rl.line);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
let formattedValue = value;
|
|
19
|
+
let defaultValue = '';
|
|
20
|
+
if (status === 'done') {
|
|
21
|
+
formattedValue = chalk.cyan(value);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
defaultValue = chalk.dim(config.default === false ? ' (y/N)' : ' (Y/n)');
|
|
25
|
+
}
|
|
26
|
+
const message = chalk.bold(config.message);
|
|
27
|
+
return `${prefix} ${message}${defaultValue} ${formattedValue}`;
|
|
28
|
+
});
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/confirm",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.22-alpha.0",
|
|
4
5
|
"description": "Inquirer confirm prompt",
|
|
5
|
-
"main": "index.js",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"typings": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/"
|
|
10
|
+
],
|
|
6
11
|
"repository": "SBoudrias/Inquirer.js",
|
|
7
12
|
"keywords": [
|
|
8
13
|
"cli",
|
|
@@ -17,12 +22,15 @@
|
|
|
17
22
|
"license": "MIT",
|
|
18
23
|
"homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/confirm/README.md",
|
|
19
24
|
"dependencies": {
|
|
20
|
-
"@inquirer/core": "^0.0.
|
|
21
|
-
"@inquirer/input": "^0.0.
|
|
22
|
-
"chalk": "^
|
|
25
|
+
"@inquirer/core": "^0.0.23-alpha.0",
|
|
26
|
+
"@inquirer/input": "^0.0.23-alpha.0",
|
|
27
|
+
"chalk": "^5.0.1"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"tsc": "tsc"
|
|
23
31
|
},
|
|
24
32
|
"publishConfig": {
|
|
25
33
|
"access": "public"
|
|
26
34
|
},
|
|
27
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "a95b68efa6f407cefff63300e7e50da34c6b6693"
|
|
28
36
|
}
|
package/demo.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const confirm = require('.');
|
|
2
|
-
|
|
3
|
-
(async () => {
|
|
4
|
-
let answer;
|
|
5
|
-
|
|
6
|
-
answer = await confirm({
|
|
7
|
-
message: 'Confirm?',
|
|
8
|
-
});
|
|
9
|
-
console.log('Answer:', answer);
|
|
10
|
-
|
|
11
|
-
answer = await confirm({
|
|
12
|
-
message: 'Confirm with default to no?',
|
|
13
|
-
default: false,
|
|
14
|
-
});
|
|
15
|
-
console.log('Answer:', answer);
|
|
16
|
-
})();
|
package/index.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const chalk = require('chalk');
|
|
2
|
-
const { createPrompt, useState, useKeypress } = require('@inquirer/core/hooks');
|
|
3
|
-
const { isEnterKey } = require('@inquirer/core/lib/key');
|
|
4
|
-
const { usePrefix } = require('@inquirer/core/lib/prefix');
|
|
5
|
-
|
|
6
|
-
module.exports = createPrompt((config, done) => {
|
|
7
|
-
const [status, setStatus] = useState('pending');
|
|
8
|
-
const [value, setValue] = useState('');
|
|
9
|
-
const prefix = usePrefix();
|
|
10
|
-
|
|
11
|
-
useKeypress((key, rl) => {
|
|
12
|
-
if (isEnterKey(key)) {
|
|
13
|
-
const answer = value ? /^y(es)?/i.test(value) : config.default !== false;
|
|
14
|
-
setValue(answer ? 'yes' : 'no');
|
|
15
|
-
setStatus('done');
|
|
16
|
-
done(answer);
|
|
17
|
-
} else {
|
|
18
|
-
setValue(rl.line);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
let formattedValue = value;
|
|
23
|
-
let defaultValue = '';
|
|
24
|
-
if (status === 'done') {
|
|
25
|
-
formattedValue = chalk.cyan(value);
|
|
26
|
-
} else {
|
|
27
|
-
defaultValue = chalk.dim(config.default === false ? ' (y/N)' : ' (Y/n)');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const message = chalk.bold(config.message);
|
|
31
|
-
return `${prefix} ${message}${defaultValue} ${formattedValue}`;
|
|
32
|
-
});
|