Skip to content

Instantly share code, notes, and snippets.

@lunelson
Created December 1, 2019 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lunelson/b96bfeebcf154f4f7356f427f331ce1a to your computer and use it in GitHub Desktop.
Save lunelson/b96bfeebcf154f4f7356f427f331ce1a to your computer and use it in GitHub Desktop.
Usage of npm package "yn"
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