# Static methods

## Public

### `Wrap.isWrap()`

The method checks if the value of any type is the [`Wrap`](https://docs.angular-package.dev/text/wrapper/wrap) instance of any or given opening and closing.

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

```typescript
public static isWrap<Opening extends string, Closing extends string>(
  value: any,
  opening?: Opening,
  closing?: Closing
): value is Wrap<Opening, Closing> {
  return isInstance(value, Wrap)
    ? isStringType(opening) && isStringType(closing)
      ? opening === value.opening && closing === value.closing
      : isStringType(opening)
      ? opening === value.opening
      : isStringType(closing)
      ? closing === value.closing
      : true
    : false;
}
```

{% endcode %}

| Generic type variables                                                                                                                                                                                                                                                                                                                                                                                  |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong><code>Opening extends string</code></strong></p><p>A generic type variable constrained by the <a href="https://www.typescriptlang.org/docs/handbook/basic-types.html#string"><code>string</code></a>, by default of the value captured from the provided <code>wrap</code> indicates the <code>Opening</code> type of the <a href=""><code>Wrap</code></a> instance via the return type.</p> |
| <p><strong><code>Closing extends string</code></strong></p><p>A generic type variable constrained by the <a href="https://www.typescriptlang.org/docs/handbook/basic-types.html#string"><code>string</code></a>, by default of the value captured from the provided <code>wrap</code> indicates the <code>Closing</code> type of the <a href=""><code>Wrap</code></a> instance via the return type.</p> |

#### Parameters

| Name: type          | Description                                                                                    |
| ------------------- | ---------------------------------------------------------------------------------------------- |
| `value: any`        | The value of any type to test against the `Wrap` instance of any or given opening and closing. |
| `opening?: Opening` | An optional wrap opening to check if the given `value` contains.                               |
| `closing?: Closing` | An optional wrap closing to check if the given `value` contains.                               |

#### Returns

| Return type                                                                                                                                                                                                                                                                                            |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><strong><code>value is Wrap\<Opening, Closing></code></strong></p><p>The return type is a <code>boolean</code> indicating the <code>value</code> parameter is an instance of <a href=""><code>Wrap</code></a> that takes a generic type variable <code>Opening</code> and <code>Closing</code>.</p> |

The **return value** is a [`boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) type indicating whether the value is an instance of `Wrap` of any or given opening and closing.

#### Example usage

```typescript
// Example usage.
import { Wrap } from '@angular-package/text';

const tagWrap = new Wrap(`[`, `]`);

// Returns true confirming the type Wrap<string, string>
Wrap.isWrap(tagWrap);

// Returns true confirming the type Wrap<"[", "]">
Wrap.isWrap(tagWrap, ['[', ']']);

// Returns true confirming the type Wrap<"[", "]">
Wrap.isWrap<'[', ']'>(tagWrap, ['[', ']']);

// Returns false by denying the value is Wrap<"(", ")">
Wrap.isWrap(tagWrap, ['(', ')']);

// Returns false by denying the value is Wrap<"[", "]">
Wrap.isWrap<'[', ']'>(null as any);

// Returns false by denying the value is Wrap<"[", "]">
Wrap.isWrap(null as any, ['[', ']']);
```

### `Wrap.template()`

The static "tag" method builds the wrap of a [`string`](https://www.typescriptlang.org/docs/handbook/basic-types.html#string) type on the template. With the added string before the expressions, it returns a wrapped string.

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

```typescript
public static template(
  template: TemplateStringsArray,
  ...values: string[]
): string {
  let opening, closing;
  if (areString(...values).every()) {
    return (
      ([opening, closing] = values), `${opening}${template[0]}${closing}`
    );
  }
  return ``;
}
```

{% endcode %}

#### Parameters

| Name: type                       | Description                                                                                                                                                                                                                                        |
| -------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `template: TemplateStringsArray` | An `array` of `string` values where the first element is a text between [opening](https://docs.angular-package.dev/text/basic-concepts#opening) and [closing](https://docs.angular-package.dev/text/basic-concepts#closing).                       |
| `...values: string[]`            | A rest parameter of expressions, where the first element is the [opening](https://docs.angular-package.dev/text/basic-concepts#opening) and the second is the [closing](https://docs.angular-package.dev/text/basic-concepts#closing) of the wrap. |

#### Returns

The **return value** is a [`string`](https://www.typescriptlang.org/docs/handbook/basic-types.html#string) the wrap, or an empty `string` if elements of the provided `values` are not `string`.

#### Example usage

```typescript
import { Wrap } from '@angular-package/text';

// Returns {{inside}}
Wrap.template`inside${'{{'}${'}}'}`;
```
