Here is a powerful toolbox providing you all the functions you need to manipulate your Sass lists. See complete documentation here.
How to use it
Install with Gem
gem install SassyLists
bower install SassyLists --save-dev
- Import the partial in your Sass files
What's in there?
sl-chunk(): returns whether list contains $value
sl-comma-list(): initializes an empty comma-separated list
sl-contain(): returns whether the list contains the value
sl-count-values(): counts the number of occurrences of each value of list
sl-debug(): returns list as a string
sl-every(): returns whether all items from list pass test from given function
sl-explode(): explodes a string into a list using a string as a delimiter
sl-first(): returns first value in list
sl-flatten(): turns multidimensional list into a one-level list
sl-has-values(): checks if list is not empty
sl-has-multiple-values(): checks if list has more than one value
sl-insert-nth(): inserts value at index
sl-intersection(): returns a list of shared values across all given lists
sl-is-empty(): checks if list is empty
sl-is-single(): checks if list has a single value
sl-is-symmetrical(): checks if list is symmetrical
sl-last(): returns last value in list
sl-last-index(): returns last index of value in list
sl-loop(): shifts indexes in list
sl-prepend(): prepends value to list
sl-purge(): removes all
nullvalues from list
sl-random-value(): returns random value from list
sl-range(): returns a list of values between 1 and given value
sl-remove(): removes value in list
sl-remove-duplicates(): removes duplicate values from list
sl-remove-nth(): removes value at index
sl-replace(): replaces value in list
sl-replace-nth(): replaces value at index
sl-reverse(): reverses list
sl-shuffle(): shuffles list
sl-slice(): slices list
sl-sort(): sorts list
sl-some(): returns whether some values from list pass test from given function
sl-sum(): sums all unitless values in list
sl-tail(): returns anything but the first element in list
sl-to-list(): casts value as list
sl-to-map(): casts list as map using indexes as keys
sl-to-string(): casts list as string (JS
sl-union(): returns a list of values from given lists minus duplicates
sl-walk(): applies a function to every value of list
If you feel like an explorer, you can have a look at the code here.
- Sass ~> 3.4
If you are looking for the last version of SassyLists running on Sass 3.2, install
If you are looking for the last version of SassyLists running on Sass 3.3, install
Some functions depend on other functions. If you include functions individually, make sure to check for these dependencies in their respective docs.
- Official site
- Advanced Sass list functions
- Advanced Sass list functions again
- How I made a Sass debug function
A lot of thanks to all contributors and to at-import for their support.
first off I love your functions :) but.. I got conflicts with your function names. Especially function "debug" and "to-string" are no good names in my opinion. Also names of the other functions are really common and it is not clear that they are dealing with lists.
I tried to run your tests but I got this error message (even without any changes):
There also was a syntax error in your gruntfile (missing comma).
NPM build is broken
The current npm build command includes
/stylesheets/_SassyLists.scss. It contains all the
@importstatements and thus generates an invalid dist file.
How did you compiled the latest
nullin case of error (#34)
npm install fails on peerDependencies of Bootcamp
After a fresh clone of the repository, issuing
npm installresults in:
Apparently, Bootcamp updated their dependencies to a newer version of grunt-contrib-sass: thejameskyle/[email protected]
After manually updating SassyLists dependency on
package.json, I get the following error when running
Do you have any ideas for how to fix this?
I either couldn't find it or it is not there.. however I am missing a function like "sl-empty" or "is-empty" or something like that. It may look like this:
Sort values in $list
Returns true if every element in $list satisfies the provided testing $function
Returns true if at least one element in $list satisfies the provided testing $function
Tail should return the rest of the list
tailis an alias of
last, returning the last item in the list. It is a common idiom to split a list into a head (first item) and tail (rest of the list), especially when using recursion.
Therefore, I propose
restto return the rest of the list instead of the last item.
Example usage (based on this gist: https://gist.github.com/jlong/8760275):
The code could be as easy as:
I'd be happy to submit a pull request, if needed.
call()function in Sass 3.3 could enable us to create walker functions, similar to those in PHP.
`compact()` breaks Compass
I've been receiving a nasty error:
Took me a while to figure this out.
compact(), used in SassyLists, overrides a Compass function with the same name.
When you import SassyLists and then try to use Compass'
transition()(and a number of other helpers), you receive the aforementioned error.
compact()is an internal function, so it should be safe to rename it.
Remove purge() from replace()
Instead of purging all falsy values, why not make
$new-value: nullremove matches.
Fixed remove-duplicates alias error
Recursive removal is not supported yet in
remove-duplicatesbut the alias was sending two arguments causing an error. Thus, removed the second argument in and from the
fix: fix libsass 4 call deprecation warning #63
Fix the following deprecation warning:
call()with a function retrieved by the new function
call()with support of both function (LibSass >= 3.5) and function name string (LibSass < 3.5)
"Invalid CSS after" at `sl-str-compare` tests
I got the following error when running tests:
Error seems to come from the tests on the
sl-str-comparefunction. Something is going wrong and the test variables are exported as pure CSS.
Sass 4.0 `call()` deprecation warning
The following is reported by node-sass
Like the warning says, use the get-function function inside each
Tests do not pass
sl-walkfail. But for flatten and walk, there is no visible differences between the actual result and what is expected.
A sl-reduce() function would be great! Check this:
And a callback:
Could be used like this: