Home > @uniformdev/canvas > parseVariableExpression
parseVariableExpression() function
Parses an expression that may contain Uniform variables and invokes a callback for each text or variable token found. The callback receives the token, its type, and offset — the index in serialized where the token's content begins. Because text tokens are always contiguous substrings of serialized, offset + token.indexOf(x) maps a position inside a text token back to the original string (which reconstructing from token lengths cannot do, since escape characters are stripped from token values).
Signature:
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
serialized |
string | |
|
onToken |
(token: string, type: 'text' | 'variable', offset: number) => void | false |
(Optional) |
Returns:
number
the number of tokens found in the string (variable or text)