Options
All
  • Public
  • Public/Protected
  • All
Menu

Lightweight utilities for text manipulation/coloring. Low import impact

Hierarchy

  • TextUtils

Index

Properties

Static Readonly AVAILABLE_CHALK_COLORS

AVAILABLE_CHALK_COLORS: string[] = ["red", "magenta", "blue", "green", "grey", "yellow", "cyan"]

Static Readonly DEFAULT_WRAP_WIDTH

DEFAULT_WRAP_WIDTH: 80 = 80

Accessors

Static chalk

  • get chalk(): any

Methods

Static buildHeaders

  • buildHeaders(objects: any[]): string[]

Static explainObject

  • explainObject(original: any, explanationMap: IExplanationMap, includeUnexplainedKeys?: boolean): any
  • Replace keys from an object with string explanations for those keys, primarily so that they can be printed for the user to read.

    Parameters

    • original: any

      the original object e.g. a response from a z/OSMF API {wrdKy4U: "weirdkeyvalue"}

    • explanationMap: IExplanationMap

      an object that maps the original to the new format

    • Default value includeUnexplainedKeys: boolean = true

      should keys not covered by the explanation object be included in the result?

    Returns any

    • the explained object

Static formatMessage

  • formatMessage(message: string, ...values: any[]): string
  • Auto-detect whether a message should be formatted with printf-style formatting or mustache (but don't try to use both!) and format the string accordingly

    Parameters

    • message: string

      the string message with %s or {{mustache}} style variables

    • Rest ...values: any[]

      the fields that will resolve the printf or mustache template

    Returns string

    • a formatted string with the variables inserted

Static getRecommendedWidth

  • getRecommendedWidth(preferredWidth?: number): number
  • Get the recommended width to wrap text. You can specify a preferred width, but this method width return

    Parameters

    • Default value preferredWidth: number = TextUtils.DEFAULT_WRAP_WIDTH

      the width you would like to use if supported by the user's terminal

    Returns number

    • the width that will work best for the user's terminal

Static getTable

  • getTable(objects: any[], primaryHighlightColor: string, maxColumnWidth?: number, includeHeader?: boolean, includeBorders?: boolean, hardWrap?: boolean, headers?: string[]): string
  • Parameters

    • objects: any[]

      the key-value objects to convert to a

    • primaryHighlightColor: string

      the main color to highlight headings of the table with. e.g. "blue"

    • Optional maxColumnWidth: number

      override the default column width of the table?

    • Default value includeHeader: boolean = true

      should the table include a header of the field names of the objects

    • Default value includeBorders: boolean = false

      should the table have borders between the cells?

    • Default value hardWrap: boolean = false

      hard wrap the text within the width of the table cells (defaults to false)

    • Optional headers: string[]

      specify which headers in which order to display. if omitted, loops through the rows and adds object properties as headers in their enumeration order

    Returns string

    the rendered table

Static highlightMatches

  • highlightMatches(text: string, term: RegExp): string
  • Highlight all matches of a full regex with TextUtils.chalk

    Parameters

    • text: string

      the text you'd like to search for matches

    • term: RegExp

      a regular expression of terms to highlight

    Returns string

    • the highlighted string

Static indentLines

  • indentLines(text: string, indent?: string): string

Static parseKeyValueString

  • parseKeyValueString(keysAndValues: string): {}
  • Parse a key value string into an object

    Parameters

    • keysAndValues: string

      a string in the format key1=value1,key2=value2,key3=value3. Note: the key names are case sensitive

    Returns {}

    the parsed object

    • [key: string]: string

Static prettyJson

  • prettyJson(object: any, options?: any, color?: boolean, append?: string): string

Static renderTemplateFromKeyValueArguments

  • renderTemplateFromKeyValueArguments(template: string, keysAndValues: string): string
  • Render a mustache template based on arguments from the user

    throws

    an Error if the keysAndValues are not in the expected format

    Parameters

    • template: string

      the mustache-style template string into which you would like to insert your values

    • keysAndValues: string

      a string in the format key1=value1,key2=value2,key3=value3. Note: the key names are case sensitive

    Returns string

    • the rendered template

Static renderWithMustache

  • renderWithMustache(template: string, values: any): string

Static wordWrap

  • wordWrap(text: string, width?: number, indent?: string, hardWrap?: boolean, trim?: boolean): string
  • Wrap some text so that it fits within a certain width with the wrap-ansi package

    Parameters

    • text: string

      The text you would like to wrap

    • Optional width: number

      The width you would like to wrap to - we'll try to determine the optimal width based on this (the resulting wrap may be wrapped to fewer columns, but not more)

    • Default value indent: string = ""

      Add this string to every line of the result

    • Default value hardWrap: boolean = false

      do not allow any letters past the requested width - defaults to false

    • Default value trim: boolean = true

    Returns string

Generated using TypeDoc