Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/timmarinin/y-or-n
Get y/n from user on terminal in callback. That's it.
https://github.com/timmarinin/y-or-n
Last synced: 1 day ago
JSON representation
Get y/n from user on terminal in callback. That's it.
- Host: GitHub
- URL: https://github.com/timmarinin/y-or-n
- Owner: timmarinin
- Created: 2016-07-18T20:02:18.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-07-21T16:36:18.000Z (over 8 years ago)
- Last Synced: 2024-11-09T09:48:56.931Z (6 days ago)
- Language: JavaScript
- Homepage: https://npmjs.com/package/y-or-n
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
y-or-n
======Get y/n from user on terminal in callback. That's it.
## Usage
Install it from npm via `npm i y-or-n`. After that, you're ready to go:
```
const yorn = require('y-or-n')yorn('Is it dark?', function(err, answer) {
// answer is Boolean, true || false.
})
```## Options
y-or-n supports few options that you can pass as a second argument. Default values:
```
const yorn = require('y-or-n')yorn('Are you OK? y/n', {
timeout: 0, // ms, 0 means no timeout
defaultAnswer: false, // read section below
input: process.stdin, // Readable stream
output: process.stdout, // Writable stream
strictNn: false // accept only n or N as false answer
}, function getAnswer (err, answer) {
if (err) {
// if user didn't enter anything before timeout
// then err.code is ETIMEOUT
assert(err.code === 'ETIMEOUT')
// and we probably should react somehow anyway, answer
// is defaultAnswer from options object
}
})### opts.defaultAnswer
Value that is used in few cases, namely when timeout is set and expired, when strictNn is set and input is not any of [yYnN].
```
## License
MIT. © 2016, Marinin Tim