push
github
312 of 350 branches covered (89.14%)
Branch coverage included in aggregate %.
10 of 33 new or added lines in 4 files covered. (30.3%)
1486 of 1622 relevant lines covered (91.62%)
757.19 hits per line
|
import { styleText } from 'node:util' |
|
|
import readline from 'node:readline/promises' |
25✔ |
|
|
25✔ |
|
const input = async ({ message, value, validate }) => { |
25✔ |
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() |
× |
NEW
|
|
× |
NEW
|
return answer
|
× |
NEW
|
})() : render(valid) |
× |
NEW
|
} |
× |
NEW
|
|
× |
NEW
|
return render()
|
× |
NEW
|
} |
× |
|
|
25✔ |
|
export { input }
|
25✔ |