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

gluegun-print

v1.0.1

Published

Simple Gluegun Print Toolbox export

Downloads

904

Readme

gluegun-print

Note: This is just an export from Gluegun Print Toolbox

The gluegun-print module provides various functions to print styled messages and tables in the console. You can use these functions to display information with different colors and formatting.

Usage

Installation

Install the module via npm or yarn:

npm install gluegun-print

# or

yarn add gluegun-print

Importing the Module

To use the print module in your Node.js application, import it as follows:

// CommonJS
const print = require('gluegun-print')

// ES modules
import print from 'gluegun-print'

Basic Example

Here's a basic example of how to use the print module to display different types of messages:

import print from 'gluegun-print'

print.info('This is an information message.');
print.error('This is an error message.');
print.warning('This is a warning message.');
print.success('This is a success message.');
print.highlight('This is a highlighted message.');
print.muted('This is a muted message.');

print.divider(); // Print a divider line
print.newline(); // Print a blank line

Printing a Table

The print.table(data, options) function allows you to display data in a table format. The data parameter should be an array of arrays, where each inner array represents a row of data. The options parameter is optional and allows you to specify the table format and style.

const tableData = [
  ['Name', 'Age', 'Country'],
  ['John', '30', 'USA'],
  ['Alice', '25', 'Canada'],
  ['Bob', '28', 'UK']
];

const tableOptions = {
  format: 'lean', // 'markdown', 'lean', or 'default' (default: 'default')
  style: {
    'padding-left': 1,
    'padding-right': 1
  }
};

print.table(tableData, tableOptions);

Using a Spinner

The print.spin(config) function creates and starts a spinner using ora. You can use it to indicate that a process is in progress.

const spinner = print.spin('Loading...');
setTimeout(() => {
  spinner.succeed('Process completed successfully.');
}, 3000);

Debugging Messages

The print.debug(message, title) function is useful for printing debug messages. It adds a title to distinguish debug output.

const debugMessage = 'Some debug information.';
print.debug(debugMessage, 'DEBUG');

API

| Method | Description | | -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | | newline() | Print a blank line. | | divider() | Prints a divider line. | | findWidths(cliTable) | Returns an array of the column widths for the given cliTable data table. | | columnHeaderDivider(cliTable, style) | Returns an array of column dividers based on column widths, considering possible paddings. | | resetTablePadding(cliTable) | Resets the padding of a table. | | table(data, options) | Prints an object to table format. The values will already be stringified. Accepts options.format (default: 'default') and options.style. | | fancy(message) | Prints text without theming. | | info(message) | Writes a normal information message. | | error(message) | Writes an error message. | | warning(message) | Writes a warning message. | | debug(message, title) | Writes a debug message. Accepts an optional title parameter. | | success(message) | Writes a success message. | | highlight(message) | Writes a highlighted message. | | muted(message) | Writes a muted message. | | spin(config) | Creates a spinner and starts it up. Accepts a configuration object or a string for the spinner text. | | checkmark | A checkmark symbol (✔︎) as a colored string. | | xmark | A crossmark symbol (ⅹ) as a colored string. |