Options
All
  • Public
  • Public/Protected
  • All
Menu

@vangware/forcli

Build Status Coverage License NPM Version Open Issues Size

🎨 Functional CLI ANSI formatter.

Usage

This package can be installed as a dependency or used directly.

Usage as ECMAScript module

In JS or deno:

import { isObject } from "https://cdn.skypack.dev/@vangware/forcli";

Or in HTML:

<script type="module" src="https://cdn.skypack.dev/@vangware/forcli"></script>

Usage with local installation

First:

npm i @vangware/forcli

And then:

import { whiteText, redBackground, bold, mix } from "@vangware/forcli";

// You can just use the styles
console.log(redBackground("Red background text"));

// Or you can mix them!
const warningText = mix([whiteText, redBackground, bold]);

console.log(warningText("Warning!"));

Documentation

Documentation can be found HERE. It is auto-generated with typedoc based on the JSDocs and the types in the source. Shouldn't be necessary to read this, code editors like VSCode integrate the documentation in the UI.

Changelog

Changelog can be found HERE.

Test coverage

Test coverage can be found HERE.

Index

Functions

Const ansi

  • ansi(source: number): string
  • Takes a source number and returns the escape ANSI sequence.

    Parameters

    • source: number

      Source to escape.

    Returns string

    Escaped ANSI sequence.

Const blackBackground

  • blackBackground(source: string): string
  • Takes a source string and adds the ANSI codes for black background.

    Parameters

    • source: string

    Returns string

    source string with black background.

Const blackText

  • blackText(source: string): string
  • Takes a source string and adds the ANSI codes for black color.

    Parameters

    • source: string

    Returns string

    source string with black color.

Const blueBackground

  • blueBackground(source: string): string
  • Takes a source string and adds the ANSI codes for blue background.

    Parameters

    • source: string

    Returns string

    source string with blue background.

Const blueText

  • blueText(source: string): string
  • Takes a source string and adds the ANSI codes for blue color.

    Parameters

    • source: string

    Returns string

    source string with blue color.

Const bold

  • bold(source: string): string
  • Takes a source string and adds the ANSI codes for bold text.

    Parameters

    • source: string

    Returns string

    source string with bold format.

Const cyanBackground

  • cyanBackground(source: string): string
  • Takes a source string and adds the ANSI codes for cyan background.

    Parameters

    • source: string

    Returns string

    source string with cyan background.

Const cyanText

  • cyanText(source: string): string
  • Takes a source string and adds the ANSI codes for cyan color.

    Parameters

    • source: string

    Returns string

    source string with cyan color.

Const dimmed

  • dimmed(source: string): string
  • Takes a source string and adds the ANSI codes for dimmed text.

    Parameters

    • source: string

    Returns string

    source string with dimmed format.

Const format

  • format(close: number): (open: number) => (source: string) => string
  • Given an open, a close value and a source string, return formatted source (surrounded by open and close).

    Parameters

    • close: number

      Close value.

    Returns (open: number) => (source: string) => string

    Curried function with close in context.

      • (open: number): (source: string) => string
      • Parameters

        • open: number

        Returns (source: string) => string

          • (source: string): string
          • Parameters

            • source: string

            Returns string

            Curried function with open and close in context.

Const formattingEnabled

  • formattingEnabled(__namedParameters?: { env?: ProcessEnv; stdout?: Pick<WriteStream & { fd: 1 }, "isTTY"> }): boolean
  • Given a NodeJS process, return true if colors are enabled.

    Parameters

    • __namedParameters: { env?: ProcessEnv; stdout?: Pick<WriteStream & { fd: 1 }, "isTTY"> } = {}
      • Optional Readonly env?: ProcessEnv
      • Optional Readonly stdout?: Pick<WriteStream & { fd: 1 }, "isTTY">

    Returns boolean

Const grayText

  • grayText(source: string): string
  • Takes a source string and adds the ANSI codes for gray color.

    Parameters

    • source: string

    Returns string

    source string with gray color.

Const greenBackground

  • greenBackground(source: string): string
  • Takes a source string and adds the ANSI codes for green background.

    Parameters

    • source: string

    Returns string

    source string with green background.

Const greenText

  • greenText(source: string): string
  • Takes a source string and adds the ANSI codes for green color.

    Parameters

    • source: string

    Returns string

    source string with green color.

Const greyText

  • greyText(source: string): string
  • Alias for grayText.

    Parameters

    • source: string

    Returns string

Const hidden

  • hidden(source: string): string
  • Takes a source string and adds the ANSI codes for hidden text.

    Parameters

    • source: string

    Returns string

    source string with hidden format.

Const inverse

  • inverse(source: string): string
  • Takes a source string and adds the ANSI codes for inverse text.

    Parameters

    • source: string

    Returns string

    source string with inverse format.

Const italic

  • italic(source: string): string
  • Takes a source string and adds the ANSI codes for italic text.

    Parameters

    • source: string

    Returns string

    source string with italic format.

Const magentaBackground

  • magentaBackground(source: string): string
  • Takes a source string and adds the ANSI codes for magenta background.

    Parameters

    • source: string

    Returns string

    source string with magenta background.

Const magentaText

  • magentaText(source: string): string
  • Takes a source string and adds the ANSI codes for magenta color.

    Parameters

    • source: string

    Returns string

    source string with magenta color.

Const mix

  • mix(formatters: readonly ((source: string) => string)[]): (source: string) => string
  • Composes formatters.

    Parameters

    • formatters: readonly ((source: string) => string)[]

      Array of formatters to be composed.

    Returns (source: string) => string

      • (source: string): string
      • Parameters

        • source: string

        Returns string

Const optionalFormat

  • optionalFormat(close: number): (open: number) => (source: string) => string
  • Impure version of format which changes depending on the current NodeJS process environment.

    Parameters

    • close: number

    Returns (open: number) => (source: string) => string

      • (open: number): (source: string) => string
      • Parameters

        • open: number

        Returns (source: string) => string

          • (source: string): string
          • Parameters

            • source: string

            Returns string

            Curried function with open and close in context.

Const redBackground

  • redBackground(source: string): string
  • Takes a source string and adds the ANSI codes for red background.

    Parameters

    • source: string

    Returns string

    source string with red background.

Const redText

  • redText(source: string): string
  • Takes a source string and adds the ANSI codes for red color.

    Parameters

    • source: string

    Returns string

    source string with red color.

Const strikethrough

  • strikethrough(source: string): string
  • Takes a source string and adds the ANSI codes for strikethrough text.

    Parameters

    • source: string

    Returns string

    source string with strikethrough format.

Const underlined

  • underlined(source: string): string
  • Takes a source string and adds the ANSI codes for underlined text.

    Parameters

    • source: string

    Returns string

    source string with underlined format.

Const whiteBackground

  • whiteBackground(source: string): string
  • Takes a source string and adds the ANSI codes for white background.

    Parameters

    • source: string

    Returns string

    source string with white background.

Const whiteText

  • whiteText(source: string): string
  • Takes a source string and adds the ANSI codes for white color.

    Parameters

    • source: string

    Returns string

    source string with white color.

Const yellowBackground

  • yellowBackground(source: string): string
  • Takes a source string and adds the ANSI codes for yellow background.

    Parameters

    • source: string

    Returns string

    source string with yellow background.

Const yellowText

  • yellowText(source: string): string
  • Takes a source string and adds the ANSI codes for yellow color.

    Parameters

    • source: string

    Returns string

    source string with yellow color.

Legend

Generated using TypeDoc