map.set()

The map.set() function sets $allowed $value under $key.

Original sass map.set() function modified, by adding $allowed... arbitrary argument to check if $value is allowed to be set.

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

// The `map.set()` function.
@function update($map, $key-value, $allowed...) {
  @each $key, $value in $key-value {
    $map: set($map, $key, $value, $allowed...);
  }
  @return $map;
}

Parameters

$map

A map to set $value at $key.

$key

A key under which $value is set.

$value

The value to set in $map under $key.

$allowed...

Allowed value types and/or values to set in $map.

Return

The return value is updated $map with $value at $key.

Examples

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

// Examples.
@debug map.set((), ((test, 1),), 2222); // ((test, 1): 2222)
@debug map.set((), (test 1, (test, 2)), 2222); // (test 1: ((test, 2): 2222))

// single type
@debug map.set((a: 1, b: 2), test string, 27, string ); // (a: 1, b: 2)
@debug map.set((a: 1, b: 2), test number, 27, number); // (a: 1, b: 2, test: (number: 27))
@debug map.set((a: 1, b: 2), test map, (map: 22,), map); // (a: 1, b: 2, test: (map: (map: 22)))
@debug map.set((a: 1, b: 2), test list, (22, 44), list); // (a: 1, b: 2, test: (list: (22, 44)))
@debug map.set((a: 1, b: 2), test color, #ffffff, color); // (a: 1, b: 2, test: (color: #ffffff))
@debug map.set((a: 1, b: 2), test null, null, null); // (a: 1, b: 2, test: (null: null))

// multiple types
@debug map.set((a: 1, b: 2), test number, 27, number, string, bool, list, map); // (a: 1, b: 2, test: (number: 27))
@debug map.set((a: 1, b: 2), test string, twenty seven, number, string, bool, list, map); // (a: 1, b: 2, test: (string: twenty seven))
@debug map.set((a: 1, b: 2), test bool, false, number, string, bool, list, map); // (a: 1, b: 2, test: (bool: false))
@debug map.set((a: 1, b: 2), test null, null, number, null, string, bool, list, map); // (a: 1, b: 2, test: (null: null))

Last updated