🐾 remember what state you're in
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
test
.gitignore
.travis.yml
CHANGELOG.md
LICENSE
README.md
index.js
package.json

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!