Fix #38, change the placement of colon in default query

A colon in `query` doesn't mean a starting point of user input now.
It is common style that makes a colon mean a separator.
This commit is contained in:
anseki 2016-06-13 19:41:45 +09:00
parent c719316327
commit e39454cd2b
3 changed files with 84 additions and 83 deletions

146
README.md
View file

@ -14,20 +14,20 @@ readlineSync tries to let your script have a conversation with the user via a co
var readlineSync = require('readline-sync'); var readlineSync = require('readline-sync');
// Wait for user's response. // Wait for user's response.
var userName = readlineSync.question('May I have your name? :'); var userName = readlineSync.question('May I have your name? ');
console.log('Hi ' + userName + '!'); console.log('Hi ' + userName + '!');
// Handle the secret text (e.g. password). // Handle the secret text (e.g. password).
var favFood = readlineSync.question('What is your favorite food? :', { var favFood = readlineSync.question('What is your favorite food? ', {
hideEchoBack: true // The typed text on screen is hidden by `*` (default). hideEchoBack: true // The typed text on screen is hidden by `*` (default).
}); });
console.log('Oh, ' + userName + ' loves ' + favFood + '!'); console.log('Oh, ' + userName + ' loves ' + favFood + '!');
``` ```
```console ```console
May I have your name? :CookieMonster May I have your name? CookieMonster
Hi CookieMonster! Hi CookieMonster!
What is your favorite food? :**** What is your favorite food? ****
Oh, CookieMonster loves tofu! Oh, CookieMonster loves tofu!
``` ```
@ -63,7 +63,7 @@ console.log('Ok, ' + animals[index] + ' goes to your room.');
[5] Hippo [5] Hippo
[0] CANCEL [0] CANCEL
Which animal? [1...5 / 0] :2 Which animal? [1...5 / 0]: 2
Ok, Elephant goes to your room. Ok, Elephant goes to your room.
``` ```
@ -176,7 +176,7 @@ It can include the [placeholders](#placeholders).
For example: For example:
```js ```js
program = readlineSync.question('Which program starts do you want? :', { program = readlineSync.question('Which program starts do you want? ', {
defaultInput: 'firefox' defaultInput: 'firefox'
}); });
``` ```
@ -213,7 +213,7 @@ The `query` is handled the same as that of the [`question`](#basic_methods-quest
For example: For example:
```js ```js
menuId = readlineSync.keyIn('Hit 1...5 key :', {limit: '$<1-5>'}); menuId = readlineSync.keyIn('Hit 1...5 key: ', {limit: '$<1-5>'});
``` ```
### <a name="basic_methods-setdefaultoptions"></a>`setDefaultOptions` ### <a name="basic_methods-setdefaultoptions"></a>`setDefaultOptions`
@ -236,13 +236,13 @@ For example:
```js ```js
readlineSync.setDefaultOptions({limit: ['green', 'yellow', 'red']}); readlineSync.setDefaultOptions({limit: ['green', 'yellow', 'red']});
a1 = readlineSync.question('Which color of signal? :'); // Input is limited to 3 things. a1 = readlineSync.question('Which color of signal? '); // Input is limited to 3 things.
a2 = readlineSync.question('Which color of signal? :'); // It's limited yet. a2 = readlineSync.question('Which color of signal? '); // It's limited yet.
a3 = readlineSync.question('What is your favorite color? :', {limit: null}); // It's unlimited temporarily. a3 = readlineSync.question('What is your favorite color? ', {limit: null}); // It's unlimited temporarily.
a4 = readlineSync.question('Which color of signal? :'); // It's limited again. a4 = readlineSync.question('Which color of signal? '); // It's limited again.
readlineSync.setDefaultOptions({limit: ['beef', 'chicken']}); readlineSync.setDefaultOptions({limit: ['beef', 'chicken']});
a5 = readlineSync.question('Beef or Chicken? :'); // Input is limited to new 2 things. a5 = readlineSync.question('Beef or Chicken? '); // Input is limited to new 2 things.
a6 = readlineSync.question('And you? :'); // It's limited to 2 things yet. a6 = readlineSync.question('And you? '); // It's limited to 2 things yet.
``` ```
The Object as `options` can have following properties. The Object as `options` can have following properties.
@ -291,12 +291,12 @@ If `true` is specified, hide the secret text (e.g. password) which is typed by u
For example: For example:
```js ```js
password = readlineSync.question('PASSWORD :', {hideEchoBack: true}); password = readlineSync.question('PASSWORD: ', {hideEchoBack: true});
console.log('Login ...'); console.log('Login ...');
``` ```
```console ```console
PASSWORD :******** PASSWORD: ********
Login ... Login ...
``` ```
@ -311,7 +311,7 @@ Set the mask characters that are shown instead of the secret text (e.g. password
For example: For example:
```js ```js
secret = readlineSync.question('Please whisper sweet words :', { secret = readlineSync.question('Please whisper sweet words: ', {
hideEchoBack: true, hideEchoBack: true,
mask: require('chalk').magenta('\u2665') mask: require('chalk').magenta('\u2665')
}); });
@ -346,12 +346,12 @@ command = readlineSync.prompt({limit: ['add', 'remove', /^clear( all)?$/]});
``` ```
```js ```js
file = readlineSync.question('Text File :', {limit: /\.txt$/i}); file = readlineSync.question('Text File: ', {limit: /\.txt$/i});
// ** But `questionPath` method should be used instead of this. ** // ** But `questionPath` method should be used instead of this. **
``` ```
```js ```js
ip = readlineSync.question('IP Address :', {limit: function(input) { ip = readlineSync.question('IP Address: ', {limit: function(input) {
return require('net').isIP(input); // Valid IP Address return require('net').isIP(input); // Valid IP Address
}}); }});
``` ```
@ -380,11 +380,11 @@ The [placeholders](#placeholders) like `'$<a-e>'` are replaced to an Array that
For example: For example:
```js ```js
direction = readlineSync.keyIn('Left or Right? :', {limit: 'lr'}); // 'l' or 'r' direction = readlineSync.keyIn('Left or Right? ', {limit: 'lr'}); // 'l' or 'r'
``` ```
```js ```js
dice = readlineSync.keyIn('Roll the dice, What will the result be? :', dice = readlineSync.keyIn('Roll the dice, What will the result be? ',
{limit: '$<1-6>'}); // range of '1' to '6' {limit: '$<1-6>'}); // range of '1' to '6'
``` ```
@ -400,7 +400,7 @@ The [placeholders](#placeholders) can be included.
For example: For example:
```js ```js
file = readlineSync.question('Name of Text File :', { file = readlineSync.question('Name of Text File: ', {
limit: /\.txt$/i, limit: /\.txt$/i,
limitMessage: 'Sorry, $<lastInput> is not text file.' limitMessage: 'Sorry, $<lastInput> is not text file.'
}); });
@ -417,7 +417,7 @@ If the user input empty text (i.e. pressed the Enter key only), return this.
For example: For example:
```js ```js
lang = readlineSync.question('Which language? :', {defaultInput: 'javascript'}); lang = readlineSync.question('Which language? ', {defaultInput: 'javascript'});
``` ```
### <a name="basic_options-truevalue_falsevalue"></a>`trueValue`, `falseValue` ### <a name="basic_options-truevalue_falsevalue"></a>`trueValue`, `falseValue`
@ -437,7 +437,7 @@ One of above or an Array that includes multiple things (or Array includes Array)
For example: For example:
```js ```js
answer = readlineSync.question('How do you like it? :', { answer = readlineSync.question('How do you like it? ', {
trueValue: ['yes', 'yeah', 'yep'], trueValue: ['yes', 'yeah', 'yep'],
falseValue: ['no', 'nah', 'nope'] falseValue: ['no', 'nah', 'nope']
}); });
@ -512,8 +512,8 @@ readlineSync.setDefaultOptions({
}); });
console.log(chalk.black.bold.bgYellow(' Your Account ')); console.log(chalk.black.bold.bgYellow(' Your Account '));
user = readlineSync.question(chalk.gray.underline(' USER NAME ') + ' :'); user = readlineSync.question(chalk.gray.underline(' USER NAME ') + ' : ');
pw = readlineSync.question(chalk.gray.underline(' PASSWORD ') + ' :', pw = readlineSync.question(chalk.gray.underline(' PASSWORD ') + ' : ',
{hideEchoBack: true}); {hideEchoBack: true});
// Authorization ... // Authorization ...
console.log(chalk.green('Welcome, ' + user + '!')); console.log(chalk.green('Welcome, ' + user + '!'));
@ -527,8 +527,8 @@ readlineSync.setDefaultOptions({
print: function(display, encoding) print: function(display, encoding)
{ process.stdout.write(display, encoding); } { process.stdout.write(display, encoding); }
}); });
var name = readlineSync.question('May I have your name? :'); var name = readlineSync.question('May I have your name? ');
var loc = readlineSync.question('Hi ' + name + '! Where do you live? :'); var loc = readlineSync.question('Hi ' + name + '! Where do you live? ');
``` ```
* Let somebody hear our conversation in real time. * Let somebody hear our conversation in real time.
@ -548,15 +548,15 @@ node conv.js >/tmp/fifo
``` ```
```console ```console
May I have your name? :Oz May I have your name? Oz
Hi Oz! Where do you live? :Emerald City Hi Oz! Where do you live? Emerald City
``` ```
And then, another terminal shows this synchronously: And then, another terminal shows this synchronously:
```console ```console
May I have your name? :Oz May I have your name? Oz
Hi Oz! Where do you live? :Emerald City Hi Oz! Where do you live? Emerald City
``` ```
### <a name="basic_options-history"></a>`history` ### <a name="basic_options-history"></a>`history`
@ -611,20 +611,20 @@ For example:
```js ```js
while (true) { while (true) {
file = readlineSync.questionPath('File :'); file = readlineSync.questionPath('File: ');
console.log('-- Specified file is ' + file); console.log('-- Specified file is ' + file);
} }
``` ```
```console ```console
File :cd foo-dir/bar-dir File: cd foo-dir/bar-dir
File :pwd File: pwd
/path/to/foo-dir/bar-dir /path/to/foo-dir/bar-dir
File :file-a.js File: file-a.js
-- Specified file is /path/to/foo-dir/bar-dir/file-a.js -- Specified file is /path/to/foo-dir/bar-dir/file-a.js
File :file-b.png File: file-b.png
-- Specified file is /path/to/foo-dir/bar-dir/file-b.png -- Specified file is /path/to/foo-dir/bar-dir/file-b.png
File :file-c.html File: file-c.html
-- Specified file is /path/to/foo-dir/bar-dir/file-c.html -- Specified file is /path/to/foo-dir/bar-dir/file-c.html
``` ```
@ -643,7 +643,7 @@ email = readlineSync.questionEMail([query[, options]])
Display a `query` to the user if it's specified, and then accept only a valid e-mail address, and then return it after the Enter key was pressed. Display a `query` to the user if it's specified, and then accept only a valid e-mail address, and then return it after the Enter key was pressed.
The `query` is handled the same as that of the [`question`](#basic_methods-question) method. The `query` is handled the same as that of the [`question`](#basic_methods-question) method.
The default value of `query` is `'Input e-mail address :'`. The default value of `query` is `'Input e-mail address: '`.
*Note:* The valid e-mail address requirement is a willful violation of [RFC5322](http://tools.ietf.org/html/rfc5322), this is defined in [HTML5](http://www.w3.org/TR/html5/forms.html). This works enough to prevent the user mistaking. If you want to change it, specify [`limit`](#basic_options-limit) option. *Note:* The valid e-mail address requirement is a willful violation of [RFC5322](http://tools.ietf.org/html/rfc5322), this is defined in [HTML5](http://www.w3.org/TR/html5/forms.html). This works enough to prevent the user mistaking. If you want to change it, specify [`limit`](#basic_options-limit) option.
@ -655,9 +655,9 @@ console.log('-- E-mail is ' + email);
``` ```
```console ```console
Input e-mail address :abc Input e-mail address: abc
Input valid e-mail address, please. Input valid e-mail address, please.
Input e-mail address :mail@example.com Input e-mail address: mail@example.com
-- E-mail is mail@example.com -- E-mail is mail@example.com
``` ```
@ -691,7 +691,7 @@ It's the password, or something that is the secret text like the password.
You can specify the valid password requirement to the options. You can specify the valid password requirement to the options.
The `query` is handled the same as that of the [`question`](#basic_methods-question) method. The `query` is handled the same as that of the [`question`](#basic_methods-question) method.
The default value of `query` is `'Input new password :'`. The default value of `query` is `'Input new password: '`.
*Note:* Only the form of password is checked. Check it more if you want. For example, [zxcvbn](https://github.com/dropbox/zxcvbn) is password strength estimation library. *Note:* Only the form of password is checked. Check it more if you want. For example, [zxcvbn](https://github.com/dropbox/zxcvbn) is password strength estimation library.
@ -703,13 +703,13 @@ console.log('-- Password is ' + password);
``` ```
```console ```console
Input new password :************ Input new password: ************
It can include: 0...9, A...Z, a...z, !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ It can include: 0...9, A...Z, a...z, !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
And the length must be: 12...24 And the length must be: 12...24
Input new password :************* Input new password: *************
Reinput a same one to confirm it :************* Reinput a same one to confirm it: *************
It differs from first one. Hit only the Enter key if you want to retry from first one. It differs from first one. Hit only the Enter key if you want to retry from first one.
Reinput a same one to confirm it :************* Reinput a same one to confirm it: *************
-- Password is _my_password_ -- Password is _my_password_
``` ```
@ -745,7 +745,7 @@ The [placeholders](#placeholders) like `'$<a-e>'` are replaced to the characters
For example, let the user input a password that is created with alphabet and some symbols: For example, let the user input a password that is created with alphabet and some symbols:
```js ```js
password = readlineSync.questionNewPassword('PASSWORD :', {charlist: '$<a-z>#$@%'}); password = readlineSync.questionNewPassword('PASSWORD: ', {charlist: '$<a-z>#$@%'});
``` ```
##### <a name="utility_methods-questionnewpassword-options-min_max"></a>`min`, `max` ##### <a name="utility_methods-questionnewpassword-options-min_max"></a>`min`, `max`
@ -759,7 +759,7 @@ password = readlineSync.questionNewPassword('PASSWORD :', {charlist: '$<a-z>#$@%
##### <a name="utility_methods-questionnewpassword-options-confirmmessage"></a>`confirmMessage` ##### <a name="utility_methods-questionnewpassword-options-confirmmessage"></a>`confirmMessage`
*Type:* string or others *Type:* string or others
*Default:* `'Reinput a same one to confirm it :'` *Default:* `'Reinput a same one to confirm it: '`
A message that lets the user input the same password again. A message that lets the user input the same password again.
It can include the [placeholders](#placeholders). It can include the [placeholders](#placeholders).
@ -850,17 +850,17 @@ You can specify the valid local file or directory path requirement to the option
It is recommended to use this method with the [`cd`](#basic_options-cd) option. (Default: `true`) It is recommended to use this method with the [`cd`](#basic_options-cd) option. (Default: `true`)
The `query` is handled the same as that of the [`question`](#basic_methods-question) method. The `query` is handled the same as that of the [`question`](#basic_methods-question) method.
The default value of `query` is `'Input path (you can "cd" and "pwd") :'`. The default value of `query` is `'Input path (you can "cd" and "pwd"): '`.
For example: For example:
```js ```js
sourceFile = readlineSync.questionPath('Read from :', { sourceFile = readlineSync.questionPath('Read from: ', {
isFile: true isFile: true
}); });
console.log('-- sourceFile: ' + sourceFile); console.log('-- sourceFile: ' + sourceFile);
saveDir = readlineSync.questionPath('Save to :', { saveDir = readlineSync.questionPath('Save to: ', {
isDirectory: true, isDirectory: true,
exists: null, exists: null,
create: true create: true
@ -869,15 +869,15 @@ console.log('-- saveDir: ' + saveDir);
``` ```
```console ```console
Read from :~/fileA Read from: ~/fileA
No such file or directory: /home/user/fileA No such file or directory: /home/user/fileA
Input valid path, please. Input valid path, please.
Read from :pwd Read from: pwd
/path/to/work /path/to/work
Read from :cd ~/project-1 Read from: cd ~/project-1
Read from :fileA Read from: fileA
-- sourceFile: /home/user/project-1/fileA -- sourceFile: /home/user/project-1/fileA
Save to :~/deploy/data Save to: ~/deploy/data
-- saveDir: /home/user/deploy/data -- saveDir: /home/user/deploy/data
``` ```
@ -940,7 +940,7 @@ This is also a return value from this method.
For example, accept only PNG file or tell it to the user: For example, accept only PNG file or tell it to the user:
```js ```js
imageFile = readlineSync.questionPath('Image File :', { imageFile = readlineSync.questionPath('Image File: ', {
validate: function(path) { return /\.png$/i.test(path) || 'It is not PNG'; } validate: function(path) { return /\.png$/i.test(path) || 'It is not PNG'; }
}); });
``` ```
@ -1248,7 +1248,7 @@ This method works like the `window.confirm` method of web browsers. A return val
* other: `''` * other: `''`
The `query` is handled the same as that of the [`question`](#basic_methods-question) method. The `query` is handled the same as that of the [`question`](#basic_methods-question) method.
The default value of `query` is `'Are you sure? :'`. The default value of `query` is `'Are you sure? '`.
The keys other than `Y` and `N` are also accepted (If you want to know a user's wish explicitly, use [`keyInYNStrict`](#utility_methods-keyinynstrict) method). Therefore, if you let the user make an important decision (e.g. files are removed), check whether the return value is not *falsy*. That is, a default is "No". The keys other than `Y` and `N` are also accepted (If you want to know a user's wish explicitly, use [`keyInYNStrict`](#utility_methods-keyinynstrict) method). Therefore, if you let the user make an important decision (e.g. files are removed), check whether the return value is not *falsy*. That is, a default is "No".
@ -1300,8 +1300,8 @@ readlineSync.keyInYN('Really? :'); // Colon already exists
``` ```
``` console ``` console
Do you like me? [y/n] :y Do you like me? [y/n]: y
Really? [y/n] :y Really? [y/n]: y
``` ```
### <a name="utility_methods-keyinynstrict"></a>`keyInYNStrict` ### <a name="utility_methods-keyinynstrict"></a>`keyInYNStrict`
@ -1317,7 +1317,7 @@ This method works like the `window.confirm` method of web browsers. A return val
* `N`: `false` * `N`: `false`
The `query` is handled the same as that of the [`question`](#basic_methods-question) method. The `query` is handled the same as that of the [`question`](#basic_methods-question) method.
The default value of `query` is `'Are you sure? :'`. The default value of `query` is `'Are you sure? '`.
A key other than `Y` and `N` is not accepted. That is, a return value has no default. Therefore, the user has to tell an own wish explicitly. If you want to know a user's wish easily, use [`keyInYN`](#utility_methods-keyinyn) method. A key other than `Y` and `N` is not accepted. That is, a return value has no default. Therefore, the user has to tell an own wish explicitly. If you want to know a user's wish easily, use [`keyInYN`](#utility_methods-keyinyn) method.
@ -1397,7 +1397,7 @@ index = readlineSync.keyInSelect(items[, query[, options]])
Display the list that was created with the `items` Array, and the `query` to the user if it's specified, and then return the number as an index of the `items` Array immediately it was chosen by pressing a key by the user, **without pressing the Enter key**. Note that the user has no chance to change the input. Display the list that was created with the `items` Array, and the `query` to the user if it's specified, and then return the number as an index of the `items` Array immediately it was chosen by pressing a key by the user, **without pressing the Enter key**. Note that the user has no chance to change the input.
The `query` is handled the same as that of the [`question`](#basic_methods-question) method. The `query` is handled the same as that of the [`question`](#basic_methods-question) method.
The default value of `query` is `'Choose one from list :'`. The default value of `query` is `'Choose one from list: '`.
The minimum length of `items` Array is 1 and maximum length is 35. These elements are displayed as item list. A key to let the user choose an item is assigned to each item automatically in sequence like "1, 2, 3 ... 9, A, B, C ...". A number as an index of the `items` Array that corresponds to a chosen item by the user is returned. The minimum length of `items` Array is 1 and maximum length is 35. These elements are displayed as item list. A key to let the user choose an item is assigned to each item automatically in sequence like "1, 2, 3 ... 9, A, B, C ...". A number as an index of the `items` Array that corresponds to a chosen item by the user is returned.
@ -1417,7 +1417,7 @@ console.log(frameworks[index] + ' is enabled.');
[5] locomotive [5] locomotive
[0] CANCEL [0] CANCEL
Which framework? [1...5 / 0] :2 Which framework? [1...5 / 0]: 2
hapi is enabled. hapi is enabled.
``` ```
@ -1484,7 +1484,7 @@ A first item in a current `items` Array.
For example: For example:
```js ```js
index = readlineSync.keyInSelect(items, 'Choose $<firstItem> or another :'); index = readlineSync.keyInSelect(items, 'Choose $<firstItem> or another: ');
``` ```
##### <a name="utility_methods-keyinselect-additional_placeholders-lastitem"></a>`lastItem` ##### <a name="utility_methods-keyinselect-additional_placeholders-lastitem"></a>`lastItem`
@ -1608,13 +1608,13 @@ For example:
```js ```js
input = readlineSync.question( input = readlineSync.question(
'Input something or the Enter key as "$<defaultInput>" :', 'Input something or the Enter key as "$<defaultInput>": ',
{defaultInput: 'hello'} {defaultInput: 'hello'}
); );
``` ```
```console ```console
Input something or the Enter key as "hello" : Input something or the Enter key as "hello":
``` ```
#### <a name="placeholders-parameters-limitcount_limitcountnotzero"></a>`limitCount`, `limitCountNotZero` #### <a name="placeholders-parameters-limitcount_limitcountnotzero"></a>`limitCount`, `limitCountNotZero`
@ -1626,13 +1626,13 @@ For example:
```js ```js
action = readlineSync.question( action = readlineSync.question(
'Choose action$<( from )limitCountNotZero( actions)> :', 'Choose action$<( from )limitCountNotZero( actions)>: ',
{limit: availableActions} {limit: availableActions}
); );
``` ```
```console ```console
Choose action from 5 actions : Choose action from 5 actions:
``` ```
#### <a name="placeholders-parameters-lastinput"></a>`lastInput` #### <a name="placeholders-parameters-lastinput"></a>`lastInput`
@ -1663,15 +1663,15 @@ For example:
```js ```js
while (true) { while (true) {
input = readlineSync.question('Something$<( or "!!" as ")history_m1(")> :'); input = readlineSync.question('Something$<( or "!!" as ")history_m1(")>: ');
console.log('-- You said "' + input + '"'); console.log('-- You said "' + input + '"');
} }
``` ```
```console ```console
Something :hello Something: hello
-- You said "hello" -- You said "hello"
Something or "!!" as "hello" :!! Something or "!!" as "hello": !!
hello hello
-- You said "hello" -- You said "hello"
``` ```
@ -1723,7 +1723,7 @@ A character list.
For example, let the user input a password that is created with alphabet: For example, let the user input a password that is created with alphabet:
```js ```js
password = readlineSync.questionNewPassword('PASSWORD :', {charlist: '$<a-z>'}); password = readlineSync.questionNewPassword('PASSWORD: ', {charlist: '$<a-z>'});
``` ```
See also [`limit` option for `keyIn*` method](#basic_options-limit-for_keyin_method). See also [`limit` option for `keyIn*` method](#basic_options-limit-for_keyin_method).
@ -1745,7 +1745,7 @@ Running "fileCopy" task
Files already exist: Files already exist:
file-a.png file-a.png
file-b.js file-b.js
Overwrite? [y/n] :y Overwrite? [y/n]: y
file-a.png copied. file-a.png copied.
file-b.js copied. file-b.js copied.
Done. Done.
@ -1783,7 +1783,7 @@ TTY interfaces are different by the platforms. If the platform doesn't support t
```js ```js
try { try {
answer = readlineSync.question('What is your favorite food? :'); answer = readlineSync.question('What is your favorite food? ');
} catch (e) { } catch (e) {
console.error(e); console.error(e);
process.exit(1); process.exit(1);

View file

@ -395,6 +395,7 @@ function _readlineSync(options) {
} }
// other ctrl-chars // other ctrl-chars
// eslint-disable-next-line no-control-regex
if (chunk) { chunk = chunk.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, ''); } if (chunk) { chunk = chunk.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, ''); }
if (chunk && limit) { chunk = chunk.replace(limit, ''); } if (chunk && limit) { chunk = chunk.replace(limit, ''); }
@ -444,7 +445,7 @@ function flattenArray(array, validator) {
} }
function escapePattern(pattern) { function escapePattern(pattern) {
return pattern.replace(/[\x00-\x7f]/g, return pattern.replace(/[\x00-\x7f]/g, // eslint-disable-line no-control-regex
function(s) { return '\\x' + ('00' + s.charCodeAt().toString(16)).substr(-2); }); function(s) { return '\\x' + ('00' + s.charCodeAt().toString(16)).substr(-2); });
} }
@ -876,7 +877,7 @@ exports.keyIn = function(query, options) {
// ------------------------------------ // ------------------------------------
exports.questionEMail = function(query, options) { exports.questionEMail = function(query, options) {
if (query == null) { query = 'Input e-mail address :'; } // eslint-disable-line eqeqeq if (query == null) { query = 'Input e-mail address: '; } // eslint-disable-line eqeqeq
/* eslint-disable key-spacing */ /* eslint-disable key-spacing */
return exports.question(query, margeOptions({ return exports.question(query, margeOptions({
// -------- default // -------- default
@ -932,12 +933,12 @@ exports.questionNewPassword = function(query, options) {
resCharlist.text = joinChunks(resCharlist.values, resCharlist.suppressed); resCharlist.text = joinChunks(resCharlist.values, resCharlist.suppressed);
confirmMessage = options.confirmMessage != null ? options.confirmMessage : // eslint-disable-line eqeqeq confirmMessage = options.confirmMessage != null ? options.confirmMessage : // eslint-disable-line eqeqeq
'Reinput a same one to confirm it :'; 'Reinput a same one to confirm it: ';
unmatchMessage = options.unmatchMessage != null ? options.unmatchMessage : // eslint-disable-line eqeqeq unmatchMessage = options.unmatchMessage != null ? options.unmatchMessage : // eslint-disable-line eqeqeq
'It differs from first one.' + 'It differs from first one.' +
' Hit only the Enter key if you want to retry from first one.'; ' Hit only the Enter key if you want to retry from first one.';
if (query == null) { query = 'Input new password :'; } // eslint-disable-line eqeqeq if (query == null) { query = 'Input new password: '; } // eslint-disable-line eqeqeq
limitMessage = readOptions.limitMessage; limitMessage = readOptions.limitMessage;
while (!res2) { while (!res2) {
@ -1066,7 +1067,7 @@ exports.questionPath = function(query, options) {
/* eslint-enable key-spacing */ /* eslint-enable key-spacing */
options = options || {}; options = options || {};
if (query == null) { query = 'Input path (you can "cd" and "pwd") :'; } // eslint-disable-line eqeqeq if (query == null) { query = 'Input path (you can "cd" and "pwd"): '; } // eslint-disable-line eqeqeq
exports.question(query, readOptions); exports.question(query, readOptions);
return validPath; return validPath;
@ -1191,9 +1192,9 @@ exports.promptSimShell = function(options) {
function _keyInYN(query, options, limit) { function _keyInYN(query, options, limit) {
var res; var res;
if (query == null) { query = 'Are you sure? :'; } // eslint-disable-line eqeqeq if (query == null) { query = 'Are you sure? '; } // eslint-disable-line eqeqeq
if ((!options || options.guide !== false) && (query += '')) { if ((!options || options.guide !== false) && (query += '')) {
query = query.replace(/\s*:?\s*$/, '') + ' [y/n] :'; query = query.replace(/\s*:?\s*$/, '') + ' [y/n]: ';
} }
/* eslint-disable key-spacing */ /* eslint-disable key-spacing */
res = exports.keyIn(query, margeOptions(options, { res = exports.keyIn(query, margeOptions(options, {
@ -1272,10 +1273,10 @@ exports.keyInSelect = function(items, query, options) {
readOptions.limit = keylist; readOptions.limit = keylist;
display += '\n'; display += '\n';
if (query == null) { query = 'Choose one from list :'; } // eslint-disable-line eqeqeq if (query == null) { query = 'Choose one from list: '; } // eslint-disable-line eqeqeq
if ((query += '')) { if ((query += '')) {
if (!options || options.guide !== false) { if (!options || options.guide !== false) {
query = query.replace(/\s*:?\s*$/, '') + ' [$<limit>] :'; query = query.replace(/\s*:?\s*$/, '') + ' [$<limit>]: ';
} }
display += query; display += query;
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "readline-sync", "name": "readline-sync",
"version": "1.4.3", "version": "1.4.4",
"title": "readlineSync", "title": "readlineSync",
"description": "Synchronous Readline for interactively running to have a conversation with the user via a console(TTY).", "description": "Synchronous Readline for interactively running to have a conversation with the user via a console(TTY).",
"keywords": [ "keywords": [