SassyLists

functions

sl-chunk

@function sl-chunk($list, $size) { ... }
View source

Description

Chunks $list into $size large lists.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to chunk

List none
$size

length of lists

Number none

Returns

List, Null

Example

sl-chunk(a b c d e, 2)
// a b, c d, e

Throws

  • $size is not a number for sl-chunk.

Requires

sl-comma-list

@function sl-comma-list() { ... }
View source

Description

Initialize an empty comma-separated list.

Parameters

None.

Returns

List

Example

sl-comma-list()
// ()

sl-contain (aliased as sl-include )

@function sl-contain($list, $value) { ... }
View source

Description

Returns whether $list contains $value.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to check

List none
$value

value to look for

Any none

Returns

Bool

Example

sl-contain(a b c, a)
// true
sl-contain(a b c, z)
// false

Used by

sl-include (alias for sl-contain)

@function sl-include() { ... }
View source

Refer to sl-contain.

sl-count-values

@function sl-count-values($list) { ... }
View source

Description

Counts the number of occurrences of each value of $list.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to count values from

List none

Returns

Values mapped to their count

Map

Example

sl-count-values(a b c a)
// (a: 2, b: 1, c: 1) 

sl-debug

@function sl-debug($list, $pre: false, $level: 1) { ... }
View source

Description

Returns $list as a string, prettified if $pre is set to true.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to debug

List none
$pre

enable/disable variables type and proper indentation

Bool false
$level

internal variable for recursion

Number 1

Returns

String

Example

sl-debug(a b c)
// '("a", "b", "c")'

Requires

Used by

sl-every

@function sl-every($list, $function, $args...) { ... }
View source

Description

Tests whether all items from $list pass the test implemented by $function.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to run test against

List none
$function

function to run against every item from list

String none
$args

extra arguments to pass to the function

Arglist none

Returns

Bool

Example

sl-every(1 2 3, unitless)
// true
sl-every(1 2 3px, unitless)
// false

Used by

sl-explode

@function sl-explode($string, $delimiter: '', $separator: 'space') { ... }
View source

Description

Explodes $string into a list using $delimiter as a delimiter.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$string

string to explode

String none
$delimiter

string to use as a delimiter

String ''
$separator

list separator

String 'space'

Returns

List, Null

Example

sl-explode(abc)
// a b c
sl-explode(abc, b)
// a c

Throws

  • $string is not a string for sl-explode.

  • $delimiter is not a string for sl-explode.

sl-first (aliased as sl-head )

@function sl-first($list) { ... }
View source

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to retrieve first item from

List none

Returns

Any

Example

sl-first(a b c)
// a
sl-first(a)
// a
sl-first(())
// null

Throws

  • Cannot find first item of empty list.

Requires

Used by

sl-head (alias for sl-first)

@function sl-head() { ... }
View source

Refer to sl-first.

sl-flatten (aliased as sl-unfold )

@function sl-flatten($list) { ... }
View source

Description

Turns multidimensional $list into a one-level list.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to flatten

List none

Returns

List

Example

sl-flatten(a b c, d e f, g h i)
// a b c d e f g h i

Requires

Used by

sl-unfold (alias for sl-flatten)

@function sl-unfold() { ... }
View source

Refer to sl-flatten.

sl-has-multiple-values

@function sl-has-multiple-values($list) { ... }
View source

Description

Tests whether $list has at least 2 values.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to run test against

List none

Returns

Bool

Example

sl-has-multiple-values(a)
// false
sl-has-multiple-values(a b)
// true

Used by

sl-has-values

@function sl-has-values($list) { ... }
View source

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to run test against

List none

Returns

Bool

Example

sl-has-values(a)
// true
sl-has-values(())
// false

sl-insert-nth

@function sl-insert-nth($list, $index, $value) { ... }
View source

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to update

List none
$index

index to add

Number none
$value

value to add

Any none

Returns

List, Null

Example

sl-insert-nth(a b c, 2, z)
// a z b c
sl-insert-nth(a b c, 42, z)
// a b c z
sl-insert-nth(a b c, -42, z)
// null

