# ★ wrapText()

## `Wrapper.prototype.wrapText()`

The method returns the [primitive value](https://wrapper.angular-package.dev/wrap/methods/instance/valueof) of the [`Wrapper`](https://wrapper.angular-package.dev/wrapper) object with [`text`](https://wrapper.angular-package.dev/wrap/accessors/text) 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`](https://wrapper.angular-package.dev/type/wrapped#openingextendsstring) type in the generic type [`Wrapped`](https://wrapper.angular-package.dev/type/wrapped) 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`](https://wrapper.angular-package.dev/type/wrapped#closingextendsstring) type in the generic type [`Wrapped`](https://wrapper.angular-package.dev/type/wrapped) 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`](https://wrapper.angular-package.dev/wrap/accessors/text) of the [`Wrapper`](https://wrapper.angular-package.dev/wrapper) instance.

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

The closing chars of a generic type variable [`TextClosing`](#textclosingextendsstring) to wrap the [`text`](https://wrapper.angular-package.dev/wrap/accessors/text) of the [`Wrapper`](https://wrapper.angular-package.dev/wrapper) instance.

### Return type

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

The return type is the generic type [`Wrapped`](https://wrapper.angular-package.dev/type/wrapped) that takes generic type variables [`Opening`](https://wrapper.angular-package.dev/type/wrapped#openingextendsstring), [`Text`](https://wrapper.angular-package.dev/type/wrapped#textextendsstring) and [`Closing`](https://wrapper.angular-package.dev/type/wrapped#closingextendsstring).

### Returns

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

## 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('<', '>');
```
