map.key-replace()
The map.key-replace() function returns the map with key $replace replaced by $replacement.
// Sass.
@use 'sass:map';
// Functions.
@use '../string';
// The `map.key-replace()` function.
@function key-replace($map, $replace, $replacement) {
@if type-of($map) == map {
@each $key, $value in $map {
$map: map.remove($map, $key);
@if type-of($key) ==
string and
type-of($replace) ==
string and
type-of($replacement) ==
string
{
@if string.index($key, $replace) {
$key: string.replace($key, first, $replace, $replacement);
}
} @else if $key == $replace {
$key: $replacement;
}
$map: map.merge(
$map,
(
$key: $value,
)
);
}
}
@return $map;
}https://github.com/angular-package/sass/blob/main/map/_map.key-replace.function.scss
Parameters
$map
$mapA map in which a $replace key is replaced with $replacement.
$replace
$replaceA key, or if string substring to replace with $replacement in $map.
$replacement
$replacementThe value to replace a $replace key in $map.
Return
The return value is a $map with replaced key $replace by $replacement.
Examples
Last updated
Was this helpful?