list.limit()

The list.limit() function returns the list from the first to $limit... index, or from the offset to the limit index.

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

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

// The `list.limit()` function.
@function limit($list, $limit...) {
  @return range(
    $list,
    if(
        list.length($limit) == 1,
        list.join(1, $limit, comma),
        list.join(
          list.nth($limit, 1),
          calc(list.nth($limit, 1) + list.nth($limit, 2) - 1),
          comma
        )
      )...
  );
}

Parameters

$list

The list to retrieve the elements from, limited by the $limit.

$limit...

A number of the indexes of the returned list from first, or given offset.

Return

The return value is $list of elements specified in $limit....

Examples

Limit

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

// Examples.
// limit - number
@debug list.limit(('a', 'b', 'c', 'd', 'e', 'f'), 1); // ("a",)
@debug list.limit(('27', '28', '29', 30), 2); // "27", "28"
@debug list.limit(('a', 'b', 'c', 'd', 'e', 'f'), 2); // "a", "b"
@debug list.limit(('a', 'b', 'c', 'd', 'e', 'f'), 5); // "a", "b", "c", "d", "e"
@debug list.limit(('a', 'b', 'c', 'd', 'e', 'f'), 4); // "a", "b", "c", "d"

Offset - limit

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

// Examples.
// offset - limit
@debug list.limit(('a', 'b', 'c', 'd', 'e', 'f'), 2, 5); // "b", "c", "d", "e", "f"
@debug list.limit(('a', 'b', 'c', 'd', 'e', 'f'), 1 4...); // "a", "b", "c", "d"
@debug list.limit(('a', 'b', 'c', 'd', 'e', 'f'), 2 4...); // "b", "c", "d", "e"
@debug list.limit(('a', 'b', 'c', 'd', 'e', 'f'), (2, 5)...); // "b", "c", "d", "e", "f"
@debug list.limit(('a', 'b', 'c', 'd', 'e', 'f'), (5, 3)...); // "e", "f", null

Last updated