Object Functions
camel
ts
obj.camel(): objectConverts object keys to camel case and returns it. Useful when you need to pass data to JavaScript and want to convert keys before calling json function.
Input Example:
textwire
{{ { First_Name: "Serhii", LastName: "Cho" }.camel() }}Output:
json
{firstName: "Serhii", lastName: "Cho"}json
ts
obj.json(): stringConverts object to a JSON string and returns it.
Input Example:
textwire
{{ { name: "Chiori", element: "Geo" }.json() }}Output:
json
{"name":"Chiori","element":"Geo"}get
ts
obj.get(): anyget function retrieves values from the object using a dot notation. It accepts a string as an argument, which represents the path to the desired value within the object. If the specified path does not exist, it returns undefined.
Input Example:
textwire
{{ obj = { game: {genshin: {char: {name: "Chiori"}}}} }}
{{ obj.get('game.genshin.char.name') }}Output:
json
ChioriImportant Notes
- Deeply nested keys. The
getfunction is particularly useful when you need to access nested keys within an object without having to worry about whether each level of the object exists. It helps prevent errors that can occur when trying to access keys onnil. For example, if you try to accessobj.game.genshin.char.namedirectly and any of those keys (game,genshin,nameorchar) do not exist, it would throw an error. Usinggetallows you to safely retrieve the value without risking an error, as it will simply returnnilif the path does not exist. - Accessing non-valid keys. Another use-case is when you need to access a key that is not a valid identifier, like
1st,naïve,日本,na$meor even an empty string. - Keys with dot. If your key contains a dot (
.) in its name, you can access it simply by specifying the key name. Example:{{ {"x.y": "Y"}.get('x.y') }}will result inY.
