npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jacoobanderson/interface-creator

v1.0.9

Published

A module that helps in creating a terminal user interface

Downloads

3

Readme

Installation and Usage

This is a Node.js module that is installed using:

$ npm i @jacoobanderson/interface-creator

Import the module and initialize a new interface creator by writing:

import { InterfaceCreator } from '@jacoobanderson/interface-creator'

const ui = new InterfaceCreator()

You can then call the methods on the ui by:

const ui = new InterfaceCreator()

ui.setColor('menu', 'red')

Methods

This is a list of the different methods that are offered:

| Method | Description | | ------------------- | ---------------------------------------------| | createPrompt(string, function, color) | Creates a string/question and also prompts the user and allows for the user's input to be handled. string is a string that shows before the user prompt.function is a function that takes the input as a parameter and handles the input.color is the color that the first parameter string should be. | | addExitOption() | Adds an exit option in the main menu. | | setMainMenu(menuOptions) | Sets the main menu view. menuOptions is a object that should contain numbered keys starting from 1 with values set to the strings that wants to be shown in the menu. | | assignMainMenuFunctionality(menuFunctionality) | Assigns the functionality needed for the main menu view menuFunctionality is an object that should contain numbered keys starting from 1 and correlate to the menuOptions, the values should be functions which will be called when the correspondent menuOption is chosen. | | createSubMenu(view, functionality) | This method is supposed to be used in another menu, i.e in the main menu as a value of the menuFunctionality object or in another submenu functionality object. view is a object that should contain numbered keys starting from 1 with values set to the strings that wants to be shown in the submenu. functionality is an object that should contain numbered keys starting from 1 and correlate to the view, the values should be functions which will be called when the correspondent view option is chosen. | | addReturnToMenuOption() | Adds a return to menu option in sub menus or after main menu functionality has been called. | | createForm(questions) | Used to create a form which supports both regular questions with written answers and multichoice questions. createForm needs to be put inside an async function, should be returned to extract the answers questions is an array that contains strings for regular questions with written answers and an object with the question as the key and and array of multichoice answers as the value for multichoice questions. | | start() | Is the method that initializes the user interface and is supposed to be put after all other methods in the code. This method is essential for it all to work. It can also be used as a method to return to the main menu if needed. | | setColor(section, color) | Sets the color of a certain section in the user interface section is the section that the color should apply to. color is the color that the section should have. All the available colors and sections are shown down below. |

Available color sections

menu The main menu. exit The exit message. returnToMenu The return to menu message. form The form.

Available colors

red green yellow blue cyan

Method examples

    ui.createPrompt('What is your name?', (user) => console.log('Welcome, ' + user + '\n'), 'blue')  
    ui.setMainMenu({
        1: 'Go to sub menu',
        2: 'Divide values',
        3: 'Multiply values'
    })
    const view = {
        1: 'Add values',
        2: 'Form',
        3: 'Subtract values'
    }

    const functionality = {
        1: () => addValues(1, 3),
        2: async () => await functionWithCreateForm(),
        3: () => subtractValues(23, 34)
    }


    ui.assignMainMenuFunctionality({
        1: () => ui.createSubMenu(view, functionality),
        2: () => divideValues(),
        3: () => multiplyValues()
    })
// Creates form and returns answers
async function form() {
  return await ui.createForm([
    'What is your name?',
    'What is your cats name?',
    // Question with multi choice answers.
    {
      'Which country do you live in?': ['Sweden', 'Norway', 'Denmark']
    }
  ])
}

const data = await form()
// Shows the form data.
console.log(data)
    ui.setColor('form', 'blue')