From 55b42749d662f8e19d54a831e93876844f6e5b45 Mon Sep 17 00:00:00 2001 From: anseki Date: Fri, 24 Apr 2015 15:00:59 +0900 Subject: [PATCH] Fix: return value of `validate` is not type checked. --- README.md | 15 +++++++-------- lib/readline-sync.js | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d434de4..852cf6e 100644 --- a/README.md +++ b/README.md @@ -350,14 +350,7 @@ If the user input empty text (i.e. pressed an Enter key only), return this. For example: ```js -answer = readlineSync.question('Do you want to install this? :', - {defaultInput: 'y'}); -if (answer === 'y') { - // install -} else { - process.exit(); -} -// ** But `keyInYN` method should be used instead of this. ** +lang = readlineSync.question('Which language? :', {defaultInput: 'javascript'}); ``` ### `trueValue`, `falseValue` @@ -677,6 +670,12 @@ And the following additional options are available. A string as the characters that can be included in the password. For example, if `'abc123'` is specified, the passwords that include any character other than these 6 characters are refused. The [placeholders](#placeholders) like `'${a-e}'` are replaced to the characters like `'abcde'`. +For example, let the user input a password that is created with alphabet and some symbols: + +```js +password = readlineSync.questionNewPassword('PASSWORD :', {charlist: '${a-z}#$@%'}); +``` + ##### `min`, `max` *Type:* number diff --git a/lib/readline-sync.js b/lib/readline-sync.js index 3415079..4e1de64 100644 --- a/lib/readline-sync.js +++ b/lib/readline-sync.js @@ -995,7 +995,7 @@ exports.questionPath = function(query, options) { } if (typeof options.validate === 'function' && (res = options.validate(validPath)) !== true) { - error = res + ''; + if (typeof res === 'string') { error = res; } return; } } catch (e) {