Question

I wish to know how to write dust tags for keys containing spaces in linkedIn's Dustjs, or if it is even possible to do so.

According to this Dust Tutorial the format of a dust tag should be {xxxxxx}, but I haven't found any information on what defines a valid x.

Example JSON:

{
    "street address": "North pole 1"
}

Failed attempts:

template = '{street address}';
template = '{street\\ address}';
template = '{"street address"}';
template = '{[street address]};
template = '{["street address"]};

Of course I know that I can just call it streetAddress and be done with it. But what I need to know is if I need to add certain restrictions on user-defined key names.

Follow-up question

If it is not possible to have space, what characters are allowed?

Was it helpful?

Solution

Spaces are not allowed for keys in Dust. A Dust key1 must start with a letter from a - z (upper or lower case), an underscore, or a $, followed 0 or more characters in the set a - z (upper or lower case), 0 - 9, underscore, $, -.

It may be more clear as a regular expression:

/[a-zA-Z_$]{1}[0-9a-zA-Z_$\-]*/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top