Page MenuHomeSealhub

question.ts
No OneTemporary

question.ts

import { createInterface } from "readline";
export async function question(
text: string,
validator: (answer: string) => boolean
) {
const rl = createInterface({
input: process.stdin,
output: process.stdout,
});
let answer = "";
while (answer == "" || !validator(answer)) {
// eslint-disable-next-line no-await-in-loop
answer = await new Promise((resolve) => rl.question(text, resolve));
if (!validator(answer)) {
// eslint-disable-next-line no-console
console.log("Try again");
}
}
rl.close();
return answer;
}

File Metadata

Mime Type
text/x-java
Expires
Wed, May 7, 19:48 (20 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
625125
Default Alt Text
question.ts (541 B)

Event Timeline