Giter Club home page Giter Club logo

gluegun-print's Introduction

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.

gluegun-print's People

Contributors

greguintow avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.