-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.js
More file actions
28 lines (26 loc) · 766 Bytes
/
input.js
File metadata and controls
28 lines (26 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import {createInterface } from 'readline/promises';
export const readNumberInput = async (message) => {
const text = message ? message : 'Enter Input: ';
const r1 = createInterface({
input: process.stdin,
output: process.stdout,
})
try{
const input = await r1.question(text);
r1.close()
const number = Number(input);
return Number(input);
} catch(error){
return new Error('Input is not a Number!');
}
}
export const readString = async (message) => {
const text = message ? message : 'Enter Input: ';
const r1 = createInterface({
input: process.stdin,
output: process.stdout,
})
const input = await r1.question(text);
r1.close()
return input;
}