Introduction
Splits $list
every $size
items.
chunk( (1, 2, 3, 4, 5), 3 );
=> (1 2 3, 4 5)
Returns a copy of the list with all falsy values and empty strings removed.
compact( (0, 1, false, 2, '', 3 ) );
=> (0, 1, 2, 3)
Returns true if the $value
is present in the $list
. Uses index
internally.
contains( (1, 2, 3), 2 );
=> true
Returns the first element of a $list
. Passing $n
will return the first $n
elements of the $list
.
first( (5, 4, 3, 2, 1) );
=> 5
Flattens a nested $list
(the nesting can be to any depth). If you pass $shallow
, the $list
will only be flattened a single level.
flatten( (1, (2), (3, ((4)))) );
=> (1, 2, 3, 4);
flatten( (1, (2), (3, ((4)))), true );
=> (1, 2, 3, ((4)));
Returns everything but the last entry of the $list
. Pass $n
to exclude the last $n
elements from the result.
initial( (5, 4, 3, 2, 1) );
=> (5, 4, 3, 2)
initial( (5, 4, 3, 2, 1), 2 );
=> (5, 4, 3)
Computes the list of values that are the intersection of all the $lists
. Each value in the result is present in each of the $lists
.
intersection( (1, 2, 3), (101, 2, 1, 10), (2, 1) );
=> (1, 2)
Returns true if $list
is symmetrical. Pass $recursive: true
to run recursively.
is-symmetrical( (1, 2, (1, 2, 3), 2, 1) );
=> true
is-symmetrical( (1, 2, (1, 2, 3), 2, 1), $recursive: true);
=> false
Returns the last element of a $list
. Passing $n
will return the last $n
elements of the array.
last( (5, 4, 3, 2, 1) );
=> 1
last( (5, 4, 3, 2, 1), 2 );
=> (2, 1)
Shifts indexes from $list
by $n
.
loop( (1, 2, 3) );
=> (3, 1, 2)
loop( (1, 2, 3), 2 );
=> (2, 3, 1)
Prepends a single $item
onto the start of a $list
.
prepend( (2, 3, 4), 1 );
=> (1, 2, 3, 4)
Replaces value at $index
from $list
by $value
. If no $value
is passed, the item will be removed.
replace-nth( (1, 0, 3), 2, 2 );
=> (1, 2, 3)
replace-nth( (1, 0, 3), 2);
=> (1, 3)
Replaces $old-value
by $new-value
in $list
. If no $new-value
is passed, the item will be removed. Pass $recursive: true
to run recursively.
replace( (1, 0, (3, 0)), 0, 2 );
=> (1, 2, (3, 0))
replace( (1, 0, (3, 0)), 2, $recursive: true);
=> (1, (3))
Returns the rest of the elements in a $list
. Passing $n
will return the values of the $list
from $n
onward.
rest( (5, 4, 3, 2, 1) );
=> (4, 3, 2, 1)
Reverses the order of $list
. Pass $recursive: true
to run recursively.
reverse( (1, (2, 3), 4) );
=> (4, (2, 3), 1)
reverse( (1, (2, 3), 4), $recursive: true );
=> (4, (3, 2), 1)
Returns a copy of the list between $min
and $max
. $min
defaults to the start of the list, $max
defaults to the end of the list. Negative values are valid and will count from the end of the list.
slice( (1, 2, 3, 4, 5), 2, 4 )
=> (2, 3, 4)
Sums up $list
of unitless numbers or numbers with the same unit.
sum( (1, 2, 3) );
=> 6
sum( (1em, 2em, 3em) );
=> 6em
Computes the union of the passed-in $lists
: the list of unique items, in order, that are present in one or more of the $lists
.
union( (1, 2, 3), (101, 2, 1, 10), (2, 1));
=> (1, 2, 3, 101, 10)
Returns a copy of the $list
with all duplicate items removed. Pass $recursive: true
to run recursively.
unique( (1, 2, (1, 2), 1, 2) );
=> (1, 2, (1, 2))
unique( (1, (2, 3), 4), $recursive: true );
=> (1, 2)
Returns a copy of the $list
with all instances of the $values
removed.
without( (1, 2, 1, 0, 3, 1, 4), 0, 1 );
=> (2, 3, 4)
Removes value from $list
at $index
.
without( (1, 2, 3), 2);
=> (1, 3)
Returns true if the $number
is an absolute value.
absolute-unit(10px);
=> true
Returns $number
rounded up to the $precision
decimal place.
ceil-to( 0.1234, 2 );
=> 0.13
Returns $number
converted to $unit
. Relative Units require a $ref
. Valid $unit
s are px
, pc
, pt
, in
, cm
, mm
, em*
, rem*
, ex*
, ch*
, ms
, s
, deg
, grad
, rad
, and turn
. *needs $ref
.
convert(10px, "in");
=> 0.104166667in
convert(10px, "em", 10);
=> 1em
Returns Euler's Number.
e();
=> 2.71828182845
Returns $number
multiplied exponentially to $exponent
.
exponent(2, 2);
=> 4
Returns the factorial of $number
.
factorial(3);
=> 6
Returns $number
rounded down to the $precision
decimal place.
floor-to( 0.1234, 2 );
=> 0.12
Returns sass infinity.
infinity();
=> 1/0
Returns true if $number
is a float.
is-float(0.1);
=> true
Returns true is $number
is infinite.
is-inf( infinity() );
=> true
Returns true is $number
is integer.
is-int(2);
=> true
Returns true if $number
is prime.
is-prime(7);
=> true
Returns true if $number
is $unit
.
is-unit(1px, "px");
=> true
Returns $number
rounded to be between $min
and $max
.
limit(3, 10, 20);
=> 10
Returns copy of $number
without any unit.
parse-int(10px);
=> 10
Returns Phi.
phi();
=> 1.61803398874
Returns Pi.
pi();
=> 3.14159265359
Returns true if the $number
is an relative value.
relative-unit(10em);
=> true
Returns $number
rounded to the $precision
decimal place.
round-to( 0.1234, 2 );
=> 0.12
Returns Tau.
tau();
=> 6.2831853072
Returns unit type of $number
(relative, absolute, or unitless).
unit-type(1em);
=> "relative"