Skip to content
v2.274.0

Token Class ​

Represents a special or lazily-evaluated value.

Can be used to delay evaluation of a certain value in case, for example, that it requires some context or late-bound data. Can also be used to mark values that need special processing at document rendering time.

Tokens can be embedded into strings while retaining their original semantics.

Methods ​

asAny(value: any): IResolvable@staticmethod def as_any(value: Any) -> IResolvablepublic static IResolvable asAny(Object value)public static IResolvable AsAny(object value)func AsAny(Value interface{}) IResolvablestatic#
Return a resolvable representation of the given value.
asList(value: any, options?: EncodingOptions): string[]@staticmethod def as_list(value: Any, options: typing.Optional[EncodingOptions] = None) -> typing.List[str]public static List<String> asList(Object value, EncodingOptions options)public static string[] AsList(object value, EncodingOptions? options = null)func AsList(Value interface{}, Options EncodingOptions) *[]*stringstatic#
Return a reversible list representation of this token.
asNumber(value: any): number@staticmethod def as_number(value: Any) -> int | floatpublic static Number asNumber(Object value)public static double AsNumber(object value)func AsNumber(Value interface{}) *float64static#
Return a reversible number representation of this token.
asString(value: any, options?: EncodingOptions): string@staticmethod def as_string(value: Any, options: typing.Optional[EncodingOptions] = None) -> strpublic static String asString(Object value, EncodingOptions options)public static string AsString(object value, EncodingOptions? options = null)func AsString(Value interface{}, Options EncodingOptions) *stringstatic#
Return a reversible string representation of this token.
notes

If the Token is initialized with a literal, the stringified value of the literal is returned. Otherwise, a special quoted string representation of the Token is returned that can be embedded into other strings.

Strings with quoted Tokens in them can be restored back into complex values with the Tokens restored by calling resolve() on the string.

compareStrings(possibleToken1: string, possibleToken2: string): TokenComparison@staticmethod def compare_strings(possible_token1: str, possible_token2: str) -> TokenComparisonpublic static TokenComparison compareStrings(String possibleToken1, String possibleToken2)public static TokenComparison CompareStrings(string possibleToken1, string possibleToken2)func CompareStrings(PossibleToken1 *string, PossibleToken2 *string) TokenComparisonstatic#
Compare two strings that might contain Tokens with each other.
isResolved(obj: any): boolean@staticmethod def is_resolved(obj: Any) -> boolpublic static Boolean isResolved(Object obj)public static bool IsResolved(object obj)func IsResolved(Obj interface{}) *boolstatic#
The negation of `Token.isUnresolved()`. In TypeScript, narrows the type to exclude `IResolvable`.
1 parameter

Parameters

  • objobjobjobjObj — The object to test.
isUnresolved(obj: any): boolean@staticmethod def is_unresolved(obj: Any) -> boolpublic static Boolean isUnresolved(Object obj)public static bool IsUnresolved(object obj)func IsUnresolved(Obj interface{}) *boolstatic#
Returns true if obj represents an unresolved value.
notes · 1 parameter

One of these must be true:

  • obj is an IResolvable
  • obj is a string containing at least one encoded IResolvable
  • obj is either an encoded number or list

This does NOT recurse into lists or objects to see if they contain resolvables.

Parameters

  • objobjobjobjObj — The object to test.