/utils/keyvalue_dictionary
The keyvalue_dictionary utility method will parse a JSON object for properties with key/value pairs matching entries a provided dictionary.
The property value will be replaced with a language lookup in the dictionary or the default value.
"keyvalue_dictionary": [
{
"key": "name",
"value": "OSM",
"default": "OpenStreetMap",
"uk": "Sława OpenStreetMap 🇺🇦"
}
]
Methods
(inner) isArrayObject(item, dictionary) → {boolean}
Checks if an item is an array or an object and recursively applies the parsing logic.
Name | Type | Description |
---|---|---|
item | * | The item to check. |
dictionary | Array | An array of dictionary entries. |
Returns true if the item is an array or an object, false otherwise.
- Type:
- boolean
(inner) keyvalue_dictionary(obj)
Replaces key-value pairs in an object with dictionary entries.
Name | Type | Description |
---|---|---|
obj | Object | The object to be mapped to keyvalue_dictionary. |
(inner) parseObject(obj, dictionary)
Parses an object and replaces its string values with dictionary entries.
Name | Type | Description |
---|---|---|
obj | Object | The object to parse. |
dictionary | Array | An array of dictionary entries. |
(inner) replaceKeyValue(obj, key, value, dictionary)
Replaces a key-value pair in an object with a dictionary entry.
Name | Type | Description |
---|---|---|
obj | Object | The object containing the key-value pair. |
key | string | The key of the value to replace. |
value | string | The value to replace. |
dictionary | Array | An array of dictionary entries. |