range.up()

The math.range-up() or range.up() function returns the range of numbers where $from is lower than $to.

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

// Functions.
@use '../../meta/meta.of-type.function';

// The `math.range-up()` or `range.up` function.
@function up($from, $to, $step: 1, $except: null, $separator: auto) {
  @if meta.of-type(number, $from, $to, $step) and $from < $to {
    $result: ();
    $number: $from;
    @while $number <= $to {
      $result: if(
        not $except or ($except and not list.index($except, $number)),
        list.append($result, $number, $separator),
        $result
      );
      $number: $number + $step;
    }

    @return if(list.length($result) > 0, $result, null);
  }
  @return null;
}

Parameters

$from

The value of the number type indicates the beginning of the range.

$to

The value of number type indicates the end of the range.

$step: 1

The value of number type indicates each increment of the range. By default, it's 1.

$except: null

The value of a number or list of numbers not belonging to the range.

$separator: auto

A separator between the given range numbers.

Return

The return value is the list of numbers from the given range.

Examples

// Use.
@use '@angular-package/sass/math';
@use '@angular-package/sass/math/range';

// Examples.
@debug math.range-up(15, 20); // 15 16 17 18 19 20

// step 0.1
@debug math.range-up(0.1, 1, 0.1); // 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

// step 2
@debug math.range-up(15, 30, 2); // 15 17 19 21 23 25 27 29

// except
@debug math.range-up(20, 35, 1, 20 35); // 21 22 23 24 25 26 27 28 29 30 31 32 33 34

// separator
@debug math.range-up(20, 25, $separator: comma); // 20, 21, 22, 23, 24, 25

// null
@debug math.range-up(20, 35); // null

Last updated