string.join()

The string.join() function returns the string built from $elements separated by $delimiter in original elements order.

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

// The `string.join()` function.
@function join($delimiter, $elements...) {
  $string: '';
  @each $element in $elements {
    @if list.index(color list number string, type-of($element)) {
      @each $element in $element {
        $string: string.insert($string, #{$element}#{$delimiter or ''}, -1);
      }
    }
  }
  @return string.slice($string, 1, calc((string.length($delimiter) + 1) * -1));
}

Parameters

$delimiter

The delimiter to add between $elements.

$elements...

Elements to join to returned string of color, list, number or string type with the $delimiter.

Return

The return value is a string built from $elements with $delimiter.

Examples

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

// Examples.
@debug string.join('-');
@debug string.join('-', 'a', 'b', 'c'); // a-b-c
@debug string.join('-', '', 'a', 'b', 'c'); // -a-b-c
@debug string.join('-', 'a', 'b', 'c', ''); // a-b-c-
@debug string.join('-', '', 'a', 'b', 'c', ''); // a-b-c-
@debug string.join('-', 'a', ('b', 'c')); // a-b-c
@debug string.join('-', a, b, c); // a-b-c

// Join number.
@debug string.join('-', a, 1, b, 2, c, 3); // a-1-b-2-c-3

// Join color.
@debug string.join('-', silver, orange, green, red, blue, yellow); // silver-orange-green-red-blue-yellow

Last updated