map.update()
Last updated
Was this helpful?
Last updated
Was this helpful?
The map.update()
function allows to set multiple key-value sets in a $map
.
// Functions.
@use 'map.set.function';
// The `map.update()` function.
@function update($map, $key-value, $allowed...) {
@each $key, $value in $key-value {
$map: map.set($map, $key, $value, $allowed...);
}
@return $map;
}
$map
A map to update by multiple sets $key-value
.
$key-value
A map of (key: value) to update the $map
.
$allowed...
Allowed value types and/or values to update $map
.
The return value is $map
with updated multiple sets.
// Use.
@use '@angular-package/sass/map';
// Examples.
$-fonts: (
"Helvetica": (
"weights": (
"regular": 400,
"medium": 500,
"bold": 700
)
)
);
// update single nested key-value
@debug map.update($-fonts, ((("Helvetica", "style"), ): (italic: italic, normal: normal, inherit: inherit))); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), ("Helvetica", "style"): (italic: italic, normal: normal, inherit: inherit))
// update multiple keys
@debug map.update($-fonts, (arial: (size: large), georgia: (size: small), verdana: (size: medium))); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), arial: (size: large), georgia: (size: small), verdana: (size: medium))
// update multiple list keys
@debug map.update($-fonts, ((arial large,): (size: large), (georgia small,): (size: small), (verdana medium,): (size: medium))); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), arial large: (size: large), georgia small: (size: small), verdana medium: (size: medium))
// update only string type
@debug map.update($-fonts, (small: 2px, medium: md, large: 3px), string); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), medium: md)
// update only string type
@debug map.update($-fonts, (small: 2px, medium: md, large: 3px), string, number); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), small: 2px, medium: md, large: 3px)
// update specified value
@debug map.update($-fonts, (small: 2px, medium: md, large: 3px), 3px); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), large: 3px)
// Functions.
@use 'map.set.function';
// Status: DONE
// The `map.update()` function allows to set multiple key-value sets in a `$map`.
// @param `$map` A map to update by multiple sets `$key-value`.
// @param `$key-value` A map of (key: value) to update `$map`.
// @arbitrary `$allowed...` Allowed value types and/or values to update the `$map`.
// @return The return value is `$map` with updated multiple sets.
@function update($map, $key-value, $allowed...) {
@each $key, $value in $key-value {
$map: map.set($map, $key, $value, $allowed...);
}
@return $map;
}
// Examples.
// $-fonts: (
// "Helvetica": (
// "weights": (
// "regular": 400,
// "medium": 500,
// "bold": 700
// )
// )
// );
// update single nested key-value
// @debug update($-fonts, ((("Helvetica", "style"), ): (italic: italic, normal: normal, inherit: inherit))); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), ("Helvetica", "style"): (italic: italic, normal: normal, inherit: inherit))
// update multiple keys
// @debug update($-fonts, (arial: (size: large), georgia: (size: small), verdana: (size: medium))); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), arial: (size: large), georgia: (size: small), verdana: (size: medium))
// update multiple list keys
// @debug update($-fonts, ((arial large,): (size: large), (georgia small,): (size: small), (verdana medium,): (size: medium))); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), arial large: (size: large), georgia small: (size: small), verdana medium: (size: medium))
// update only string type
// @debug update($-fonts, (small: 2px, medium: md, large: 3px), string); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), medium: md)
// update only string type
// @debug update($-fonts, (small: 2px, medium: md, large: 3px), string, number); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), small: 2px, medium: md, large: 3px)
// update specified value
// @debug update($-fonts, (small: 2px, medium: md, large: 3px), 3px); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), large: 3px)