map.update()

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;
}

Parameters

$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.

Return

The return value is $map with updated multiple sets.

Examples

// 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)

Last updated