diff --git a/lib/readline-sync.js b/lib/readline-sync.js index f5449e4..af0884e 100644 --- a/lib/readline-sync.js +++ b/lib/readline-sync.js @@ -27,8 +27,8 @@ var caseSensitive: false, noTrim: false, encoding: 'utf8', - bufSize: 1024, - print: null + bufferSize: 1024, + print: void 0 }, useExt = false, @@ -43,7 +43,7 @@ var limit: string (pattern) caseSensitive: boolean noTrim: boolean - encoding, bufSize, print + encoding, bufferSize, print */ function _readlineSync(options) { var input = '', displaySave = (options.display += ''), @@ -147,7 +147,7 @@ function _readlineSync(options) { input = tryExt(); return; } - buffer = new Buffer((reqSize = options.keyIn ? 1 : options.bufSize)); + buffer = new Buffer((reqSize = options.keyIn ? 1 : options.bufferSize)); if (options.keyIn && options.limit) { limit = new RegExp('[^' + options.limit + ']', @@ -421,7 +421,7 @@ function margeOptions() { /* jshint eqnull:false */ break; // number - case 'bufSize': // * * + case 'bufferSize': // * * if (!isNaN(value = parseInt(value, 10)) && typeof value === 'number') { options[optionName] = value; } break; @@ -434,7 +434,7 @@ function margeOptions() { break; // function case 'print': // * * - options[optionName] = typeof value === 'function' ? value : null; + options[optionName] = typeof value === 'function' ? value : void 0; break; // other case 'prompt': // * @@ -497,9 +497,14 @@ exports.setDefault = function(options) { return margeOptions(true); // copy }; -// These APIs are now obsolete. -exports.setPrint = function(value) { return exports.setDefault({print: value}).print; }; -exports.setPrompt = function(value) { return exports.setDefault({prompt: value}).prompt; }; -exports.setEncoding = function(value) { return exports.setDefault({encoding: value}).encoding; }; -exports.setMask = function(value) { return exports.setDefault({mask: value}).mask; }; -exports.setBufferSize = function(value) { return exports.setDefault({bufSize: value}).bufSize; }; +// ======== These APIs are now obsolete. ======== +function setOption(optionName, args) { + var options; + if (args.length) { options = {}; options[optionName] = args[0]; } + return exports.setDefault(options)[optionName]; +} +exports.setPrint = function() { return setOption('print', arguments); }; +exports.setPrompt = function() { return setOption('prompt', arguments); }; +exports.setEncoding = function() { return setOption('encoding', arguments); }; +exports.setMask = function() { return setOption('mask', arguments); }; +exports.setBufferSize = function() { return setOption('bufferSize', arguments); };