# Instance methods

## Public

### `Tag.prototype.getClosingTag()`

Gets the [closing tag](https://docs.angular-package.dev/text/tag/instance-accessors#closingtag) of a specified [`Tag`](https://docs.angular-package.dev/text/tag/tag) object.

```typescript
public getClosingTag(): ClosingTag<Name, Chars> {
  return this.closingTag;
}
```

#### Returns

The **return value** is the closing tag of a generic type [`ClosingTag`](https://docs.angular-package.dev/text/tag/types#closingtag).

### `Tag.prototype.getName()`

Gets the tag name without the [opening](https://docs.angular-package.dev/text/wrapper/wrap/instance-accessors#openingchar) and [closing](https://docs.angular-package.dev/text/wrapper/wrap/instance-accessors#closingchar) char.

```typescript
public getName(): Name {
  return this.#name;
}
```

#### Returns

The **return value** is the tag name of a generic type variable [`Name`](https://docs.angular-package.dev/text/tag/generic-type-variables#name).

### `Tag.prototype.getOpeningTag()`

Gets the [opening tag](https://docs.angular-package.dev/text/tag/types#openingtag) of the specified [`Tag`](https://docs.angular-package.dev/text/tag/tag) object.

```typescript
public getOpeningTag(): OpeningTag<Name, Chars> {
  return this.tag as OpeningTag<Name, Chars>;
}
```

#### Returns

The **return value** is the opening tag of a generic type [`OpeningTag`](https://docs.angular-package.dev/text/tag/types#openingtag).

### `Tag.prototype.getWrap()`

Gets the [wrap](https://docs.angular-package.dev/text/wrapper/basic-concepts#wrap) of a tag name.

```typescript
public getWrap(): Wrap<Chars> {
  return this.#wrap;
}
```

#### Returns

The **return value** is an instance of [`Wrap`](https://docs.angular-package.dev/text/wrapper/wrap).

### `Tag.prototype.replaceTag()`

The method replaces the tag of a specified [`Tag`](https://docs.angular-package.dev/text/tag/tag) object with the provided `replaceValue` in the given `text` if both values are strings.

{% hint style="warning" %}
**Need to know:** The return type of a generic type variable `Text` returns the text with not replaced tags.
{% endhint %}

```typescript
public replaceTag<Text extends string>(
  text: Text,
  replaceValue?: string
): Text {
  return guardString(text)
    ? isString(replaceValue)
      ? (text.split(this.tag).join(replaceValue) as Text)
      : text
    : ('' as Text);
}
```

#### Generic Type variables

<table><thead><tr><th>Name / Description</th><th data-hidden>Name</th></tr></thead><tbody><tr><td><p><strong><code>Text extends string</code></strong></p><p>​A generic type variable constrained by the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> by default of the value captured from the provided <code>text</code> parameter indicates the type of <code>Text</code> via the return type.</p></td><td><code>Chars</code></td></tr></tbody></table>

#### Parameters

<table><thead><tr><th width="173.44477578337126">Name: type</th><th>Description</th></tr></thead><tbody><tr><td><code>text: Text</code></td><td>The text in which to replace a tag of a specified object with a given <code>replaceValue</code>.</td></tr><tr><td><code>replaceValue?: string</code></td><td>The value to replace a tag of a specified object in the given <code>text</code>.</td></tr></tbody></table>

#### Returns

The **return value** is the given `text` of a generic type variable `Text` with a replaced tag if both the `text` and `replaceValue` are strings. If `replaceValue` is not a `string` returns not replaced `text`, and if both the `text` and `replaceValue` are not strings returns an empty `string`.

### `Tag.prototype.tagText()`

The method [tags](https://docs.angular-package.dev/text/basic-concepts#tag) the provided `text` with the [opening](https://docs.angular-package.dev/text/tag/instance-accessors#openingtag) and [closing](https://docs.angular-package.dev/text/tag/instance-accessors#openingtag) tag.

```typescript
public tagText<Text extends string>(text: Text): Tagged<Text, Name, Chars> {
  return new Tagged(
    `${this.openingTag}${text}${this.closingTag}` as Text,
    this
  );
}
```

#### Generic type variables

<table><thead><tr><th>Name / Description</th><th data-hidden>Name</th></tr></thead><tbody><tr><td><p><strong><code>Text extends string</code></strong></p><p>​A generic type variable constrained by the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"><code>string</code></a> by default of the value captured from the provided <code>text</code> parameter indicates the type of <a href="../tagged"><code>Tagged</code></a> via the return type.</p></td><td><code>Chars</code></td></tr></tbody></table>

#### Parameters

<table><thead><tr><th width="173.44477578337126">Name: type</th><th>Description</th></tr></thead><tbody><tr><td><code>text: Text</code></td><td>The text of a <code>string</code> type, to be tagged with the opening and closing tag.</td></tr></tbody></table>

#### Returns

The **return value** is a new [`Tagged`](https://docs.angular-package.dev/text/tag/tagged) instance with a tagged `text`.

#### Example usage

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

// Define the tag.
const quote = new Tag(`quote`);

// Tag the text with a `quote` tag.
// Returns Tagged {`[quote]"It's a possible."[/quote]`}
quote.tagText(`"It's a possible."`);
```

### `Tag.prototype.valueOf()`

Returns tag name, a primitive value of the specified [`Tag`](https://docs.angular-package.dev/text/tag/tag) object.

```typescript
public valueOf(): Name {
  return super.valueOf() as Name;
}
```

#### Returns

The **return value** is a tag name of a generic type variable [`Name`](https://docs.angular-package.dev/text/tag/generic-type-variables#name).
