The method replaces the tag of a specified Tag object with the provided replaceValue in the given text if both values are strings.
Need to know: The return type of a generic type variable Text returns the text with not replaced tags.
Generic Type variables
Name / Description
Text extends string
A generic type variable constrained by the string by default of the value captured from the provided text parameter indicates the type of Text via the return type.
Parameters
Name: type
Description
text: Text
The text in which to replace a tag of a specified object with a given replaceValue.
replaceValue?: string
The value to replace a tag of a specified object in the given text.
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.
A generic type variable constrained by the string by default of the value captured from the provided text parameter indicates the type of Tagged via the return type.
Parameters
Name: type
Description
text: Text
The text of a string type, to be tagged with the opening and closing tag.
Returns
The return value is a new Tagged instance with a tagged text.
Example usage
Tag.prototype.valueOf()
Returns tag name, a primitive value of the specified Tag object.
Returns
The return value is a tag name of a generic type variable Name.
public getOpeningTag(): OpeningTag<Name, Chars> {
return this.tag as OpeningTag<Name, Chars>;
}
public getWrap(): Wrap<Chars> {
return this.#wrap;
}
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);
}
public tagText<Text extends string>(text: Text): Tagged<Text, Name, Chars> {
return new Tagged(
`${this.openingTag}${text}${this.closingTag}` as Text,
this
);
}
// 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."`);
public valueOf(): Name {
return super.valueOf() as Name;
}