map.values()

The modified map.values() function returns all values or values of $keys from $map.

The modified map.values() function, by adding arbitrary parameter $keys... to return values of the specified keys.

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

// The `map.values()` function.
@function values($map, $keys...) {
  @if list.length($keys) > 0 {
    @for $i from 1 through list.length($keys) {
      $keys: if(
        map.has-key($map, list.nth($keys, $i)),
        list.set-nth($keys, $i, map.get($map, list.nth($keys, $i))),
        $keys
      );
    }
  } @else {
    $keys: map.values($map);
  }
  @return $keys;
}

Parameters

$map

A map from which all values or values of $keys are returned.

$keys...

The keys to retrieve values from $map.

Return

The return value is a comma-separated list of values retrieved from $map.

Examples

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

// Examples.
// key string
@debug map.values((a: 1, b: 2, c: 3), 'a', 'b', 'c'); // (1, 2, 3)

// different map order
@debug map.values((b: 2, a: 1, c: 3), 'a', 'b', 'c'); // (1, 2, 3)

// different map order + keys
@debug map.values((b: 2, a: 1, c: 3), 'c', 'b', 'a'); // (3, 2, 1)
@debug map.values((a: 1, b: 2, c: 3), 'b', 'c'); // (2, 3)

// key list
@debug map.values(((a, b): 1, b: 2, c: 3), 'a', (a, b), 'c'); // ("a", 1, 3)

// key map
@debug map.values((b: 2, (a: b): 1, c: 3), 'a', (a: b), 'c'); // ("a", 1, 3)

// default functionality
@debug map.values((a: 1, b: 2, c: 3)); // (1, 2, 3)

Last updated