github
274 of 319 branches covered (85.89%)
Branch coverage included in aggregate %.
120 of 158 new or added lines in 9 files covered. (75.95%)
1 existing line in 1 file now uncovered.1298 of 1438 relevant lines covered (90.26%)
352.81 hits per line
1 |
import { styleText } from 'node:util' |
|
2 |
import readline from 'node:readline/promises' |
17✔ |
|
|
17✔ |
|
const input = async ({ message, value, validate }) => { |
17✔ |
NEW
|
const rl = readline.createInterface({ |
× |
NEW
|
input: process.stdin,
|
× |
NEW
|
output: process.stdout
|
× |
NEW
|
}) |
× |
NEW
|
|
× |
NEW
|
const render = async err => { |
× |
NEW
|
if (err) console.log(styleText(['red'], err)) |
× |
NEW
|
|
× |
NEW
|
const question = styleText(['cyan'],`${message}: (${value}) `) |
× |
NEW
|
const answer = await rl.question(question).then(v => v.trim()) || value |
× |
NEW
|
const valid = validate(answer) |
× |
NEW
|
|
× |
NEW
|
return valid === true ? (() => { |
× |
NEW
|
rl.close() |
× |
19 |
|
× |
NEW
|
return answer
|
× |
21 |
})() : render(valid) |
× |
NEW
|
} |
× |
NEW
|
|
× |
NEW
|
return render()
|
× |
NEW
|
} |
× |
|
|
17✔ |
|
export { input }
|
17✔ |