dictionary.merge()

The dictionary.merge() function returns a global dictionary merged with $dictionary and/or multiple $dictionaries, optionally merged in $key.

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

// Variables.
@forward 'dictionary.variables';
@use 'dictionary.variables' as variables;

// Functions.
@use 'dictionary.get.function' as *;

// Modules.
@use '../../../map';

// The `translator.dictionary-merge()` or `dictionary.merge()` function.
@function merge($key: null, $dictionary, $dictionaries...) {
  $retrieved-dictionary: ();
  @each $dictionary in list.join(($dictionary, ), $dictionaries, comma) {
    $retrieved-dictionary: map.deep-merge($retrieved-dictionary, $dictionary);
  }

  variables.$dictionary: if(
    $key,
    map.merge(get() or (), list.append($key, $retrieved-dictionary)...),
    map.deep-merge(get() or (), $retrieved-dictionary)
  );

  @return variables.$dictionary;
}

Parameters

$key: null

The optional key under which $dictionary and multiple $dictionaries are being merged.

$dictionary: ()

Dictionary of map type to merge with a global dictionary.

$dictionaries...

Additional dictionaries along with a $dictionary to merge with a global dictionary.

Return

The return value is global dictionary merged with $dictionary and/or multiple $dictionaries, optionally merged in $key.

Examples

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

// Examples.
$-dictionary: (
  (extra large, 'extra large', extra-large): xl,
  (extra small, 'extra small', extra-small): xs,
  class: (prefix: class-prefix, suffix: class-suffix),
  large: lg,
  medium: md,
  prefix: spectre,
  size: s,
  small: sm,
  suffix: end,
  var: (prefix: var-prefix, suffix: var-suffix),
);

// merge in `class` key
@debug translator.dictionary-merge(class, (prefix: spectre, suffix: end)); // (word: translation, class: (prefix: spectre, suffix: end))

// merge in nested (accordion, class) key
@debug translator.dictionary-merge((accordion, class), (prefix: spectre, suffix: end)); // (word: translation, class: (prefix: spectre, suffix: end), accordion: (class: (prefix: spectre, suffix: end)))

Last updated