Created
December 1, 2019 12:12
-
-
Save lunelson/b96bfeebcf154f4f7356f427f331ce1a to your computer and use it in GitHub Desktop.
Usage of npm package "yn"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const yn = require('yn'); | |
function confirm(message, callback) { | |
process.stdin.setEncoding('utf8'); | |
process.stdin.resume(); | |
process.stdout.write(`Confirm: ${message} [Y]`); | |
process.stdin.once('data', function(data) { | |
var ok = yn(data) || data.trim() == ''; | |
try { callback(ok); } catch (e) { throw new Error(e); } | |
process.stdin.pause(); | |
}); | |
} | |
confirm('You are about to process 400 files. Proceed?', (ok) => { | |
console.log(`the response was ${ok}`); | |
if (!ok) process.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment