Skip to content
James Kyle edited this page Nov 23, 2013 · 8 revisions

Lists

Chunk chunk($list, $size)

Splits $list every $size items.

chunk( (1, 2, 3, 4, 5), 3 );
=> (1 2 3, 4 5)

Compact compact($list) Alias: purge

Returns a copy of the list with all falsy values and empty strings removed.

compact( (0, 1, false, 2, '', 3 ) );
=> (0, 1, 2, 3)

Contains contains($list, $value) Alias: include

Returns true if the $value is present in the $list. Uses index internally.

contains( (1, 2, 3), 2 );
=> true

First first($list, [$n]) Alias: head, take

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

Flatten flatten($list, [$shallow])

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)));

Initial initial($list, [$n])

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)

Intersection intersection($lists...)

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)

Is Symmetrical is-symmetrical($list, [$recursive])Alias: is-mirror

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

Last last($list, [$n])

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)

Loop loop($list, [$n]) Alias: shift-indexes

Shifts indexes from $list by $n.

loop( (1, 2, 3) );
=> (3, 1, 2)

loop( (1, 2, 3), 2 );
=> (2, 3, 1)

Prepend prepend($list, $item)

Prepends a single $item onto the start of a $list.

prepend( (2, 3, 4), 1 );
=> (1, 2, 3, 4)

Replace Nth replace-nth($list, $index, [$value])

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)

Replace replace($list, $old-value, [$new-value], [$recursive])

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))

Rest rest($list, [$n]) Alias: tail, drop

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)

Reverse reverse($list, [$recursive]

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)

Slice slice($list, [$min], [$max])

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)

Sum sum($list) Alias: total

Sums up $list of unitless numbers or numbers with the same unit.

sum( (1, 2, 3) );
=> 6

sum( (1em, 2em, 3em) );
=> 6em

Union union($lists...)

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)

Unique unique($list, [$recursive]) Alias: uniq, remove-duplicates

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)

Without without($list, [$values...]) Alias: remove

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)

Without-Nth without-nth($list, $index) Alias: remove-nth

Removes value from $list at $index.

without( (1, 2, 3), 2);
=> (1, 3)

Numbers

Absolute Unit absolute-unit($number)

Returns true if the $number is an absolute value.

absolute-unit(10px);
=> true

Ceil To ceil-to($number, $precision)

Returns $number rounded up to the $precision decimal place.

ceil-to( 0.1234, 2 );
=> 0.13

Convert convert($number, $unit, [$ref])

Returns $number converted to $unit. Relative Units require a $ref. Valid $units 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

E e()

Returns Euler's Number.

e();
=> 2.71828182845

Exponent exponent($number, $exponent) Alias: power, pow

Returns $number multiplied exponentially to $exponent.

exponent(2, 2);
=> 4

Factorial factorial($number) Alias: fact

Returns the factorial of $number.

factorial(3);
=> 6

Floor To floor-to($number, $precision)

Returns $number rounded down to the $precision decimal place.

floor-to( 0.1234, 2 );
=> 0.12

Infinity infinity() Alias: inf

Returns sass infinity.

infinity();
=> 1/0

Is Float is-float($number)

Returns true if $number is a float.

is-float(0.1);
=> true

Is Inf is-inf($number)

Returns true is $number is infinite.

is-inf( infinity() );
=> true

Is Int is-int($number)

Returns true is $number is integer.

is-int(2);
=> true

Is Prime is-prime($number)

Returns true if $number is prime.

is-prime(7);
=> true

Is Unit is-unit($number, $unit)

Returns true if $number is $unit.

is-unit(1px, "px");
=> true

Limit limit($number, [$min], [$max])

Returns $number rounded to be between $min and $max.

limit(3, 10, 20);
=> 10

Parse Int parse-int($number) Alias: strip-unit

Returns copy of $number without any unit.

parse-int(10px);
=> 10

Phi phi() Alias: golden-ratio

Returns Phi.

phi();
=> 1.61803398874

Pi pi()

Returns Pi.

pi();
=> 3.14159265359

Relative Unit relative-unit($number)

Returns true if the $number is an relative value.

relative-unit(10em);
=> true

Round To round-to($number, $precision)

Returns $number rounded to the $precision decimal place.

round-to( 0.1234, 2 );
=> 0.12

Tau tau()

Returns Tau.

tau();
=> 6.2831853072

Unit Type unit-type($number)

Returns unit type of $number (relative, absolute, or unitless).

unit-type(1em);
=> "relative"
Clone this wiki locally