pax_global_header00006660000000000000000000000064121706524420014515gustar00rootroot0000000000000052 comment=c9a100d89e5f296312c5b001ff0c43e9fd1c43bc read-1.0.5/000077500000000000000000000000001217065244200124335ustar00rootroot00000000000000read-1.0.5/.gitignore000066400000000000000000000000331217065244200144170ustar00rootroot00000000000000npm-debug.log node_modules read-1.0.5/LICENCE000066400000000000000000000024461217065244200134260ustar00rootroot00000000000000Copyright (c) Isaac Z. Schlueter All rights reserved. The BSD License Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. read-1.0.5/README.md000066400000000000000000000032711217065244200137150ustar00rootroot00000000000000## read For reading user input from stdin. Similar to the `readline` builtin's `question()` method, but with a few more features. ## USAGE ```javascript var read = require("read") read(options, callback) ``` The callback gets called with either the user input, or the default specified, or an error, as `callback(error, result, isDefault)` node style. ## OPTIONS Every option is optional. * `prompt` What to write to stdout before reading input. * `silent` Don't echo the output as the user types it. * `replace` Replace silenced characters with the supplied character value. * `timeout` Number of ms to wait for user input before giving up. * `default` The default value if the user enters nothing. * `edit` Allow the user to edit the default value. * `terminal` Treat the output as a TTY, whether it is or not. * `input` Readable stream to get input data from. (default `process.stdin`) * `output` Writeable stream to write prompts to. (default: `process.stdout`) If silent is true, and the input is a TTY, then read will set raw mode, and read character by character. ## COMPATIBILITY This module works sort of with node 0.6. It does not work with node versions less than 0.6. It is best on node 0.8. On node version 0.6, it will remove all listeners on the input stream's `data` and `keypress` events, because the readline module did not fully clean up after itself in that version of node, and did not make it possible to clean up after it in a way that has no potential for side effects. Additionally, some of the readline options (like `terminal`) will not function in versions of node before 0.8, because they were not implemented in the builtin readline module. ## CONTRIBUTING Patches welcome. read-1.0.5/example/000077500000000000000000000000001217065244200140665ustar00rootroot00000000000000read-1.0.5/example/example.js000066400000000000000000000010101217065244200160470ustar00rootroot00000000000000var read = require("../lib/read.js") read({prompt: "Username: ", default: "test-user" }, function (er, user) { read({prompt: "Password: ", default: "test-pass", silent: true }, function (er, pass) { read({prompt: "Password again: ", default: "test-pass", silent: true }, function (er, pass2) { console.error({user: user, pass: pass, verify: pass2, passMatch: (pass === pass2)}) console.error("the program should exit now") }) }) }) read-1.0.5/lib/000077500000000000000000000000001217065244200132015ustar00rootroot00000000000000read-1.0.5/lib/read.js000066400000000000000000000045771217065244200144670ustar00rootroot00000000000000 module.exports = read var readline = require('readline') var Mute = require('mute-stream') function read (opts, cb) { if (opts.num) { throw new Error('read() no longer accepts a char number limit') } if (typeof opts.default !== 'undefined' && typeof opts.default !== 'string' && typeof opts.default !== 'number') { throw new Error('default value must be string or number') } var input = opts.input || process.stdin var output = opts.output || process.stdout var prompt = (opts.prompt || '').trim() + ' ' var silent = opts.silent var editDef = false var timeout = opts.timeout var def = opts.default || '' if (def) { if (silent) { prompt += '(