47e764132f
WIP lib graphique
41 lines
755 B
JavaScript
41 lines
755 B
JavaScript
//@ts-check
|
|
|
|
/**
|
|
* @param {string} str
|
|
* @returns { Promise<string> }
|
|
*/
|
|
async function getline(str) {
|
|
process.stdout.write(str)
|
|
process.stdin.resume()
|
|
process.stdin.setEncoding('utf8')
|
|
let line = ""
|
|
return new Promise((res, rej) => {
|
|
process.stdin.on('data', function(chunk) {
|
|
|
|
line += chunk
|
|
if (chunk.toString('utf-8').endsWith('\n')) {
|
|
process.stdin.pause()
|
|
res(line.substring(0, line.length -1))
|
|
}
|
|
})
|
|
process.stdin.on('error', function(err) {
|
|
rej(err)
|
|
})
|
|
})
|
|
}
|
|
|
|
/**
|
|
* @param { string } str
|
|
* @returns
|
|
*/
|
|
function isAlpha(str){
|
|
return /^[a-zA-Z]*$/.test(str)
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
isAlpha, getline
|
|
|
|
} |