> For the complete documentation index, see [llms.txt](https://docs.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://docs.angular-package.dev/text/tag/tag/instance-methods.md).

# Instance methods

## Public

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

Gets the [closing tag](/text/tag/tag/instance-accessors.md#closingtag) of a specified [`Tag`](/text/tag/tag.md) object.

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

#### Returns

The **return value** is the closing tag of a generic type [`ClosingTag`](/text/tag/tag/types.md#closingtag).

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

Gets the tag name without the [opening](/text/wrapper/wrap/instance-accessors.md#openingchar) and [closing](/text/wrapper/wrap/instance-accessors.md#closingchar) char.

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

#### Returns

The **return value** is the tag name of a generic type variable [`Name`](/text/tag/tag/generic-type-variables.md#name).

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

Gets the [opening tag](/text/tag/tag/types.md#openingtag) of the specified [`Tag`](/text/tag/tag.md) 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`](/text/tag/tag/types.md#openingtag).

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

Gets the [wrap](/text/wrapper/basic-concepts.md#wrap) of a tag name.

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

#### Returns

The **return value** is an instance of [`Wrap`](/text/wrapper/wrap.md).

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

The method replaces the tag of a specified [`Tag`](/text/tag/tag.md) 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](/text/tag/basic-concepts.md#tag) the provided `text` with the [opening](/text/tag/tag/instance-accessors.md#openingtag) and [closing](/text/tag/tag/instance-accessors.md#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="/pages/KzuktBfAn9cEOQzMF5JO"><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`](/text/tag/tagged.md) 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`](/text/tag/tag.md) object.

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

#### Returns

The **return value** is a tag name of a generic type variable [`Name`](/text/tag/tag/generic-type-variables.md#name).


---

# 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://docs.angular-package.dev/text/tag/tag/instance-methods.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.
