Members
# (constant) assembleMethodSymbol :symbol
Type:
- symbol
# (constant) initMethodSymbol :symbol
Type:
- symbol
# (constant) Monster :Namespace
Type:
- Namespace
Methods
# buildMap(subject, selector, valuePath, keyPath, filter) → {*}
With the help of the function buildMap()
, maps can be easily created from data objects.
Either a simple definition a.b.c
or a template ${a.b.c}
can be specified as the path.
Key and value can be either a definition or a template. The key does not have to be defined.
You can call the method via the monster namespace Monster.Data.buildMap()
.
<script type="module">
import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@/dist/modules/data/buildmap.js';
console.log(Monster.Data.buildMap())
</script>
Alternatively, you can also integrate this function individually.
<script type="module">
import {buildMap} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@/dist/modules/types/buildmap.js';
console.log(buildMap())
</script>
Parameters:
Name | Type | Description |
---|---|---|
subject |
* | |
selector |
string | |
valuePath |
string | undefined | |
keyPath |
string | undefined | |
filter |
function | undefined |
Returns:
- Type
- *
Example
// a typical data structure as reported by an api
let map;
let obj = {
"data": [
{
"id": 10,
"name": "Cassandra",
"address": {
"street": "493-4105 Vulputate Street",
"city": "Saumur",
"zip": "52628"
}
},
{
"id": 20,
"name": "Holly",
"address": {
"street": "1762 Eget Rd.",
"city": "Schwalbach",
"zip": "952340"
}
},
{
"id": 30,
"name": "Guy",
"address": {
"street": "957-388 Sollicitudin Avenue",
"city": "Panchià",
"zip": "420729"
}
}
]
};
// The function is passed this data structure and with the help of the selector `'data.*'` the data to be considered are selected.
// The key is given by a simple definition `'id'` and the value is given by a template `'${name} (${address.zip} ${address.city})'`.
map = buildMap(obj, 'data.*', '${name} (${address.zip} ${address.city})', 'id');
console.log(map);
// ↦ Map(3) {
// '10' => 'Cassandra (52628 Saumur)',
// '20' => 'Holly (952340 Schwalbach)',
// '30' => 'Guy (420729 Panchià)'
// }
// If no key is specified, the key from the selection, here the array index, is taken.
map = buildMap(obj, 'data.*', '${name} (${address.zip} ${address.city})');
console.log(map);
// ↦ Map(3) {
// '0' => 'Cassandra (52628 Saumur)',
// '1' => 'Holly (952340 Schwalbach)',
// '2' => 'Guy (420729 Panchià)'
// }
// a filter (function(value, key) {}) can be specified to accept only defined entries.
map = buildMap(obj, 'data.*', '${name} (${address.zip} ${address.city})', 'id', function (value, key) {
return (value['id'] >= 20) ? true : false
});
console.log(map);
// ↦ Map(2) {
// 20 => 'Holly (952340 Schwalbach)',
// 30 => 'Guy (420729 Panchià)'
// }
# getDocumentTheme() → {Theme}
The theming used in the document can be defined via the html-tag.
The theming is specified via the attribute data-monster-theme-name
.
As name for a theme all characters are valid, which are also allowed for a HTMLElement-ID.
<html data-monster-theme-name="my-theme">
the default theme name is monster
.
- Since:
- 1.7.0
Returns:
- Type
- Theme