awt-prompt 1.0.4
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/LICENSE +21 -0
- package/README.md +112 -0
- package/package.json +27 -0
- package/prompt.js +15 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mourão
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Awt-Prompt
|
|
2
|
+
|
|
3
|
+
**Simple async prompt for Node.js using modern ES modules**
|
|
4
|
+
|
|
5
|
+
Node.js does not provide a built in `prompt()` like browsers.
|
|
6
|
+
This tiny package gives you a clean, promise based solution that works perfectly with `async/await`.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Install directly from GitHub:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install github:MouraoDev22/awt-prompt
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Or from npm
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install awt-prompt
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Requirements
|
|
27
|
+
|
|
28
|
+
Node.js **18+ recommended**
|
|
29
|
+
|
|
30
|
+
Your project must use ES modules. Add this to your `package.json`:
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"type": "module"
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
import prompt from 'awt-prompt';
|
|
44
|
+
|
|
45
|
+
const name = await prompt('What is your name?');
|
|
46
|
+
console.log(`Hello ${name}`);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The function always returns a **string**.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Working With Numbers
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
import prompt from 'awt-prompt';
|
|
57
|
+
|
|
58
|
+
const age = Number(await prompt('Your age:'));
|
|
59
|
+
console.log(age);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Example With Validation
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
import prompt from 'awt-prompt';
|
|
68
|
+
|
|
69
|
+
async function getPositiveNumber() {
|
|
70
|
+
let value = Number(await prompt('Enter a number:'));
|
|
71
|
+
|
|
72
|
+
while (isNaN(value) || value <= 0) {
|
|
73
|
+
value = Number(await prompt('Invalid input. Enter a valid number:'));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const number = await getPositiveNumber();
|
|
80
|
+
console.log(number);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Why This Exists
|
|
86
|
+
|
|
87
|
+
Browsers have `prompt()`.
|
|
88
|
+
Node.js does not.
|
|
89
|
+
|
|
90
|
+
This package provides a minimal, modern and promise based alternative using `readline`.
|
|
91
|
+
|
|
92
|
+
No setup. No boilerplate. Just ask and get input.
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## API
|
|
97
|
+
|
|
98
|
+
### `prompt(question)`
|
|
99
|
+
|
|
100
|
+
| Parameter | Type | Description |
|
|
101
|
+
| --------- | ------ | -------------------------- |
|
|
102
|
+
| question | string | Text shown in the terminal |
|
|
103
|
+
|
|
104
|
+
**Returns:** `Promise<string>`
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
MIT License
|
|
111
|
+
|
|
112
|
+
---
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "awt-prompt",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./prompt.js",
|
|
6
|
+
"exports": "./prompt.js",
|
|
7
|
+
"description": "Simple prompt method for Node.js",
|
|
8
|
+
"author": "Mourão",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"files": [
|
|
11
|
+
"prompt.js"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"prompt",
|
|
15
|
+
"cli",
|
|
16
|
+
"input",
|
|
17
|
+
"terminal",
|
|
18
|
+
"node"
|
|
19
|
+
],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/MouraoDev22/awt-prompt.git"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/prompt.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import readline from 'readline';
|
|
2
|
+
|
|
3
|
+
export default function prompt(question) {
|
|
4
|
+
const rl = readline.createInterface({
|
|
5
|
+
input: process.stdin,
|
|
6
|
+
output: process.stdout
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
rl.question(question + ' ', (answer) => {
|
|
11
|
+
rl.close();
|
|
12
|
+
resolve(answer);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
};
|