# RichText

Collection of strings, `RichTextSymbol`, and `RichTextGlyph` that are rendered together. Attempts to be compatible with JavaScript's [`String`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) class.

## Constructors

RichText(args)→[RichText](https://cuttle.xyz/learn/reference/RichText)

Constructs a RichText object from strings and `RichTextSymbol`. Strings can include newlines, which are handled by the Text component. Subsequent string items will be concatenated together.

```
const rich = RichText("Before ", RichTextSymbol("https://..."), " after");
const lines = MyFont.render(rich);
// Result: Array<{ geometry: Group; advanceX: number; warning: string | undefined; }>
```

`args`

`unknown[]`

Strings, `RichTextSymbol`, and `RichTextGlyph` to be rendered together.

## Properties

.items(string | [RichTextGlyph](https://cuttle.xyz/learn/reference/RichTextGlyph) | [RichTextSymbol](https://cuttle.xyz/learn/reference/RichTextSymbol))\[\]

Array of strings, `RichTextSymbol`, and `RichTextGlyph`.

.lengthnumber

String length of all of the items, with each symbol counting as one character.

## Methods

.append(item)→[RichText](https://cuttle.xyz/learn/reference/RichText)

Append an item to the end of the items. If the item to append and the last item are both strings, they are combined.

`item`

`(string | [RichTextGlyph](https://cuttle.xyz/learn/reference/RichTextGlyph) | [RichTextSymbol](https://cuttle.xyz/learn/reference/RichTextSymbol))`

Returns this `RichText` object, with modified items.

.clone()→[RichText](https://cuttle.xyz/learn/reference/RichText)

Returns a copy of this `RichText` with all items cloned.

.canonicalize()→[RichText](https://cuttle.xyz/learn/reference/RichText)

Concatinates subsequent string items together.

Returns this `RichText` object, with modified items.

.equals(richText)→boolean

`richText`

`(string | [RichText](https://cuttle.xyz/learn/reference/RichText))`

Returns `true` if the RichText items are all equal, `false` otherwise.

.trim()→[RichText](https://cuttle.xyz/learn/reference/RichText)

First item gets leading whitespace removed. Last item gets trailing whitespace removed.

Returns a new `RichText` object, without modifying the original.

.trimStart()→[RichText](https://cuttle.xyz/learn/reference/RichText)

First item gets leading whitespace removed.

Returns a new `RichText` object, without modifying the original.

.trimEnd()→[RichText](https://cuttle.xyz/learn/reference/RichText)

Last item gets trailing whitespace removed.

Returns a new `RichText` object, without modifying the original.

.toLowerCase()→[RichText](https://cuttle.xyz/learn/reference/RichText)

Makes a clone with all string items lowercase.

Returns a new `RichText` object, without modifying the original.

.toUpperCase()→[RichText](https://cuttle.xyz/learn/reference/RichText)

Makes a clone with all string items uppercase.

Returns a new `RichText` object, without modifying the original.

.toLocaleLowerCase(locales)→[RichText](https://cuttle.xyz/learn/reference/RichText)

Makes a clone with all string items lowercase, taking into account the host environment's current locale.

`locales`

`(string | string[])`

optional

Returns a new `RichText` object, without modifying the original.

.toLocaleUpperCase(locales)→[RichText](https://cuttle.xyz/learn/reference/RichText)

Makes a clone with all string items uppercase, taking into account the host environment's current locale.

`locales`

`(string | string[])`

optional

Returns a new `RichText` object, without modifying the original.

.charCodeAt(index)→number

`index`

`number`

The zero-based index of the desired character within the items.

Returns the Unicode value of the character at the specified location. If there is no character at the specified index, NaN is returned.

.slice(start,end)→[RichText](https://cuttle.xyz/learn/reference/RichText)

Returns a portion of this RichText\`, from the start to the end index, including symbols.

`start`

`number`

`end`

`number`

optional

Returns a new `RichText` object, without modifying the original.

.substr(start,length)→[RichText](https://cuttle.xyz/learn/reference/RichText)

Returns a portion of this `RichText`, starting at the specified index and extending for a given number of characters and symbols afterwards.

`start`

`number`

`length`

`number`

optional

Returns a new `RichText` object, without modifying the original.

.charAt(index)→([RichText](https://cuttle.xyz/learn/reference/RichText) | undefined)

`index`

`number`

Returns a new `RichText` object, containing the indexed character or symbol.

.replace(searchValue,replaceValue)→[RichText](https://cuttle.xyz/learn/reference/RichText)

Replaces text in the items, using a regular expression or search string.

`searchValue`

`(string | RegExp)`

`replaceValue`

`string`

Returns a new `RichText` object, without modifying the original.

.toString()→string

Returns items joined into one string, with RichTextSymbols represented as underscore.

.split(separator)→[RichText](https://cuttle.xyz/learn/reference/RichText)\[\]

Split a `RichText` items into multiple `RichText` using the specified separator string.

`separator`

`(string | RegExp)`

Returns an array of `RichText` objects

.startsWith(searchString,position)→boolean

`searchString`

`string`

The characters to be searched for at the start of the RichText.

`position`

`number`

optional

Optional. The start position at which searchString is expected to be found (the index of searchString's first character). Defaults to 0.

Returns boolean `true` if the RichText starts with the specified string. `RichTextSymbol`s are represented as underscore.

.endsWith(searchString,position)→boolean

`searchString`

`string`

The characters to be searched for at the end of the RichText.

`position`

`number`

optional

Optional. The end position at which searchString is expected to be found (the index of searchString's last character plus 1). Defaults to this.length.

Returns boolean `true` if the RichText ends with the specified string. `RichTextSymbol`s are represented as underscore.