Throws

  • List index $index is not a number for sl-insert-nth.

  • List index $index must be a non-zero integer for sl-insert-nth.

sl-intersection

@function sl-intersection($list, $lists...) { ... }
View source

Description

Returns a list of shared value from $list and $lists minus duplicates.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

first list

List none
$lists

other lists

Arglist none

Returns

List

Example

sl-intersection(a b c, b e d, a c b)
// b

Requires

sl-is-empty (aliased as sl-empty )

@function sl-is-empty($list) { ... }
View source

Description

Tests whether $list is empty.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to run test against

List none

Returns

Bool

Example

sl-is-empty(())
// true
sl-is-empty(a)
// false

Used by

sl-empty (alias for sl-is-empty)

@function sl-empty() { ... }
View source

Refer to sl-is-empty.

sl-is-single

@function sl-is-single($list) { ... }
View source

Description

Tests whether $list has a single item.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to run test against

List none

Returns

Bool

Example

sl-is-single(())
// false
sl-is-single(a)
// true
sl-is-single(a b)
// false

Used by

sl-is-symmetrical (aliased as sl-is-mirror )

@function sl-is-symmetrical($list) { ... }
View source

Description

Checks whether $list is symmetrical.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to check

List none

Returns

Bool

Example

sl-is-symmetrical(a b c)
// false
sl-is-symmetrical(a b a)
// true

Requires

Used by

sl-is-mirror (alias for sl-is-symmetrical)

@function sl-is-mirror() { ... }
View source

Refer to sl-is-symmetrical.

sl-last-index

@function sl-last-index($list, $value) { ... }
View source

Description

Returns last index of $value in $list.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to search

List none
$value

value to be searched for

Any none

Returns

Number, Null

Example

sl-last-index(a b a, a)
// 3
sl-last-index(a b a, z)
// null

sl-last

@function sl-last($list) { ... }
View source

Description

Returns last element of $list.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to retrieve last value from

List none

Returns

Any

Example

sl-last(a b c)
// c
sl-last(a)
// a
sl-last(())
// null

Throws

  • Cannot find last item of empty list.

Requires

Used by

sl-loop (aliased as sl-shift-indexes )

@function sl-loop($list, $value: 1) { ... }
View source

Description

Shift indexes from $list of $value.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to update

List none
$value

number of position between old and new indexes

Number 1

Returns

List, Null

Example

sl-loop(a b c)
// c a b
sl-loop(a b c, 2)
// b c a

Throws

  • $value is not a number for loop.

Requires

Used by

Author

  • Ana Tudor

sl-shift-indexes (alias for sl-loop)

@function sl-shift-indexes() { ... }
View source

Refer to sl-loop.

sl-prepend

@function sl-prepend($list, $value) { ... }
View source

Description

Adds $value as first index of $list.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to preprend value to

List none
$value

value to prepend to the list

Any none

Returns

List

Example

sl-prepend(a b c, z)
// z a b c

Requires

sl-purge (aliased as sl-clean )

@function sl-purge($list) { ... }
View source

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to purge

List none

Returns

List

Example

sl-purge(null a false b)
// a b

Requires

Used by

sl-clean (alias for sl-purge)

@function sl-clean() { ... }
View source

Refer to sl-purge.

sl-random-value (aliased as sl-roll sl-luck )

@function sl-random-value($list) { ... }
View source

Description

Returns a random value of $list.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to random value from

List none

Returns

Any

Example

sl-random-value(a b c)
// a

Throws

  • Cannot find a random value in an empty list.

Requires

Used by

sl-roll (alias for sl-random-value)

@function sl-roll() { ... }
View source

Refer to sl-random-value.

sl-luck (alias for sl-random-value)

@function sl-luck() { ... }
View source

Refer to sl-random-value.

sl-range

@function sl-range($n) { ... }
View source

Description

Build a list of values from 1 through $n.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$n

maximum value

Number none

Returns

List, Number, Null

Example

sl-range(5)
// 1 2 3 4 5
sl-range(1)
// 1
sl-range(-42)
// null

