values.combine()

The values.combine() function combines multiple $values into the list. By default, the function use append method to combine $values. The parameters of the list (bracketed, delimiter, method, null, separator) can be changed by providing map value eg. (method: join).

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

// Functions.
@use '../list/list.join.function' as *;

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

// The `values.combine()` function.
@function combine($values...) {
  $parameters: (
    bracketed: map.get(list.nth($values, 1), bracketed, auto),
    delimiter: null,
    method: append,
    null: false,
    separator: map.get(list.nth($values, 1), separator, auto),
  );
  $result: list.join((), (), map.pick($parameters, separator, bracketed)...);
  @each $value in $values {
    $allow: true;
    $method: map.get($parameters, method);
    @if type-of($value) ==
      map and
      map.has-keys($value, any, append, join, map.keys($parameters)...)
    {
      $parameters: map.merge($parameters, map.remove($value, append, join));
      @if map.has-keys($value, any, append, join) {
        @each $use-method, $use-value in $value {
          $method: $use-method;
          $value: $use-value;
        }
      } @else {
        $allow: false;
      }
    }
    @if not map.get($parameters, null) and not $value {
      $allow: false;
    }
    @if $allow {
      $result: meta.call(
        meta.get-function($method),
        $result,
        $value,
        map.pick(
            $parameters,
            if($method == join, (separator, bracketed), separator)...
          )...
      );
    }
  }
  @if map.get($parameters, delimiter) {
    $result: join((), $result, map.pick($parameters, separator, delimiter)...);
  }
  @return $result;
}
https://github.com/angular-package/sass/blob/main/values/_values.combine.function.scss

Parameters

$values...

Arbitrary values to combine into the returned list.

Return

The return value is the list combined by the specified method, with a separator, and/or delimiter.

Examples

Last updated

Was this helpful?