From e952a7b08968144fa0adcc7f001d536f9f3de67b Mon Sep 17 00:00:00 2001 From: anseki Date: Mon, 20 Apr 2015 16:43:12 +0900 Subject: [PATCH] `trueValue`, `falseValue` of `keyIn` accept function --- lib/readline-sync.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/readline-sync.js b/lib/readline-sync.js index b6f6e9c..36a71bc 100644 --- a/lib/readline-sync.js +++ b/lib/readline-sync.js @@ -811,16 +811,13 @@ exports.keyIn = function(query, options) { readOptions.limit = readOptions.limitSrc.join('').replace(/[^A-Za-z0-9_ ]/g, '\\$&'); ['trueValue', 'falseValue'].forEach(function(optionName) { - var comps = []; - readOptions[optionName].forEach(function(comp) { + readOptions[optionName] = readOptions[optionName].reduce(function(comps, comp) { var type = typeof comp; if (type === 'string' || type === 'number') { comps = comps.concat((comp + '').split('')); - } else if (comp instanceof RegExp) { - comps.push(comp); - } - }); - readOptions[optionName] = comps; + } else { comps.push(comp); } + return comps; + }, []); }); readOptions.display = replacePlaceholder(readOptions.display + '',