-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompt.js
More file actions
23 lines (21 loc) · 692 Bytes
/
Copy pathprompt.js
File metadata and controls
23 lines (21 loc) · 692 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import readline from 'readline/promises';
import { stdin as input, stdout as output } from 'process';
export async function confirm(message) {
const rl = readline.createInterface({ input, output });
try {
const answer = await rl.question(`${message} (y/N) `);
return /^y(es)?$/i.test(answer.trim());
} finally {
rl.close();
}
}
export async function ask(message, defaultValue = '') {
const rl = readline.createInterface({ input, output });
try {
const answer = await rl.question(`${message} `);
const trimmed = answer.trim();
return trimmed === '' ? defaultValue : trimmed;
} finally {
rl.close();
}
}