map.remove()

The map.remove() function with unified map.remove() and deep-remove() returns $map without $keys.

Modified by adding deep remove on key as comma-separated list. This way of providing key is consistent with a map.set() and map.get() functions.

// Sass.
@use 'sass:list';
@use 'sass:map';
@use 'sass:meta';

// The `map.remove()` function.
@function remove($map, $keys...) {
  @each $key in $keys {
    $map: if(
      meta.type-of($key) == list and list.separator($key) == comma,
      map.deep-remove($map, $key...),
      map.remove($map, $key)
    );
  }
  @return $map;
}

Parameters

$map

A map to remove $keys from.

$keys...

Multiple keys to remove from $map. If key is a comma-separated list then map.deep-remove() function is used, otherwise map.remove().

Return

The return value is a copy of $map without any values associated with $keys.

Examples

// Use.
@use '@angular-package/sass/map';

// Examples.
$-fonts: (
  "Helvetica": (
    "weights": (
      "regular": 400,
      "medium": 500,
      "bold": 700
    )
  ),
  "regular": 400,
  "medium": 500,
  "bold": 700
);

// key - default feature `map.remove()` and `deep-remove()`.
@debug map.remove($-fonts, regular, (Helvetica, weights, medium)); // ("Helvetica": ("weights": ("regular": 400, "bold": 700)), "medium": 500, "bold": 700)

Last updated