Throws

  • $n is not a number for sl-range.

  • $n is not unitless for sl-range.

  • $n is not greater than 0 for sl-range.

Used by

sl-remove-duplicates (aliased as sl-unique )

@function sl-remove-duplicates($list) { ... }
View source

Description

Removes duplicate values from $list.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to remove duplicates from

List none

Returns

List

Example

sl-remove-duplicates(a b a b)
// a b

Requires

Used by

sl-unique (alias for sl-remove-duplicates)

@function sl-unique() { ... }
View source

Refer to sl-remove-duplicates.

sl-remove-nth (aliased as sl-without-nth )

@function sl-remove-nth($list, $index) { ... }
View source

Description

Removes value from $list at index $index.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to remove value from

List none
$index

index to remove

Number none

Returns

List, Null

Example

sl-remove-nth(a b c, 2)
// a c
sl-remove-nth(a b c, 42)
// null

Requires

Used by

sl-without-nth (alias for sl-remove-nth)

@function sl-without-nth() { ... }
View source

Refer to sl-remove-nth.

sl-remove (aliased as sl-without )

@function sl-remove($list, $value) { ... }
View source

Description

Removes value(s) $value from $list.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to update

List none
$value

value to remove

Any none

Returns

List

Example

sl-remove(a b c, a)
// b c

Requires

Used by

sl-without (alias for sl-remove)

@function sl-without() { ... }
View source

Refer to sl-remove.

sl-replace-nth

@function sl-replace-nth($list, $index, $value) { ... }
View source

Description

Replaces value at $index from $list by $value.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to update

List none
$index

index to update

Number none
$value

new value for index

Any none

Returns

List, Null

Example

sl-replace-nth(a b c, 2, z)
// a z c
sl-replace-nth(a b c, 100, z)
// null

Throws

  • Invalid index $index for sl-replace-nth.

Requires

Used by

sl-replace

@function sl-replace($list, $old, $value) { ... }
View source

Description

Replaces $old by $new in $list.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to update

List none
$old

value to replace

Any none
$value

new value for $old

Any none

Returns

List

Example

sl-replace(a b c, b, z)
// a z c
sl-replace(a b c, y, z)
// a b c

Requires

Used by

sl-reverse (aliased as sl-mirror )

@function sl-reverse($list) { ... }
View source

Description

Reverses the order of $list.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to reverse

List none

Returns

List

Example

sl-reverse(a b c)
// c b a

Requires

Used by

sl-mirror (alias for sl-reverse)

@function sl-mirror() { ... }
View source

Refer to sl-reverse.

sl-shuffle (aliased as sl-randomize )

@function sl-shuffle($list) { ... }
View source

Description

Shuffle $list using Fisher-Yates method.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to shuffle

List none

Returns

List

Example

sl-shuffle(a b c)
// b a c

Requires

Used by

sl-randomize (alias for sl-shuffle)

@function sl-randomize() { ... }
View source

Refer to sl-shuffle.

sl-slice

@function sl-slice($list, $start: 1, $end: length($list)) { ... }
View source

Description

Slices $list between $start and $end.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to slice

List none
$start

start index

Number 1
$end

end index

Number length($list)

Returns

List, Null

Example

sl-slice(a b c d e, 2, 4)
// b c d
sl-slice(a b c d e, 2, 2)
// b
sl-slice(a b c d e, 4, 2)
// null
sl-slice(a b c d e, -1, 6)
// null

Throws

  • List indexes $start and $end must be numbers for sl-slice.

  • Start index has to be lesser than or equals to the end index for sl-slice.

  • List indexes must be non-zero integers for sl-slice.

  • Start index has to be lesser than or equal to list length for sl-slice.

  • End index has to be lesser than or equal to list length for sl-slice.

Used by

sl-some

@function sl-some($list, $function, $args...) { ... }
View source

Description

Tests whether some items from $list pass the test implemented by $function.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to run test against

List none
$function

function to run against every item from list

String none
$args

extra arguments to pass to the function

Arglist none

Returns

Bool

Example

