iniquity

A re-imagining of the iconic BBS software.

View on GitHub

Class: IQText

text.IQText

IQText class for advanced text manipulation

Table of contents

Constructors

Accessors

Methods

Constructors

constructor

new IQText(content?, width?)

Parameters

Name Type Default value
content string ""
width number 80

Defined in

core/src/text.ts:83

Accessors

visibleLength

get visibleLength(): number

Get visible length (excluding ANSI codes)

Returns

number

Defined in

core/src/text.ts:98

Methods

append

append(content): IQText

Append content

Parameters

Name Type
content string

Returns

IQText

Defined in

core/src/text.ts:113


box

box(options): IQText

Create a text box

Parameters

Name Type
options ITextBoxOptions

Returns

IQText

Defined in

core/src/text.ts:301


center

center(width?): IQText

Center text

Parameters

Name Type
width? number

Returns

IQText

Defined in

core/src/text.ts:137


color

color(color): IQText

Apply color

Parameters

Name Type
color string

Returns

IQText

Defined in

core/src/text.ts:129


left

left(width?): IQText

Left align text

Parameters

Name Type
width? number

Returns

IQText

Defined in

core/src/text.ts:150


lower

lower(): IQText

Convert to lowercase

Returns

IQText

Defined in

core/src/text.ts:224


newlines

newlines(count?, position?): IQText

Add newlines

Parameters

Name Type Default value
count number 1
position "both" | "before" | "after" "after"

Returns

IQText

Defined in

core/src/text.ts:248


pad

pad(length, char?, side?): IQText

Pad text

Parameters

Name Type Default value
length number undefined
char string " "
side "left" | "right" | "both" "right"

Returns

IQText

Defined in

core/src/text.ts:186


prepend

prepend(content): IQText

Prepend content

Parameters

Name Type
content string

Returns

IQText

Defined in

core/src/text.ts:121


repeat

repeat(count): IQText

Repeat text

Parameters

Name Type
count number

Returns

IQText

Defined in

core/src/text.ts:208


reverse

reverse(): IQText

Reverse text

Returns

IQText

Defined in

core/src/text.ts:240


right(width?): IQText

Right align text

Parameters

Name Type
width? number

Returns

IQText

Defined in

core/src/text.ts:162


set

set(content): IQText

Set content

Parameters

Name Type
content string

Returns

IQText

Defined in

core/src/text.ts:105


title

title(): IQText

Title case

Returns

IQText

Defined in

core/src/text.ts:232


toString

toString(): string

Get the text content

Returns

string

Defined in

core/src/text.ts:91


truncate

truncate(maxLength, suffix?): IQText

Truncate text

Parameters

Name Type Default value
maxLength number undefined
suffix string "..."

Returns

IQText

Defined in

core/src/text.ts:174


upper

upper(): IQText

Convert to uppercase

Returns

IQText

Defined in

core/src/text.ts:216


wrap

wrap(options): IQText

Word wrap text

Parameters

Name Type
options ITextWrapOptions

Returns

IQText

Defined in

core/src/text.ts:265


center

Static center(text, width): string

Center text within width

Parameters

Name Type
text string
width number

Returns

string

Defined in

core/src/text.ts:396


formatBytes

Static formatBytes(bytes, decimals?): string

Format bytes to human readable

Parameters

Name Type Default value
bytes number undefined
decimals number 2

Returns

string

Defined in

core/src/text.ts:564


formatDate

Static formatDate(date, format?): string

Format date

Parameters

Name Type Default value
date string | Date undefined
format string "YYYY-MM-DD"

Returns

string

Defined in

core/src/text.ts:600


formatDuration

Static formatDuration(seconds): string

Format duration to human readable

Parameters

Name Type
seconds number

Returns

string

Defined in

core/src/text.ts:577


formatNumber

Static formatNumber(num, separator?): string

Format number with thousands separator

Parameters

Name Type Default value
num number undefined
separator string ","

Returns

string

Defined in

core/src/text.ts:593


left

Static left(text, width): string

Left align text within width

Parameters

Name Type
text string
width number

Returns

string

Defined in

core/src/text.ts:417


line

Static line(width, char?, color?): string

Create horizontal line

Parameters

Name Type Default value
width number undefined
char string "─"
color? string undefined

Returns

string

Defined in

core/src/text.ts:371


progressBar

Static progressBar(current, total, width?, options?): string

Create a progress bar

Parameters

Name Type Default value
current number undefined
total number undefined
width number 20
options? Object undefined
options.empty? string undefined
options.emptyColor? string undefined
options.filled? string undefined
options.filledColor? string undefined
options.leftCap? string undefined
options.rightCap? string undefined
options.showPercent? boolean undefined

Returns

string

Defined in

core/src/text.ts:462


right

Static right(text, width): string

Right align text within width

Parameters

Name Type
text string
width number

Returns

string

Defined in

core/src/text.ts:407


stripAnsi

Static stripAnsi(text): string

Strip ANSI codes from text

Parameters

Name Type
text string

Returns

string

Defined in

core/src/text.ts:382


table

Static table(headers, rows, options?): string

Create a table

Parameters

Name Type
headers string[]
rows string[][]
options? Object
options.border? "ascii" | "none" | "single" | "double"
options.cellPadding? number
options.columnWidths? number[]
options.headerColor? string

Returns

string

Defined in

core/src/text.ts:505


truncate

Static truncate(text, maxLength, suffix?): string

Truncate text to max length

Parameters

Name Type Default value
text string undefined
maxLength number undefined
suffix string "..."

Returns

string

Defined in

core/src/text.ts:427


visibleLength

Static visibleLength(text): number

Get visible length of text (excluding ANSI codes)

Parameters

Name Type
text string

Returns

number

Defined in

core/src/text.ts:389


wrap

Static wrap(text, width): string[]

Word wrap text to width

Parameters

Name Type
text string
width number

Returns

string[]

Defined in

core/src/text.ts:437