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

termx-markup

v2.0.2

Published

Markup based text formatting for terminal.

Downloads

22

Readme

termx-markup

GitHub GitHub Workflow Status npm Libraries.io dependency status for latest release GitHub last commit

Usage

Print markup

import { Output, html } from "termx-markup";

Output.setDefaultPrintMethod(console.log); // (optional) print using console.log

const markup = html`
  <span bold color="red">
    Hello
    <pre color="blue"> in my </pre>
    world!
  </span>
`;

Output.println(markup);

Output:

Hello in my World!

Only formatting

import { MarkupFormatter, html } from "termx-markup";

const markup = html`
  <span color="red">
    Hello
    <pre color="blue"> in my </pre>
    world!
  </span>
`;

const formatted = MarkupFormatter.format(markup);
// formatted = "\u001b[31mHello \u001b[34min my\u001b[0m\u001b[31m world!\u001b[0m"

console.log(formatted);

Output:

Hello in my World!

Define custom colors

import { Output, MarkupFormatter, html } from "termx-markup";

MarkupFormatter.defineColor("burgundy", "rgb(128, 0, 32)");
MarkupFormatter.defineColor("mauve", "#E0B0FF");
MarkupFormatter.defineColor("teal", { r: 0, g: 128, b: 128 });

const markup = html`
  <line color="burgundy">Burgundy</line>
  <line color="mauve">Mauve</line>
  <line color="teal">Teal</line>
`;

Output.print(markup);

Output:

Burgundy, Mauve, Teal

Printing lists

import { Output, html } from "termx-markup";

Output.print(html`
  <line>Drinks:</line>
  <ul>
    <li>Coffee</li>
    <li>Tea</li>
    <li>
      <line>Milk</line>
      <ul type="circle">
        <li>Skim</li>
        <li>Whole</li>
      </ul>
    </li>
  </ul>
`);

Output:

Drinks: Coffee Tea Milk Skim Whole

Supported tags

  • <span> - regular text, trims white-space characters and removes end-line characters
  • <line> - same as span, but prints a new line character at the end
  • <pre> - preformatted text, all white-space characters will be preserved
  • <br /> - prints a new line character
  • <s /> - prints a space character
  • <ol> - ordered list, each child element is required to ba a <li> tag
  • <ul> - unordered list, each child element is required to ba a <li> tag, accepts additional attribute type (string) which can be of value circle, square or bullet (default is bullet)
  • <pad> - adds left padding to it's content, accepts attribute size (number) which determines the number of spaces to print
  • <frame> - adds a border around it's content, accepts attributes padding, padding-left, padding-right, padding-top, padding-bottom, padding-horizontal and padding-vertical (number) which determines the number of spaces to print between the border and the content

Inline and Block elements

There are two display types of elements, inline and block.

Inline elements are always rendered next to each other within the same line, if there are any white-spaces between the inline elements it will be replaced with a single space.

Block elements, start with a line break character, unless the block element is the first one, and end with a line break, unless the block element is the last one.

Inline elements:

  • <span>
  • <pre>
  • <br>
  • <s>
  • <li>

Block elements:

  • <line>
  • <frame>
  • <pad>
  • <ul>
  • <ol>

Supported attributes

Following attributes are available on all tags:

  • color - color of the text (css-like rgb or a color name)
  • bg - background color of the text (css-like rgb or a color name)
  • bold - bold text (boolean)
  • dim - dimmed text (boolean)
  • italic - italic text (boolean)
  • underscore - underlined text (boolean)
  • blink - blinking text (boolean)
  • invert - inverse color text (boolean)
  • strike - strike-through text (boolean)
  • no-inherit - prevents inheriting parent styles (boolean)

Default available colors

  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • lightRed
  • lightGreen
  • lightYellow
  • lightBlue
  • lightMagenta
  • lightCyan
  • lightWhite