map.remove-type()

The map.remove-type() function removes the properties from $map where values are of $types.

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

// The `map.remove-type()` function.
@function remove-type($map, $types...) {
  @each $type in $types {
    @if list.index(
      number string color list map calculation bool null function,
      $type
    )
    {
      @each $key, $value in $map {
        @if type-of($value) ==
          $type or
          (not $type and type-of($type) == type-of($value))
        {
          $map: map.remove($map, $key);
        }
      }
    }
  }
  @return $map;
}
https://github.com/angular-package/sass/blob/main/map/_map.remove-type.function.scss
// Sass.
@use 'sass:list';
@use 'sass:map';

// Functions.
@use '../list/list.append.function' as *;

// Status: DONE
// The`map.remove-type()` function removes the properties from `$map` where values are of `$types`.
// @param `$map` A map from which the values of type from `$types` are removed.
// @param `$type` Required type of value to remove from `$map`.
// @arbitrary `$types...` The types of values in `$map` to remove .
// @return The return value is a copy of `$map` without the values associated with `$types`.
@function remove-type($map, $type, $types...) {
  @each $type in append((), $type, comma, $types...) {
    @if list.index(number string color list map calculation bool null function, $type) {
      @each $key, $value in $map {
        @if type-of($value) == $type or (not $type and type-of($type) == type-of($value)) {
          $map: map.remove($map, $key);
        }
      }
    }
  }
  @return $map;
}

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

//   name: firstname,
//   age: 15,
//   surname: false,
//   calc: calc(15 + 5),
//   color: silver,
//   names: (no name, with name),
//   nullified: null,
//   fn: get-function(append)
// );

// Remove number.
// @debug remove-type($example-data, number); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), surname: false, color: silver, names: (no name, with name), nullified: null, fn: get-function("append"))
// @debug remove-type((a: 1, b: 2, c: 3), number); // ()

// Remove string and other types.
// @debug remove-type($example-data, string); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), "regular": 400, "medium": 500, "bold": 700, age: 15, surname: false, calc: 20, color: silver, names: (no name, with name), nullified: null, fn: get-function("append"))
// @debug remove-type($example-data, map); // ("regular": 400, "medium": 500, "bold": 700, age: 15, surname: false, calc: 20, color: silver, names: (no name, with name), nullified: null, fn: get-function("append"))
// @debug remove-type($example-data, color); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), "regular": 400, "medium": 500, "bold": 700, age: 15, surname: false, calc: 20, names: (no name, with name), nullified: null, fn: get-function("append"))
// @debug remove-type($example-data, list); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), "regular": 400, "medium": 500, "bold": 700, age: 15, surname: false, calc: 20, color: silver, nullified: null, fn: get-function("append"))
// @debug remove-type($example-data, calculation); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), "regular": 400, "medium": 500, "bold": 700, age: 15, surname: false, calc: 20, color: silver, names: (no name, with name), nullified: null, fn: get-function("append"))
// @debug remove-type($example-data, bool); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), "regular": 400, "medium": 500, "bold": 700, age: 15, calc: 20, color: silver, names: (no name, with name), nullified: null, fn: get-function("append"))
// @debug remove-type($example-data, null); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), "regular": 400, "medium": 500, "bold": 700, name: firstname, age: 15, surname: false, calc: 20, color: silver, names: (no name, with name), fn: get-function("append"))
// @debug remove-type($example-data, function); // ("Helvetica": ("weights": ("regular": 400, "medium": 500, "bold": 700)), "regular": 400, "medium": 500, "bold": 700, age: 15, surname: false, calc: 20, color: silver, names: (no name, with name), nullified: null)

// Remove string, number.
// @debug remove((a: 1, b: 2, c: 3, d: e, f: g, h: (i, j)), number, string); // (h: (i, j))

// All types.
// @debug remove-type($example-data, number, string, map, color, list, calculation, bool, null, function); // ()

Parameters

$map

A map from which the values of type from $types are removed.

$types...

The types of values in $map to remove .

Return

The return value is a copy of $map without the values associated with $types.

Examples

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

// Examples.

Last updated

Was this helpful?