map.has-keys()

The map.has-keys() function checks whether $map contains $keys.

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

// The `map.has-keys()` function.
@function has-keys($map, $keys...) {
  $has: ();
  @each $key in $keys {
    $has: list.append(
      $has,
      if(
        list.separator($key) == comma,
        map.has-key($map, $key...),
        map.has-key($map, $key)
      )
    );
  }
  @return if(list.index($has, false), false, true);
}

Parameters

$map

A map to check whether it has all $keys.

$keys...

The keys to check if $map contains them.

Return

The return value is a bool indicating $map contains $keys.

Examples

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

// Examples.
$-map: (list1: (), list2: (), a b c d e f: value, a: (b: (c: (d: e))), any: true, all: false, separator: auto, bracketed: false, method: join, null: false);

// string key
@debug map.has-keys($-map, list1, list2); // true

// string keys
@debug map.has-keys($-map, list1, list2); // true
@debug map.has-keys($-map, list1, list2, wrong); // false
@debug map.has-keys($-map, list1, list3); // false

// list key
@debug map.has-keys($-map, a b c d e f); // true
@debug map.has-keys($-map, a b c d e); // false
@debug map.has-keys($-map, a b c d e f, bracketed); // true
@debug map.has-keys($-map, a b c d e, bracketed); // false

// nested keys
@debug map.has-keys($-map, (a, b, c, d), a b c d e f); // true
@debug map.has-keys($-map, (a, b, c, d), (a b c d e f g)); // false

Last updated