just-prompt 1.0.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/README.md +18 -0
  2. package/just-prompt.js +52 -0
  3. package/package.json +40 -0
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # just-prompt
2
+
3
+ Very simple, chainable readline-based prompt helper for Node.js command-line tools.
4
+
5
+ ```js
6
+ import prompt from 'just-prompt';
7
+
8
+ const p = prompt.app(
9
+ 'You > ',
10
+ 'exit',
11
+ async (input) => {
12
+ console.log('→', input.toUpperCase());
13
+ }
14
+ );
15
+
16
+ p.onExit(() => console.log('\nšŸ‘‹ Goodbye!'))
17
+ .start();
18
+
package/just-prompt.js ADDED
@@ -0,0 +1,52 @@
1
+ // just-prompt.js
2
+ import readline from 'node:readline';
3
+
4
+ class JustPrompt {
5
+ constructor(message, exitCommand, work) {
6
+ this.exitCommand = exitCommand;
7
+ this.message = message;
8
+ this.work = work;
9
+ this.rl = readline.createInterface({
10
+ input: process.stdin,
11
+ output: process.stdout
12
+ });
13
+ }
14
+
15
+ onExit(onexit) {
16
+ this.onexit = onexit;
17
+ return this;
18
+ }
19
+
20
+ start() {
21
+ return new Promise((resolve) => {
22
+ const ask = () => {
23
+ this.rl.question(this.message, async (input) => {
24
+ if (input.trim().toLowerCase() === this.exitCommand.toLowerCase()) {
25
+ this.rl.close();
26
+ if (this.onexit) this.onexit();
27
+ resolve(input);
28
+ } else {
29
+ await this.work(input);
30
+ ask();
31
+ }
32
+ });
33
+ };
34
+ ask();
35
+ });
36
+ }
37
+
38
+ stop() {
39
+ this.rl.close();
40
+ return this;
41
+ }
42
+ }
43
+
44
+ // ────────────────────────────────────────────────
45
+ // Create the main exported object
46
+ // ────────────────────────────────────────────────
47
+ const prompt = {
48
+ app: (message, exitCommand, work) => new JustPrompt(message, exitCommand, work),
49
+ argv: () => process.argv.slice(2),
50
+ };
51
+
52
+ export default prompt;
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "just-prompt",
3
+ "version": "1.0.0",
4
+ "description": "Simple, chainable readline-based prompt utility for Node.js CLI apps",
5
+ "main": "just-prompt.js",
6
+ "type": "module",
7
+ "exports": {
8
+ "default": "./just-prompt.js"
9
+ },
10
+ "scripts": {
11
+ "test": "echo \"Error: no test specified\" && exit 1"
12
+ },
13
+ "keywords": [
14
+ "just-prompt",
15
+ "prompt",
16
+ "readline",
17
+ "cli",
18
+ "command-line",
19
+ "interactive",
20
+ "node",
21
+ "terminal"
22
+ ],
23
+ "author": "littlejustnode",
24
+ "license": "MIT",
25
+ "engines": {
26
+ "node": ">=18.0.0"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/littlejustnode/just-prompt.git"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/littlejustnode/just-prompt/issues"
34
+ },
35
+ "homepage": "https://github.com/littlejustnode/just-prompt#readme",
36
+ "files": [
37
+ "just-prompt.js",
38
+ "README.md"
39
+ ]
40
+ }