New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

tiny-menu

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiny-menu

Terminal menu

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

tiny-menu

Terminal menu

npm i tiny-menu

Usage

const Menu = require('tiny-menu')

const menu = new Menu({
  render (page) {
    this.create('MENU')

    this.add(1, 'List')
    this.add(2, 'Add')
    this.add(3, 'Remove')
    this.add(4, 'Edit\n')

    this.add(-1, 'Text A')
    this.add(-1, 'Text B\n')

    this.add(9, 'Generate\n')

    this.add(0, 'Exit')
  },
  handler (item, value, page) {
    console.log('Callback:', { item, value, page })
  }
})

await menu.show()

Examples

Pagination

const Menu = require('tiny-menu')

const DATA = new Array(25).fill().map(() => Math.random())

const viewer = new Menu({
  render (page) {
    const pages = Menu.calculatePages(page, DATA.length, 10)

    this.create('Pagination (' + pages.page + '/' + pages.max + ')')

    this.add(-1, 'Data:')

    for (let i = pages.start, count = 1; i < pages.end; i++, count++) {
      this.add(-1, crayon.yellow('#' + i) + ' ' + DATA[i])
    }

    this.add(-1, '')
    this.add(8, 'Back', { disabled: page <= 1 })
    this.add(9, 'Next', { disabled: page >= pages.max })
    this.add(0, 'Exit')
  },
  handler (item, value, page) {
    if (item === 0 || item === null) return
    if (item === 8) return viewer.show(page - 1)
    if (item === 9) return viewer.show(page + 1)
  }
})

await viewer.show()

License

Apache-2.0

FAQs

Package last updated on 05 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts