Lightweight utilities for text manipulation/coloring. Low import impact

### Hierarchy

- TextUtils

## Index

### Properties

- AVAILABLE_CHALK_COLORS
- DEFAULT_WRAP_WIDTH

### Accessors

- chalk

### Methods

- buildHeaders
- explainObject
- formatMessage
- getRecommendedWidth
- getTable
- highlightMatches
- indentLines
- parseKeyValueString
- prettyJson
- renderTemplateFromKeyValueArguments
- renderWithMustache
- wordWrap

## Properties

### Static Readonly AVAILABLE_CHALK_COLORS

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

- Defined in @zowe/imperative/src/utilities/src/TextUtils.ts:30

### Static Readonly DEFAULT_WRAP_WIDTH

DEFAULT_WRAP_WIDTH: 80 = 80

- Defined in @zowe/imperative/src/utilities/src/TextUtils.ts:29

## Accessors

### Static chalk

- get chalk(): any

- - Defined in @zowe/imperative/src/utilities/src/TextUtils.ts:302

  #### Returns any

## Methods

### Static buildHeaders

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

- - Defined in @zowe/imperative/src/utilities/src/TextUtils.ts:216

  Build table headers from an array of key-value objects

  #### Parameters

  - ##### objects: any[]

    the key-value objects from which to build headers

  #### Returns string[]

  the headers array

### Static explainObject

- explainObject(original: any, explanationMap: IExplanationMap, includeUnexplainedKeys?: boolean): any

- - Defined in @zowe/imperative/src/utilities/src/TextUtils.ts:68

  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

- - Defined in @zowe/imperative/src/utilities/src/TextUtils.ts:279

  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

- - Defined in @zowe/imperative/src/utilities/src/TextUtils.ts:39

  Get the recommended width to wrap text. You can specify a preferred width, but this method width return

  #### Parameters

  - ##### Default value preferredWidth: number = process?.stdout?.columns ? process.stdout.columns : 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

- - Defined in @zowe/imperative/src/utilities/src/TextUtils.ts:160

  #### 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

- - Defined in @zowe/imperative/src/utilities/src/TextUtils.ts:266

  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

- - Defined in @zowe/imperative/src/utilities/src/TextUtils.ts:251

  Indent some text

  #### Parameters

  - ##### text: string

    The text you would like to indent

  - ##### Default value indent: string = ""

    Add this string to every line of the result

  #### Returns string

### Static parseKeyValueString

- parseKeyValueString(keysAndValues: string): {}

- - Defined in @zowe/imperative/src/utilities/src/TextUtils.ts:326

  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

- - Defined in @zowe/imperative/src/utilities/src/TextUtils.ts:129

  Get a json object in tabular form

  #### Parameters

  - ##### object: any

  - ##### Optional options: any

  - ##### Default value color: boolean = true

    use color on the result?

  - ##### Default value append: string = ""

  #### Returns string

### Static renderTemplateFromKeyValueArguments

- renderTemplateFromKeyValueArguments(template: string, keysAndValues: string): string

- - Defined in @zowe/imperative/src/utilities/src/TextUtils.ts:361

  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

- - Defined in @zowe/imperative/src/utilities/src/TextUtils.ts:50

  #### Parameters

  - ##### template: string

  - ##### values: any

  #### Returns string

### Static wordWrap

- wordWrap(text: string, width?: number, indent?: string, hardWrap?: boolean, trim?: boolean): string

- - Defined in @zowe/imperative/src/utilities/src/TextUtils.ts:239

  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