Instance methods

Public

Variable.prototype.getValue()

Gets the value of the variable by returning the private #value property of a specified Variable object.

variable.class.ts
public getValue(): Value | undefined {
  return this.#value;
}

Returns

The return value is the value of a generic type variable Value if set, otherwise undefined.

Example usage

// Example usage.
import { Variable } from '@angular-package/text';

// Returns Variable {'{fix}'} of Variable<"fix", string>.
const fix = new Variable('fix');

// Returns undefined of string | undefined.
fix.getValue();

// Returns Variable {'{fix}'} of Variable<"fix", "Open the link https://duckduckgo.com/">.
const fixed = new Variable('fix', 'Open the link https://duckduckgo.com/');

// Returns Open the link https://duckduckgo.com/ of "Open the link https://duckduckgo.com/" | undefined.
fixed.getValue();

Variable.prototype.replaceVariable()

Replaces variable in the format {variable name} with the value of a specified Variable object or with a provided replaceValue, in a given text.

circle-info

If replaceValue is not provided, ​private #value property is used, and if the #value is undefined an empty string is used.

Generic type variables

ReplaceValue extends Value ​A generic type variable ReplaceValue constrained by a generic type variable Value, by default of the value captured from the provided replaceValue indicates replacement value type.

Parameters

Name: type
Description

text: string

The text of a string type in which replace the variable with the value from the private #value property or a given replaceValue.

replaceValue?: ReplaceValue

Optional value of a generic type variable ReplaceValue to replace the variable in the form {variable name} in a given text.

Returns

The return value is the text of a string type with a replaced variable by value.

Example usage

Variable.prototype.toArray()

Returns converted variable to a read-only array where the first element is the name, and the second is the value if set, otherwise undefined.

Returns

The return value is a read-only array of the variable name and value.

Example usage

Variable.prototype.toObject()

Returns converted variable to a read-only object where the key is the variable name.

Returns

The return value is a read-only object where the property name is the variable name, and the property value is equal to the variable value.

Example usage

Variable.prototype.toString()

Returns the variable in form {name}, a primitive value of the specified Variable object.

Returns

The return value is the variable of a generic type variable Name on the template {${Name}}.

Example usage

Variable.prototype.valueOf()

Returns the variable in form {name}, a primitive value of the specified Variable object.

Returns

The return value is the variable of a generic type variable Name on the template {${Name}}.

Example usage

Last updated