pick.pattern()

The pick.pattern() function returns a copy of $map filtered by using pattern.

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

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

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

// The `pick.pattern()` or `map.pick-pattern()` function.
@function pattern($map, $patterns...) {
  $result: ();
  @each $pattern in $patterns {
    @if type-of($pattern) == string {
      @if string.index($pattern, '*') {
        $result: map.deep-merge(
          $result,
          key-substring(
            $map,
            string.replace($pattern, list.join(first '*', ''))
          )
        );
      } @else if
        string.index($pattern, 'value:') or
        string.index($pattern, 'key:')
      {
        $result: map.deep-merge($result, type($map, $pattern));
      }
    }
  }
  @return $result;
}

Parameters

$map

A map from which properties are picked.

$patterns...

A patterns to pick properties from a $map.

Return

The return value is a copy of $map with properties associated with patterns.

Examples

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

// Examples.

Last updated