New:Socket for Asana Is Now Available.Learn more
Get Started

fmttxt

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fmttxt

Small library for formatting plain text.

latest
Source
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

fmttxt

Small plain text formatting library.

Say you want to create a simple text tile table but you want to format some cell of it to specific length. Here's an simple example


    var fmt = require("../fmttxt"),
        data = {
            "jane.doe@example.com": {date: "03/19/1902", hour: "9.6"},
            "john.doe@example": {date: "04/01/1902", hour: "3.5"}
        };

    // Create a simple heading line
    console.log("| " + 
        [fmt.right("Contact", 36), fmt.left("Hour", 24), fmt.center("Date", 24)].join(" | ") +
        " |");
    // Create a separator row
    console.log("+-" +
        [fmt.left("-", 36, "-"), fmt.left("-", 24, "-"), fmt.left("-", 24, "-")].join("-+-") +
        "-+");

    // Now our simple table.
    Object.keys(data).forEach(function (contact) {
        // Create a data row
        console.log("| " +
            [fmt.right(contact, 36), fmt.left(data[contact].hour, 24), fmt.center(data[contact].date, 24)].join(" | ") +
            " |");
        // Create a separator row
        console.log("+-" +
            [fmt.left("-", 36, "-"), fmt.left("-", 24, "-"), fmt.left("-", 24, "-")].join("-+-") +
            "-+");
    });

Keywords

text

FAQs

Package last updated on 11 Feb 2015

Related posts