1.1.0 • Published 2 years ago

@greggry/menu v1.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

menu-js

menu-js is a simple menu tool for use it for CLI interfaces.

Installation

npm i @greggry/menu

How it works

The Menu class takes in an array of object. Each object represents an option. The class executes the callbackFn argument, which should be attached to options. Only the callbacks that have no sub menus are executed. The onEmpty property has to be added as the last item in the options array.

Example

const Menu = require('@greggry/menu');

const options = [
  {
    text: 'option 1',
    submenu: [
      {
        text: 'option 1a',
        callbackFn: () => console.log('ran option 1a')
      },
      {
        text: 'option 1b',
        callbackFn: () => console.log('ran option 1b')
        doExitOnCallback: true;
      },
    ],
  },
  {
    text: 'option 2',
    callbackFn: () => console.log('ran option 2')
  },
  {
    text: 'option 3',
    callbackFn: () => console.log('ran option 3')
    onEmpty: true, // run when '' passed
    onEmptyDescription: 'Leave empty to quit'
    doExitOnCallback: true;
  }

];

const menu = new Menu(options);

If your project already uses a readline interface, you can pass it into the Ask() constructor as the second argument.

const ask = new Ask(options, readlineInterface);

1.1.0

2 years ago

1.0.0

2 years ago