# ★ wrap()

## `Wrapper.prototype.wrap()`

The method wraps the [primitive value](https://wrapper.angular-package.dev/wrap/methods/instance/valueof) of a specified [`Wrapper`](https://wrapper.angular-package.dev/wrapper) object by its [`opening`](https://wrapper.angular-package.dev/wrap/accessors/opening) and [`closing`](https://wrapper.angular-package.dev/wrap/accessors/closing) 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`](https://wrapper.angular-package.dev/type/wrapped#openingextendsstring) type in the generic type [`Wrapped`](https://wrapper.angular-package.dev/type/wrapped) via [return type](#undefined), by default generic type variable [`Opening`](https://wrapper.angular-package.dev/generic-type-variables#wrap-opening) of the [`Wrapper`](https://wrapper.angular-package.dev/wrapper) 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`](https://wrapper.angular-package.dev/type/wrapped#closingextendsstring) type in the generic type [`Wrapped`](https://wrapper.angular-package.dev/type/wrapped) via [return type](#undefined), by default generic type variable [`Closing`](https://wrapper.angular-package.dev/generic-type-variables#wrap-closing) of the [`Wrapper`](https://wrapper.angular-package.dev/wrapper) 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](https://wrapper.angular-package.dev/wrap/methods/instance/valueof) of the [`Wrapper`](https://wrapper.angular-package.dev/wrapper) 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](https://wrapper.angular-package.dev/wrap/methods/instance/valueof) of the [`Wrapper`](https://wrapper.angular-package.dev/wrapper) instance.

### Return type

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

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 a [primitive value](https://wrapper.angular-package.dev/wrap/methods/instance/valueof) wrapped by the [`opening`](https://wrapper.angular-package.dev/wrap/accessors/opening) and [`closing`](https://wrapper.angular-package.dev/wrap/accessors/closing) chars of the [`Wrapper`](https://wrapper.angular-package.dev/wrapper) 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: 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/wrap.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.
