math.range()
The math.range()
function returns the range of numbers.
// Sass.
@use 'sass:list';
// Functions.
@use '../meta/meta.of-type.function';
// Modules.
@use 'range';
// The `math.range()` function.
@function range($from, $to, $step: 1, $except: null, $separator: auto) {
@return if(
meta.of-type(number, $from, $to, $step),
if(
$from < $to,
range.up($from, $to, $step, $except, $separator),
range.down($from, $to, $step, $except, $separator)
),
null
);
}
https://github.com/angular-package/sass/blob/main/math/_math.range.function.scss
// Sass.
@use 'sass:list';
// Functions.
@use '../meta/meta.of-type.function';
// Modules.
@use 'range';
// Status: DONE
// The `math.range()` function returns the range of numbers.
// @param `$from` The value of the number type indicates the beginning of the range.
// @param `$to` The value of the number type indicates the end of the range.
// @param `$except` The value of a number or list of numbers not belonging to the range.
// @param `$separator` A separator between the given range numbers.
// @return The return value is the list of numbers from the given range.
@function range($from, $to, $step: 1, $except: null, $separator: auto) {
@return if(
meta.of-type(number, $from, $to, $step),
if($from < $to, range.up($from, $to, $step, $except, $separator), range.down($from, $to, $step, $except, $separator)),
null
);
}
// Examples.
// @debug range(15, 20); // 15 16 17 18 19 20
// @debug range(20, 15); // 20 19 18 17 16 15
// step 2
// @debug range(15, 20, 2); // 15 17 19
// to lower step 2
// @debug range(15, -3, 2); // 15 13 11 9 7 5 3 1 -1 -3
// except
// @debug range(15, -3, 1, 0); // 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 -1 -2 -3
// @debug range(15, -3, 1, 0 15 14); // 13 12 11 10 9 8 7 6 5 4 3 2 1 -1 -2 -3
// separator
// @debug range(15, -3, 3, $separator: comma); // 15, 12, 9, 6, 3, 0, -3
Parameters
$from
$from
The value of the number
type indicates the beginning of the range.
$to
$to
The value of number
type indicates the end of the range.
$step: 1
$step: 1
The value of number
type indicates each increment of the range. By default, it's 1
.
$except: null
$except: null
The value of a number
or list
of numbers not belonging to the range.
$separator: auto
$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';
// Examples.
@debug math.range(15, 20); // 15 16 17 18 19 20
@debug math.range(20, 15); // 20 19 18 17 16 15
// step 2
@debug math.range(15, 20, 2); // 15 17 19
// to lower step 2
@debug math.range(15, -3, 2); // 15 13 11 9 7 5 3 1 -1 -3
// except
@debug math.range(15, -3, 1, 0); // 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 -1 -2 -3
@debug math.range(15, -3, 1, 0 15 14); // 13 12 11 10 9 8 7 6 5 4 3 2 1 -1 -2 -3
// separator
@debug math.range(15, -3, 3, $separator: comma); // 15, 12, 9, 6, 3, 0, -3
Last updated
Was this helpful?