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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wrapper.angular-package.dev/wrapper/methods/instance/wraptext.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
