@inquirer/rawlist 0.0.10-alpha.0 → 0.1.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.
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const core_1 = require("@inquirer/core");
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const numberRegex = /[0-9]+/;
9
+ exports.default = (0, core_1.createPrompt)((config, done) => {
10
+ const { choices } = config;
11
+ const [status, setStatus] = (0, core_1.useState)('pending');
12
+ const [value, setValue] = (0, core_1.useState)('');
13
+ const [errorMsg, setError] = (0, core_1.useState)(undefined);
14
+ const prefix = (0, core_1.usePrefix)();
15
+ (0, core_1.useKeypress)((key, rl) => {
16
+ if ((0, core_1.isEnterKey)(key)) {
17
+ let selectedChoice;
18
+ if (numberRegex.test(value)) {
19
+ const answer = parseInt(value, 10) - 1;
20
+ selectedChoice = choices[answer];
21
+ }
22
+ else {
23
+ const answer = value.toLowerCase();
24
+ selectedChoice = choices.find(({ key }) => key === answer);
25
+ }
26
+ if (selectedChoice) {
27
+ const finalValue = selectedChoice.value || selectedChoice.name;
28
+ setValue(finalValue);
29
+ setStatus('done');
30
+ done(finalValue);
31
+ }
32
+ else if (value === '') {
33
+ setError('Please input a value');
34
+ }
35
+ else {
36
+ setError(`"${chalk_1.default.red(value)}" isn't an available option`);
37
+ }
38
+ }
39
+ else {
40
+ setValue(rl.line);
41
+ setError(undefined);
42
+ }
43
+ });
44
+ const message = chalk_1.default.bold(config.message);
45
+ if (status === 'done') {
46
+ return `${prefix} ${message} ${chalk_1.default.cyan(value)}`;
47
+ }
48
+ const choicesStr = choices
49
+ .map((choice, index) => {
50
+ const humanIndex = index + 1;
51
+ const line = ` ${choice.key || humanIndex}) ${choice.name || choice.value}`;
52
+ if (choice.key === value.toLowerCase() || String(humanIndex) === value) {
53
+ return chalk_1.default.cyan(line);
54
+ }
55
+ return line;
56
+ })
57
+ .join('\n');
58
+ let error = '';
59
+ if (errorMsg) {
60
+ error = chalk_1.default.red(`> ${errorMsg}`);
61
+ }
62
+ return [
63
+ `${prefix} ${message} ${value}`,
64
+ [choicesStr, error].filter(Boolean).join('\n'),
65
+ ];
66
+ });
@@ -1,10 +1,10 @@
1
1
  import { AsyncPromptConfig } from '@inquirer/core';
2
- declare type RawlistConfig = AsyncPromptConfig & {
2
+ type RawlistConfig = AsyncPromptConfig & {
3
3
  choices: {
4
4
  value: string;
5
5
  name?: string;
6
6
  key?: string;
7
7
  }[];
8
8
  };
9
- declare const _default: import("@inquirer/core").Prompt<string, RawlistConfig>;
9
+ declare const _default: import("@inquirer/type").Prompt<string, RawlistConfig>;
10
10
  export default _default;
@@ -0,0 +1,10 @@
1
+ import { AsyncPromptConfig } from '@inquirer/core';
2
+ type RawlistConfig = AsyncPromptConfig & {
3
+ choices: {
4
+ value: string;
5
+ name?: string;
6
+ key?: string;
7
+ }[];
8
+ };
9
+ declare const _default: import("@inquirer/type").Prompt<string, RawlistConfig>;
10
+ export default _default;
package/package.json CHANGED
@@ -1,21 +1,22 @@
1
1
  {
2
2
  "name": "@inquirer/rawlist",
3
- "type": "module",
4
- "version": "0.0.10-alpha.0",
3
+ "version": "0.1.0",
5
4
  "description": "Inquirer rawlist prompt",
6
- "main": "dist/index.js",
7
- "typings": "dist/index.d.ts",
5
+ "main": "./dist/cjs/index.js",
6
+ "typings": "./dist/cjs/types/index.d.mts",
8
7
  "files": [
9
- "dist/"
8
+ "dist/**/*"
10
9
  ],
11
- "repository": "SBoudrias/Inquirer.js",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/SBoudrias/Inquirer.js.git"
13
+ },
12
14
  "keywords": [
13
15
  "answer",
14
16
  "answers",
15
17
  "ask",
16
18
  "base",
17
19
  "cli",
18
- "cli",
19
20
  "command",
20
21
  "command-line",
21
22
  "confirm",
@@ -53,14 +54,34 @@
53
54
  "license": "MIT",
54
55
  "homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/rawlist/README.md",
55
56
  "dependencies": {
56
- "@inquirer/core": "^0.0.26-alpha.0",
57
- "chalk": "^5.0.1"
57
+ "@inquirer/core": "^1.0.0",
58
+ "@inquirer/type": "^0.1.0",
59
+ "chalk": "^5.2.0"
58
60
  },
59
61
  "scripts": {
60
- "tsc": "tsc"
62
+ "tsc": "yarn run clean && yarn run tsc:esm && yarn run tsc:cjs",
63
+ "clean": "rm -rf dist",
64
+ "tsc:esm": "tsc -p ./tsconfig.esm.json",
65
+ "tsc:cjs": "tsc -p ./tsconfig.cjs.json && yarn run fix-ext",
66
+ "fix-ext": "ts-node ../../tools/rename-ext.ts"
61
67
  },
62
68
  "publishConfig": {
63
69
  "access": "public"
64
70
  },
65
- "gitHead": "0e3ef8e31fc34b5fa5308be95af77ba9f5ede8fa"
71
+ "engines": {
72
+ "node": ">=14.18.0"
73
+ },
74
+ "exports": {
75
+ ".": {
76
+ "import": {
77
+ "types": "./dist/esm/types/index.d.mts",
78
+ "default": "./dist/esm/index.mjs"
79
+ },
80
+ "require": {
81
+ "types": "./dist/cjs/types/index.d.mts",
82
+ "default": "./dist/cjs/index.js"
83
+ }
84
+ }
85
+ },
86
+ "gitHead": "bd58130dd8204945a31b062070b829003b8385fc"
66
87
  }
File without changes