@augment-vir/node-js
Advanced tools
Comparing version 15.6.1 to 16.0.0
@@ -34,4 +34,8 @@ /// <reference types="node" /> | ||
export declare const logIf: Record<keyof Logger, (condition: boolean, ...args: ReadonlyArray<any>) => void>; | ||
export declare function askQuestion(questionToAsk: string, timeoutMs?: number): Promise<string>; | ||
export declare function askQuestionUntilConditionMet({ questionToAsk, conditionCallback, invalidInputMessage, tryCountMax, timeoutMs, }: { | ||
export type AskQuestionOptions = { | ||
timeoutMs: number; | ||
hideUserInput: boolean; | ||
}; | ||
export declare function askQuestion(questionToAsk: string, { hideUserInput, timeoutMs, }?: Partial<AskQuestionOptions>): Promise<string>; | ||
export declare function askQuestionUntilConditionMet({ questionToAsk, conditionCallback, invalidInputMessage, tryCountMax, ...options }: { | ||
questionToAsk: string; | ||
@@ -41,5 +45,3 @@ conditionCallback: (response: string) => boolean | Promise<boolean>; | ||
tryCountMax?: number; | ||
/** Set to 0 to disable the timeout */ | ||
timeoutMs?: number; | ||
}): Promise<string>; | ||
} & Partial<AskQuestionOptions>): Promise<string>; | ||
export {}; |
@@ -117,3 +117,7 @@ "use strict"; | ||
}); | ||
async function askQuestion(questionToAsk, timeoutMs = 60000) { | ||
const defaultAskQuestionOptions = { | ||
timeoutMs: 60000, | ||
hideUserInput: false, | ||
}; | ||
async function askQuestion(questionToAsk, { hideUserInput = defaultAskQuestionOptions.hideUserInput, timeoutMs = defaultAskQuestionOptions.timeoutMs, } = defaultAskQuestionOptions) { | ||
const cliInterface = (0, readline_1.createInterface)({ | ||
@@ -123,2 +127,12 @@ input: process.stdin, | ||
}); | ||
if (hideUserInput) { | ||
let promptWritten = false; | ||
/** _writeToOutput is not in the types OR in the Node.js documentation but is a thing. */ | ||
cliInterface._writeToOutput = (prompt) => { | ||
if (!promptWritten) { | ||
cliInterface.output.write(prompt); | ||
promptWritten = true; | ||
} | ||
}; | ||
} | ||
// handle killing the process | ||
@@ -137,3 +151,4 @@ cliInterface.on('SIGINT', () => { | ||
: undefined; | ||
cliInterface.question(questionToAsk + ' ', (response) => { | ||
process.stdout.write(questionToAsk + '\n'); | ||
cliInterface.question('', (response) => { | ||
if (timeoutId != undefined) { | ||
@@ -148,3 +163,3 @@ clearTimeout(timeoutId); | ||
exports.askQuestion = askQuestion; | ||
async function askQuestionUntilConditionMet({ questionToAsk, conditionCallback, invalidInputMessage, tryCountMax = 5, timeoutMs = 60000, }) { | ||
async function askQuestionUntilConditionMet({ questionToAsk, conditionCallback, invalidInputMessage, tryCountMax = 5, ...options }) { | ||
let wasConditionMet = false; | ||
@@ -154,3 +169,3 @@ let retryCount = 0; | ||
while (!wasConditionMet && retryCount <= tryCountMax) { | ||
response = (await askQuestion(questionToAsk, timeoutMs)).trim(); | ||
response = (await askQuestion(questionToAsk, options)).trim(); | ||
wasConditionMet = await conditionCallback(response); | ||
@@ -157,0 +172,0 @@ if (!wasConditionMet) { |
{ | ||
"name": "@augment-vir/node-js", | ||
"version": "15.6.1", | ||
"version": "16.0.0", | ||
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/node-js", | ||
@@ -25,3 +25,3 @@ "bugs": { | ||
"dependencies": { | ||
"@augment-vir/common": "^15.6.1", | ||
"@augment-vir/common": "^16.0.0", | ||
"ansi-colors": "^4.1.3", | ||
@@ -34,3 +34,3 @@ "axios": "^1.4.0", | ||
"devDependencies": { | ||
"@augment-vir/chai": "^15.6.1", | ||
"@augment-vir/chai": "^16.0.0", | ||
"@electrovir/nyc": "^15.1.0-fix0", | ||
@@ -41,3 +41,3 @@ "@istanbuljs/nyc-config-typescript": "^1.0.2", | ||
"@types/mocha": "^10.0.1", | ||
"@types/node": "^20.4.2", | ||
"@types/node": "^20.4.5", | ||
"chai": "^4.3.7", | ||
@@ -44,0 +44,0 @@ "istanbul-smart-text-reporter": "^1.1.2", |
37920
865
+ Added@augment-vir/common@16.4.2(transitive)
- Removed@augment-vir/common@15.6.1(transitive)
Updated@augment-vir/common@^16.0.0