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

inquirer-table-input

v0.0.3

Published

A table input for Inquirer

Downloads

686

Readme

inquirer-table-input npm version

An editing table prompt for Inquirer.js

Screen capture of the table input

Installation

npm install --save inquirer-table-input

Usage

After registering the prompt, set any question to have type: "table-input" to make use of this prompt.

const chalk = require("chalk");
const inquirer = require("inquirer");
const TableInput = require("inquirer-table-input");

inquirer.registerPrompt("table-input", TableInput);

inquirer
  .prompt([
    {
      type: "table-input",
      name: "pricing",
      message: "PRICING",
      infoMessage: `Navigate and Edit`,
      hideInfoWhenKeyPressed: true,
      freezeColumns: 1,
      decimalPoint: ".",
      decimalPlaces: 2,
      selectedColor: chalk.yellow,
      editableColor: chalk.bgYellow.bold,
      editingColor: chalk.bgGreen.bold,
      columns: [
        { name: chalk.cyan.bold("NF Number"), value: "nf" },
        { name: chalk.cyan.bold("Customer"), value: "customer" },
        { name: chalk.cyan.bold("City"), value: "city", editable: "text" },
        {
          name: chalk.cyan.bold("Quantity"),
          value: "quantity",
          editable: "number"
        },
        {
          name: chalk.cyan.bold("Pricing"),
          value: "pricing",
          editable: "decimal"
        }
      ],
      rows: [
        [chalk.bold("8288"), "Shinji Masumoto", "Chicago", 1, 68.03],
        [chalk.bold("8289"), "Arnold Mcfee", "New York", 4, 125.85]
      ],
      validate: () => false /* See note ¹ */
    }
  ])
  .then(answers => {
    console.log(answers);
  });

¹ This extension of Inquirer was programmed to enable quick table editing, so it's common for users to use the ENTER key to confirm after updating a cell. However, by default, Inquirer was designed so that when ENTER is used, it concludes the answer, and this has become a problem for the purpose of this extension. Therefore, it is essential here to force VALIDATE to be FALSE so that the accidental triggering of ENTER does not correspond to the completion of the answer.

The result will be an array, containing the value for each row.

{
  "pricing": {
    "state": true,
    "result": [
      {
        "nf": "8288",
        "customer": "Shinji Masumoto",
        "city": "Chicago",
        "quantity": "1",
        "pricing": "68.03"
      },
      {
        "nf": "8289",
        "customer": "Arnold Mcfee",
        "city": "New York",
        "quantity": "4",
        "pricing": "125.85"
      }
    ]
  }
}

Options

  • infoMessage Optional A message that will appear after the message argument.
  • hideInfoWhenKeyPressed Default: false The infoMessage disappears after any key is pressed.
  • freezeColumns Default: 0 The number of frozen columns, preventing navigation and editing of them.
  • decimalPoint Default: '.' The decimal point used to represent editable columns of the "decimal" type.
  • decimalPlaces Default: 2 The decimal places used to represent editable columns of the "decimal" type.
  • selectedColor Default: chalk.yellow The color used to represent the currently selected cell.
  • editableColor Default: chalk.bgYellow.bold The color used to represent when a selected cell can be edited.
  • editingColor Default: chalk.bgGreen.bold The color used to represent when a cell is being edited.
  • escapeMessage Default: chalk.red("Press ESC again to exit!") Alert message that will appear when the user tries to cancel by pressing the ESC key.
  • confirmMessage Default: chalk.green("Press ENTER again to confirm!") Alert message that will appear when the user tries to confirm by pressing the ENTER key.
  • columns A array of objects that represent the columns of your table.
    • name The title that will represent the column (the one visible to the user).
    • value The name of the columns (Used to structure the result of the Inquirer response.)
    • editable Optional When used, it determines the type of the field to be edited, with options including "text", "number", and "decimal."
  • columns A array of values that represent the items of your table. The size of each array should represent the same number of columns in your table.

Acknowledgments

Thanks to Eduardo Bouças, creator of inquirer-table-prompt, which inspired me to create this project.