map.pick()

The map.pick() function returns a copy of $map of $keys.

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

// Functions.
@use 'map.deep-merge.function' as *;
@use 'map.get.function' as *;
@use 'map.set.function' as *;

// Modules.
@use 'pattern';
@use 'pick';

// The `map.pick()` function.
@function pick($map, $keys...) {
  $result: ();
  @each $key in $keys {
    @if type-of($key) == list {
      $result: set(
        $result,
        if(
          list.separator($key) == space,
          ($key),
          if(list.length($key) > 1, list.nth($key, list.length($key)), $key)
        ),
        get($map, $key)
      );
    } @else if pattern.is($key) {
      $result: deep-merge($result, pick.pattern($map, $key...));
    } @else {
      $result: deep-merge(
        $result,
        (
          $key: get($map, $key),
        )
      );
    }
  }
  @return $result;
}

Parameters

$map

A map from which values of $keys are taken.

$keys...

List of keys to get the values from $map.

Return

The return value is a copy of $map built of $keys.

Examples

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

// Examples.

Last updated