pick.type()

The pick.type() or map.pick-type() function picks the properties with values and/or keys of type.

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

// Functions.
@use 'pick.key-type.function' as *;
@use 'pick.value-type.function' as *;

// Modules.
@use '../../string';

// The `pick.type()` or `map.pick-type()` function.
@function type($map, $field-type...) {
  $result: ();
  @each $pattern in $field-type {
    @if type-of($pattern) == string {
      @if string.index($pattern, 'value:') or string.index($pattern, 'key:') {
        $pattern: string.split(string.unquote($pattern), ':');
        $type: string.split(list.nth($pattern, 2), ',');
        $result: map.deep-merge(
          $result,
          if(
            list.nth($pattern, 1) == key,
            key-type($map, $type...),
            value-type($map, $type...)
          )
        );
      }
    }
  }
  @return $result;
}

Parameters

$map

A map from which properties with values and/or keys of a certain type are picked.

$field-type...

A pattern field:type where field can be value or key and type bool, calculation, color, function, list, map, null, number or string, to pick properties with the value and/or key of the specified type.

Return

The return value is a copy of $map with values and/or keys associated with types.

Examples

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

// Examples.

Last updated