pattern.is()

The pattern.is() function checks whether the $value is a map pattern.

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

// The `pattern.is()` function.
@function is($value, $pattern: map.values($pattern)) {
  @if type-of($value) == string {
    @each $pattern in $pattern {
      @if type-of($pattern) == list {
        @each $sub-pattern in $pattern {
          @if string.index($value, $sub-pattern) {
            @return true;
          }
        }
      } @else {
        @if string.index($value, $pattern) {
          @return true;
        }
      }
    }
  }
  @return false;
}

Parameters

$value

A value to check against it's a pattern.

$pattern: map.values($pattern)

A list of patterns to check.

Return

The return value is a bool indicating the $value is a pattern of $pattern.

Examples

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

// Examples.
@debug pattern.is('*.palette'); // true
@debug pattern.is('value:string'); // true
@debug pattern.is('key:number'); // true

Last updated