0.1.30 • Published 11 months ago
@trenskow/reader v0.1.30
@trenskow/reader
A simple package to ask questions of a stream.
Usage
To ask a question use the example below.
import { question } from '@trenskow/reader';
const answer = await question('What is your name?', {
// options
});
console.info(answer);Options
These are the options available for question.
| Name | Description | Default value |
|---|---|---|
defaultValue | The default value for the question. | |
silent | Do not echo input (useful for private data). | false |
input | The input stream to read from. | process.stdin |
output | The output stream to write to. | process.stdout |
Interviews
There is also an interview mechanism for filling an entire data structure. The data is validated using isvalid.
Usage
import { interview } from '@trenskow/reader';
const data = await interview({
// schema
'username': {
type: String,
label: 'Username',
description: 'Enter your username.',
type: String,
required: true,
len: '3-'
},
'password': {
type: String,
label: 'Password',
description: 'Enter your password.',
type: String,
required: true,
silent: true // Tells the interviewer to not echo input.
}
}, {
// options
});
console.info(data); // Will output `{ username: 'my-username', password: 'my-password' }`.Options
These are the options available for interview.
| Name | Description | Default value |
|---|---|---|
spacing | The number of vertical spacing (lines) between questions. | 0 |
input | The input stream to read from. | process.stdin |
output | The output stream to write to. | process.stdout |
Extensions to isvalid schemas
In addition to the build-in validators of isvalid, the following is also supported (as in the example above).
| Name | Description | Type | Default value |
|---|---|---|---|
label | The string to print before the user input. | String | |
description | The string to print above the question. | String | |
silent | Indicates if the property is private (does not echo input). | Boolean | false |
License
See license in LICENSE.
0.1.30
11 months ago
0.1.27
11 months ago
0.1.28
11 months ago
0.1.29
11 months ago
0.1.23
1 year ago
0.1.24
1 year ago
0.1.25
1 year ago
0.1.26
11 months ago
0.1.20
1 year ago
0.1.21
1 year ago
0.1.22
1 year ago
0.1.10
1 year ago
0.1.11
1 year ago
0.1.12
1 year ago
0.1.13
1 year ago
0.1.14
1 year ago
0.1.15
1 year ago
0.1.16
1 year ago
0.1.8
1 year ago
0.1.17
1 year ago
0.1.18
1 year ago
0.1.19
1 year ago
0.1.9
1 year ago
0.1.7
1 year ago
0.1.4
1 year ago
0.1.3
1 year ago
0.1.6
1 year ago
0.1.5
1 year ago
0.1.2
1 year ago
0.1.1
1 year ago
0.1.0
1 year ago