0.0.3 • Published 6 years ago

statewise v0.0.3

Weekly downloads
2
License
Apache-2.0
Repository
-
Last release
6 years ago

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('statewise');

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

      console.log(answer);

    }
  }),
  new State({
    name: 'get-name',
    run: async (data) => {
      data.name = await ask('What is your name?', /([a-zA-Z]+)$/, 'Bob')
      return { action: 'transition', stateName: 'main-menu' }
    }
  })
])

Examples

see the /examples directory to see some examples

if you have a cool example please open an PR!