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";

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

Variables

Const backgroundColor

backgroundColor: (Anonymous function) = optionalFormat(49)

Takes an open ANSI code and a source string and adds the open and close ANSI codes to that string (for background color).

returns

Curried function with close ANSI code for background in context.

Const blackBackground

blackBackground: (Anonymous function) = backgroundColor(40)

Takes a source string and adds the ANSI codes for black background.

returns

source string with black background.

Const blackText

blackText: (Anonymous function) = textColor(30)

Takes a source string and adds the ANSI codes for black color.

returns

source string with black color.

Const blueBackground

blueBackground: (Anonymous function) = backgroundColor(44)

Takes a source string and adds the ANSI codes for blue background.

returns

source string with blue background.

Const blueText

blueText: (Anonymous function) = textColor(34)

Takes a source string and adds the ANSI codes for blue color.

returns

source string with blue color.

Const bold

bold: (Anonymous function) = optionalFormat(22)(1)

Takes a source string and adds the ANSI codes for bold text.

returns

source string with bold format.

Const cyanBackground

cyanBackground: (Anonymous function) = backgroundColor(46)

Takes a source string and adds the ANSI codes for cyan background.

returns

source string with cyan background.

Const cyanText

cyanText: (Anonymous function) = textColor(36)

Takes a source string and adds the ANSI codes for cyan color.

returns

source string with cyan color.

Const dimmed

dimmed: (Anonymous function) = optionalFormat(22)(2)

Takes a source string and adds the ANSI codes for dimmed text.

returns

source string with dimmed format.

Const grayText

grayText: (Anonymous function) = textColor(90)

Takes a source string and adds the ANSI codes for gray color.

returns

source string with gray color.

Const greenBackground

greenBackground: (Anonymous function) = backgroundColor(42)

Takes a source string and adds the ANSI codes for green background.

returns

source string with green background.

Const greenText

greenText: (Anonymous function) = textColor(32)

Takes a source string and adds the ANSI codes for green color.

returns

source string with green color.

Const greyText

greyText: (Anonymous function) = grayText

Alias for grayText.

Const hidden

hidden: (Anonymous function) = optionalFormat(28)(8)

Takes a source string and adds the ANSI codes for hidden text.

returns

source string with hidden format.

Const inverse

inverse: (Anonymous function) = optionalFormat(27)(7)

Takes a source string and adds the ANSI codes for inverse text.

returns

source string with inverse format.

Const italic

italic: (Anonymous function) = optionalFormat(23)(3)

Takes a source string and adds the ANSI codes for italic text.

returns

source string with italic format.

Const magentaBackground

magentaBackground: (Anonymous function) = backgroundColor(45)

Takes a source string and adds the ANSI codes for magenta background.

returns

source string with magenta background.

Const magentaText

magentaText: (Anonymous function) = textColor(35)

Takes a source string and adds the ANSI codes for magenta color.

returns

source string with magenta color.

Const optionalFormat

optionalFormat: format = formattingEnabled(process)? format: (_close: number) => (_open: number) => (source: string) => source

Impure version of format which changes depending on the current NodeJS process environment.

param

NodeJS process.

Const redBackground

redBackground: (Anonymous function) = backgroundColor(41)

Takes a source string and adds the ANSI codes for red background.

returns

source string with red background.

Const redText

redText: (Anonymous function) = textColor(31)

Takes a source string and adds the ANSI codes for red color.

returns

source string with red color.

Const strikethrough

strikethrough: (Anonymous function) = optionalFormat(29)(9)

Takes a source string and adds the ANSI codes for strikethrough text.

returns

source string with strikethrough format.

Const textColor

textColor: (Anonymous function) = optionalFormat(39)

Takes an open ANSI code and a source string and adds the open and close ANSI codes to that string (for text color).

returns

Curried function with close ANSI code for text color in context.

Const underlined

underlined: (Anonymous function) = optionalFormat(24)(4)

Takes a source string and adds the ANSI codes for underlined text.

returns

source string with underlined format.

Const whiteBackground

whiteBackground: (Anonymous function) = backgroundColor(47)

Takes a source string and adds the ANSI codes for white background.

returns

source string with white background.

Const whiteText

whiteText: (Anonymous function) = textColor(37)

Takes a source string and adds the ANSI codes for white color.

returns

source string with white color.

Const yellowBackground

yellowBackground: (Anonymous function) = backgroundColor(43)

Takes a source string and adds the ANSI codes for yellow background.

returns

source string with yellow background.

Const yellowText

yellowText: (Anonymous function) = textColor(33)

Takes a source string and adds the ANSI codes for yellow color.

returns

source string with yellow color.

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 format

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

    Parameters

    • close: number

      Close value.

    Returns (Anonymous function)

    Curried function with close in context.

Const formattingEnabled

  • formattingEnabled(__namedParameters?: { env: { FORCE_COLOR: undefined | string; NODE_DISABLE_COLORS: undefined | string; NO_COLOR: undefined | string; TERM: undefined | string }; stdout: object }): boolean
  • Given a NodeJS process, return true if colors are enabled.

    Parameters

    • Default value __namedParameters: { env: { FORCE_COLOR: undefined | string; NODE_DISABLE_COLORS: undefined | string; NO_COLOR: undefined | string; TERM: undefined | string }; stdout: object } = {}
      • env: { FORCE_COLOR: undefined | string; NODE_DISABLE_COLORS: undefined | string; NO_COLOR: undefined | string; TERM: undefined | string }
        • FORCE_COLOR: undefined | string
        • NODE_DISABLE_COLORS: undefined | string
        • NO_COLOR: undefined | string
        • TERM: undefined | string
      • stdout: object
        • isTTY: false

    Returns boolean

Const mix

  • mix(formatters: readonly ReturnType<ReturnType<typeof format>>[]): (Anonymous function)
  • Composes formatters.

    Parameters

    • formatters: readonly ReturnType<ReturnType<typeof format>>[]

      Array of formatters to be composed.

    Returns (Anonymous function)

Legend

Generated using TypeDoc