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