Readonly
paramsThe template's parameters.
This property is read-only. To update it, use insertParam, updateParam, or deleteParam as per your needs.
Readonly
titleThe template's title.
This property is read-only. To update it, use setTitle.
Deletes a parameter from the template.
The parameter key to delete.
Optional
resolveHierarchy: booleanWhether to consider hierarchies when
resolving the key. If true
, this method checks the params object for any parameter whose key is
an alias of key
and deletes it if found. (Default: false
)
true
if a matching parameter was deleted; otherwise, false
.
Gets a parameter object by key.
Caution: The returned object is mutable.
The parameter key.
Optional
resolveHierarchy: booleanWhether to consider hierarchies when
searching for a matching parameter. If true
, this method first checks whether key
belongs to a hierarchy
array. If params contains a parameter with a higher-priority key in that hierarchy, that parameter
is returned instead. (Default: false
).
Example:
key = '1'
, hierarchies = [['1', 'user', 'User']]
, and params
containing a parameter keyed 'user'
,
this method returns the 'user'
parameter.If key
does not belong to any hierarchy array, the method behaves the same as when
resolveHierarchy
is false
. This also applies if no template parameter hierarchies have been provided
via the constructor or ParseTemplatesConfig.hierarchies.
The parameter object if found; otherwise, null
.
Checks if a template parameter with the specified key exists, optionally matching its value.
The parameter key to match, either as an exact string or a regular expression.
Optional
value: string | RegExpThe optional value matcher.
true
if a matching parameter exists; otherwise, false
.
Checks if a template parameter exists based on a custom predicate function.
A function that tests each parameter.
true
if a matching parameter exists; otherwise, false
.
Inserts a template parameter into the list.
By default, if the parameter is new:
position
is specified, the insertion position is controlled accordingly.If a parameter with the same key
already exists:
overwrite
is true
(default):
position
is not specified, the parameter’s value is updated in place (its position remains unchanged).position
is specified, the parameter’s value is updated and moved to the specified position.overwrite
is false
, the existing parameter is left unchanged and no insertion occurs.If parameter hierarchies are set, key
is automatically
resolved to the higher-priority key, if applicable.
Note that the order of parameters in the final output can also be controlled via stringify, using TemplateOutputConfig.sortPredicate, regardless of the insertion order tracked by this instance.
The key of the parameter. This can be an empty string for unnamed parameters.
The value of the parameter.
Optional
overwrite: booleanWhether to overwrite an existing parameter if it exists. (Default: true
)
Optional
position: { before: string } | { after: string } | "start" | "end"Where to insert or move the parameter:
'start'
: Insert at the beginning.'end'
: Insert at the end (default for new parameters).{ before: referenceKey }
: Insert before the given key.{ after: referenceKey }
: Insert after the given key.If referenceKey
does not exist:
'end'
.position
is not specified).When specifying a referenceKey
, it is best practice to verify its existence beforehand to ensure
expected behavior. See hasParam for the relevant utility.
The current instance for chaining.
Sets a new title to the instance.
The new title to set.
Optional
verbose: booleanWhether to log errors. (Default: false
)
A boolean indicating whether the new title was set.
Stringifies the instance.
Optional
options: TemplateOutputConfig<Title>Options to format the output.
The template as a string.
Updates the value of an existing parameter without changing its position.
key
exists, this method does nothing.key
is automatically
resolved to the higher-priority key, if applicable.This is functionally equivalent to calling insertParam with overwrite = true
and no position
,
except that it performs no operation if the parameter does not already exist.
Use this method when you want to safely update a parameter only if it exists, without affecting the order of parameters or accidentally inserting new ones.
The key of the parameter. This can be an empty string for unnamed parameters.
The new value of the parameter.
The current instance for chaining.
The instance members of the
Template
class. For static members, see TemplateStatic (defined separately due to TypeScript limitations).