0.0.5 • Published 8 years ago

@joegesualdo/prompt-node v0.0.5

Weekly downloads
-
License
-
Repository
github
Last release
8 years ago

prompt Build Status

Command line prompt.

demo

Highlights

  • Supports validation
  • Hides password

Install

$ npm install --save @joegesualdo/prompt-node

Usage

import prompt from '@joegesualdo/prompt-node'

new Prompt('Are you tired?')
.on('done', answer => {
  console.log(`You've answered '${answer}'`)
})
.begin()

Test

$ npm test

API

Prompt(text, [options])

Instantiates a new prompt

Params

NameTypeDefaultDescription
textArrayTest description

Options

NameTypeDefaultDescription
hiddenBooleanfalseShould answer be hidden?
requiredBooleanfalseDoes it accept empty answers?
validationFunction() => {return true}Test if answer is valid

Returns: prompt

import prompt from '@joegesualdo/prompt-node'

new Prompt('Are you tired?', {
  required: true,
  hidden: true,
  validation: (answer) => {
    return answer === 'woo';
  }
})

prompt.begin()

Starts the prompt

import prompt from '@joegesualdo/prompt-node'

new Prompt('Are you tired?')
.on('done', answer => {
  console.log(`You've answered '${answer}'`)
})
.begin()

prompt.on(type, fn)

Sets lifecycle methods

Params

NameTypeDefaultDescriptionPossible values
typeStringN/AThe lifecycle namebackspace, keypress, validationError, change, done
fnFunctionN/AFunction to runN/A
import prompt from '@joegesualdo/prompt-node'

new Prompt('Are you tired?')
.on('validationError', answer => {
})
.on('backspace', () => {
})
.on('change', (oldStr, newStr ) => {
})
.on('done', answer => {
  console.log(`You've answered '${answer}'`)
})
.begin()

Build

$ npm run build

License

MIT © Joe Gesualdo