0.1.30 • Published 5 months ago

@trenskow/reader v0.1.30

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
5 months ago

@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.

NameDescriptionDefault value
defaultValueThe default value for the question.
silentDo not echo input (useful for private data).false
inputThe input stream to read from.process.stdin
outputThe 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.

NameDescriptionDefault value
spacingThe number of vertical spacing (lines) between questions.0
inputThe input stream to read from.process.stdin
outputThe 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).

NameDescriptionTypeDefault value
labelThe string to print before the user input.String
descriptionThe string to print above the question.String
silentIndicates if the property is private (does not echo input).Booleanfalse

License

See license in LICENSE.

0.1.30

5 months ago

0.1.27

5 months ago

0.1.28

5 months ago

0.1.29

5 months ago

0.1.23

6 months ago

0.1.24

6 months ago

0.1.25

6 months ago

0.1.26

5 months ago

0.1.20

6 months ago

0.1.21

6 months ago

0.1.22

6 months ago

0.1.10

6 months ago

0.1.11

6 months ago

0.1.12

6 months ago

0.1.13

6 months ago

0.1.14

6 months ago

0.1.15

6 months ago

0.1.16

6 months ago

0.1.8

6 months ago

0.1.17

6 months ago

0.1.18

6 months ago

0.1.19

6 months ago

0.1.9

6 months ago

0.1.7

6 months ago

0.1.4

7 months ago

0.1.3

7 months ago

0.1.6

6 months ago

0.1.5

6 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago