AskIt
Wrapper around inquirer to make asking questions in Node CLIs easier.
Setup
Install It
Add to your package.json
"askIt": "git+https://github.com/keg-hub/askIt.git"
Use It
See an example here
;(() => {
const { ask, separator, models } = require('askIt')
const questionModelObject = {
...models.input,
type: 'Question type',
name: 'Name of the question',
message: 'Question to ask',
default: 'Default value if user enters nothing',
}
const askResponse = await ask({ ...questionModelObject })
const confirmResponse = await ask.confirm('Ask a confirm question?')
const inputResponse = await ask.input('Ask for text input')
const passwordResponse = await ask.password('Ask for hidden text input')
const listResponse = await ask.promptList([
'Option 1',
'Option 2',
'Option 3',
])
})()
API
ask
- @type
function
- @param
Object
- a question model object
- ask.confirm
- @type
function
- @param
string
- The true / false question to ask - Helper method to ask a true/false question
- Accepts a
string
used as the question asked to the user
- ask.input
- @type
function
- @param
string
- The text input question to ask - Helper method to ask a text input question
- ask.password
- @type
function
- @param
string
- The text input question to ask - Same as
ask.input
, except user input is hidden
- ask.promptList
- @type
function
- @param
array
- List of options to present to the user - Asks the user to select from a list of options
- @returns -
index
of the selected item from the passed in options
separator
- @type
function
- Helper that returns
new inquirer.Separator()
models
- @type
Object
- Prebuilt question models with defaults already set
- Expected to be overwritten with custom values as needed
- Question model object