> For the complete documentation index, see [llms.txt](https://wrapper.angular-package.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wrapper.angular-package.dev/wrapper/methods/instance/wraptext.md).

# ★ wrapText()

## `Wrapper.prototype.wrapText()`

The method returns the [primitive value](/wrap/methods/instance/valueof.md) of the [`Wrapper`](/wrapper/overview.md) object with [`text`](/wrap/accessors/text.md) wrapped by given [`opening`](#opening-textopening) and [`closing`](#closing-textclosing) chars.

{% code title="wrapper.class.ts" %}

```typescript
public wrapText<
  TextOpening extends string = '',
  TextClosing extends string = ''
>(
  opening: TextOpening,
  closing: TextClosing
): Wrapped<Opening, Wrapped<TextOpening, Text, TextClosing>, Closing> {
  return `${this.opening}${this.textWrap(opening, closing)}${this.closing}`;
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`TextOpening`</mark>`extends`<mark style="color:green;">`string`</mark>`=`<mark style="color:green;">`''`</mark>

A generic type variable constrained by the [`string`](https://www.typescriptlang.org/docs/handbook/basic-types.html#string) indicates the captured type of the supplied [`opening`](#opening-textopening) parameter and the [`Opening`](/type/wrapped.md#openingextendsstring) type in the generic type [`Wrapped`](/type/wrapped.md) via [return type](#return-type), by default an empty [`string`](https://www.typescriptlang.org/docs/handbook/basic-types.html#string).

#### <mark style="color:green;">`TextClosing`</mark>`extends`<mark style="color:green;">`string`</mark>`=`<mark style="color:green;">`''`</mark>

A generic type variable constrained by the [`string`](https://www.typescriptlang.org/docs/handbook/basic-types.html#string) indicates the captured type of the supplied [`closing`](#closing-textclosing) parameter and the [`Closing`](/type/wrapped.md#closingextendsstring) type in the generic type [`Wrapped`](/type/wrapped.md) via [return type](#return-type), by default an empty [`string`](https://www.typescriptlang.org/docs/handbook/basic-types.html#string).

### Parameters

#### `opening:`[<mark style="color:green;">`TextOpening`</mark>](#textopeningextendsstring)

The opening chars of a generic type variable [`TextOpening`](#textopeningextendsstring) to wrap the [`text`](/wrap/accessors/text.md) of the [`Wrapper`](/wrapper/overview.md) instance.

#### `closing:`[<mark style="color:green;">`TextClosing`</mark>](#textclosingextendsstring)

The closing chars of a generic type variable [`TextClosing`](#textclosingextendsstring) to wrap the [`text`](/wrap/accessors/text.md) of the [`Wrapper`](/wrapper/overview.md) instance.

### Return type

#### `Wrapped<Opening, Wrapped<TextOpening, Text, TextClosing>, Closing>`

The return type is the generic type [`Wrapped`](/type/wrapped.md) that takes generic type variables [`Opening`](/type/wrapped.md#openingextendsstring), [`Text`](/type/wrapped.md#textextendsstring) and [`Closing`](/type/wrapped.md#closingextendsstring).

### Returns

The **return value** is the [primitive value](/wrap/methods/instance/valueof.md) with [`text`](/wrap/accessors/text.md) wrapped by given [`opening`](#opening-textopening) and [`closing`](#closing-textclosing) characters of generic type [`Wrapped`](/type/wrapped.md).

## Example usage

```typescript
// Example usage.
import { Wrapper } from '@angular-package/wrapper';

const longText = new Wrapper('{', '}', '{This is a long text}');

// Returns {{{This is a long text}}} of "{{{This is a long text}}}".
longText.wrapText('{', '}');

// Returns {<{This is a long text}>} of "{<{This is a long text}>}".
longText.wrapText('<', '>');
```
