Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

statewise

šŸ¾ remember what state you're in

Npm Version Build Status Coverage Status Dependency Status devDependency Status npm npm

statewise is a CLI helper that helps get you get things working without the stress of application state.

TOC

Installation

npm install statewise --save

Usage

const { StateManager, State, ask } = require('../');

const stateManager = new StateManager([
  new State({
    name: 'main-menu',
    run: async (data) => {
      if (!data.name) return State.transition('get-name')
      const choice = await ask(`
hello ${data.name}
======================
please select one
======================
1. change name
2. exit
`, /([1-2])/, '1|2')

      switch (parseInt(choice)) {
        case 1:
          return State.transition('get-name')
        case 2:
          console.log('Good bye šŸ‘‹')
          return State.exit()
        default:
          return State.exit()
      }
    }
  }),
  new State({
    name: 'get-name',
    run: async (data) => {
      data.name = await ask('What is your name?', /([a-zA-Z]+)$/, 'Bob')
      return State.transition('main-menu')
    }
  })
])

await stateManager.run()
process.exit()

Examples

see the /examples directory to see some examples

if you have a cool example please open an PR!