sl-some(1 2 3, unitless)
// true
sl-some(1 2 3px, unitless)
// true
sl-some(1px 2px 3px, unitless)
// false

sl-sum

@function sl-sum($list, $force: false) { ... }
View source

Description

Sums up all numeric values in $list, stripping unit if $force set to true.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list

List none
$force

enable/disable parseInt

Bool false

Returns

Number

Example

sl-sum(1 2 3)
// 6
sl-sum(a b 1)
null
sl-sum(1 2 3px, true)
// 6

Throws

  • All items from list are not numbers for sl-sum.

Requires

sl-tail (aliased as sl-rest )

@function sl-tail($list) { ... }
View source

Description

Returns the tail of $list: all items except the first (head).

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to retrieve tail from

List none

Returns

List, Null

Example

sl-tail(a b c)
// b c 

Requires

Used by

sl-rest (alias for sl-tail)

@function sl-rest() { ... }
View source

Refer to sl-tail.

sl-sort (aliased as sl-order )

@function sl-sort($list, $order) { ... }
View source

Description

Sorts values of $list using quick-sort algorithm using $order.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to sort

List none
$order

order to respect

List none

Returns

List

Example

sl-sort(b a c)
// a b c
sl-sort(3 5 1)
// 1 3 5 

Requires

Used by

sl-order (alias for sl-sort)

@function sl-order() { ... }
View source

Refer to sl-sort.

sl-to-list (aliased as sl-listify )

@function sl-to-list($value, $separator: space) { ... }
View source

Description

Casts $value into a list.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$value

value to cast to list

Any none
$separator

separator to use

String space

Returns

List

Example

sl-to-list(a b c, comma)
// a, b, c

Used by

sl-listify (alias for sl-to-list)

@function sl-listify() { ... }
View source

Refer to sl-to-list.

sl-to-map (aliased as sl-enumerate sl-mapify )

@function sl-to-map($list) { ... }
View source

Description

Casts $list into a map, using indexes as keys (starting with $start). Useful for iterating through a list with an index variable. e.g. @each $index, $value in to-map($list)

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to turn into map

List none

Returns

Map, Null

Example

sl-to-map(a b c)
// 1 a, 2 b, 3 c

Throws

  • List cannot be empty for sl-to-map.

Requires

Used by

Authors

  • Andrey "Lolmaus" Mikhaylov

  • Chris Eppstein

sl-enumerate (alias for sl-to-map)

@function sl-enumerate() { ... }
View source

Refer to sl-to-map.

sl-mapify (alias for sl-to-map)

@function sl-mapify() { ... }
View source

Refer to sl-to-map.

sl-to-string (aliased as sl-stringify )

@function sl-to-string($list, $glue: '') { ... }
View source

Description

Joins all elements of $list with $glue.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to cast

List none
$glue

value to use as a join string

String ''

Returns

String

Example

sl-to-string(a b c)
// abc
sl-to-string(a b c, '-')
// a-b-c

Requires

Used by

sl-stringify (alias for sl-to-string)

@function sl-stringify() { ... }
View source

Refer to sl-to-string.

sl-union (aliased as sl-merge )

@function sl-union($lists...) { ... }
View source

Description

Returns a list of values from $lists minus duplicates.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$lists

lists to unify

Arglist none

Returns

List

Example

sl-union(a b c, b e d, a c b)
// a b c e d

Requires

Used by

sl-merge (alias for sl-union)

@function sl-merge() { ... }
View source

Refer to sl-union.

sl-walk

@function sl-walk($list, $function, $args...) { ... }
View source

Description

Apply $function to every item from $list passing $args as parameters.

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list to update

List none
$function

function to call on each value

String none
$args

optional function arguments

Arglist none

Returns

List, Null

Example

sl-walk(a b c, to-upper-case)
// A B C

Throws

  • There is no $function function for sl-walk.

Requires

mixins

sl-debug

@mixin sl-debug($list) { ... }
View source

Description

Mixin displaying clean debug

Parameters

parameter Name parameter Description parameter Type parameter Default value
$list

list

List none

Requires