> 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/wrap.md).

# ★ wrap()

## `Wrapper.prototype.wrap()`

The method wraps the [primitive value](/wrap/methods/instance/valueof.md) of a specified [`Wrapper`](/wrapper/overview.md) object by its [`opening`](/wrap/accessors/opening.md) and [`closing`](/wrap/accessors/closing.md) chars, or the given [`opening`](#opening-customopening) and [`closing`](#closing-customclosing) chars.

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

```typescript
public wrap<
  CustomOpening extends string = Opening,
  CustomClosing extends string = Closing
>(
  opening: CustomOpening = this.opening as any,
  closing: CustomClosing = this.closing as any
): Wrapped<CustomOpening, Wrapped<Opening, Text, Closing>, CustomClosing> {
  return new Wrap(opening, closing, this.valueOf()).valueOf();
}
```

{% endcode %}

### Generic type variables

#### <mark style="color:green;">`CustomOpening`</mark>`extends`<mark style="color:green;">`string`</mark>`=`<mark style="color:green;">`Opening`</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-customopening) parameter and the [`Opening`](/type/wrapped.md#openingextendsstring) type in the generic type [`Wrapped`](/type/wrapped.md) via [return type](#undefined), by default generic type variable [`Opening`](/wrapper/generic-type-variables.md#wrap-opening) of the [`Wrapper`](/wrapper/overview.md) object.

#### <mark style="color:green;">`CustomClosing`</mark>`extends`<mark style="color:green;">`string`</mark>`=`<mark style="color:green;">`Closing`</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-customclosing) parameter and the [`Closing`](/type/wrapped.md#closingextendsstring) type in the generic type [`Wrapped`](/type/wrapped.md) via [return type](#undefined), by default generic type variable [`Closing`](/wrapper/generic-type-variables.md#wrap-closing) of the [`Wrapper`](/wrapper/overview.md) object.

### Parameters

#### `opening:`[<mark style="color:green;">`CustomOpening`</mark>](#customopeningextendsstring-opening)

Optional opening chars of a generic type variable [`CustomOpening`](#customopeningextendsstring-opening) to wrap the [primitive value](/wrap/methods/instance/valueof.md) of the [`Wrapper`](/wrapper/overview.md) instance.

#### `closing:`[<mark style="color:green;">`CustomClosing`</mark>](#customclosingextendsstring-closing)

Optional closing chars of a generic type variable [`CustomClosing`](#customclosingextendsstring-closing) to wrap the [primitive value](/wrap/methods/instance/valueof.md) of the [`Wrapper`](/wrapper/overview.md) instance.

### Return type

#### `Wrapped<CustomOpening, Wrapped<Opening, Text, Closing>, CustomClosing>`&#x20;

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 a [primitive value](/wrap/methods/instance/valueof.md) wrapped by the [`opening`](/wrap/accessors/opening.md) and [`closing`](/wrap/accessors/closing.md) chars of the [`Wrapper`](/wrapper/overview.md) instance or the given [`opening`](#opening-customopening) and [`closing`](#closing-customclosing) chars.

## 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}}}.
longText.wrap();

// Returns {{This is a long text}}.
longText.wrap('', '');
```


---

# 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
