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 withbower install SassyLists --save-dev
- Import the partial in your Sass files
What's in there?
sl-chunk()
: returns whether list contains $valuesl-comma-list()
: initializes an empty comma-separated listsl-contain()
: returns whether the list contains the valuesl-count-values()
: counts the number of occurrences of each value of listsl-debug()
: returns list as a stringsl-every()
: returns whether all items from list pass test from given functionsl-explode()
: explodes a string into a list using a string as a delimitersl-first()
: returns first value in listsl-flatten()
: turns multidimensional list into a one-level listsl-has-values()
: checks if list is not emptysl-has-multiple-values()
: checks if list has more than one valuesl-insert-nth()
: inserts value at indexsl-intersection()
: returns a list of shared values across all given listssl-is-empty()
: checks if list is emptysl-is-single()
: checks if list has a single valuesl-is-symmetrical()
: checks if list is symmetricalsl-last()
: returns last value in listsl-last-index()
: returns last index of value in listsl-loop()
: shifts indexes in listsl-prepend()
: prepends value to listsl-purge()
: removes allfalse
andnull
values from listsl-random-value()
: returns random value from listsl-range()
: returns a list of values between 1 and given valuesl-remove()
: removes value in listsl-remove-duplicates()
: removes duplicate values from listsl-remove-nth()
: removes value at indexsl-replace()
: replaces value in listsl-replace-nth()
: replaces value at indexsl-reverse()
: reverses listsl-shuffle()
: shuffles listsl-slice()
: slices listsl-sort()
: sorts listsl-some()
: returns whether some values from list pass test from given functionsl-sum()
: sums all unitless values in listsl-tail()
: returns anything but the first element in listsl-to-list()
: casts value as listsl-to-map()
: casts list as map using indexes as keyssl-to-string()
: casts list as string (JS.join()
)sl-union()
: returns a list of values from given lists minus duplicatessl-walk()
: applies a function to every value of list
If you feel like an explorer, you can have a look at the code here.
Requirements
- Sass ~> 3.4
If you are looking for the last version of SassyLists running on Sass 3.2, install 0.4.9
.
If you are looking for the last version of SassyLists running on Sass 3.3, install 2.2.5
.
Some functions depend on other functions. If you include functions individually, make sure to check for these dependencies in their respective docs.
Also read
- Official site
- Advanced Sass list functions
- Advanced Sass list functions again
- How I made a Sass debug function
Credits
A lot of thanks to all contributors and to at-import for their support.
Renamed functions
Hi Hugo,
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).
Greetings
NPM build is broken
The current npm build command includes
/stylesheets/_SassyLists.scss
. It contains all the@import
statements and thus generates an invalid dist file.How did you compiled the latest
dist/_SassyLists.scss
for thev3.0.0
?Roadmap 2.0
false
returns tonull
in case of error (#34)every()
andsome()
functions (#2)npm install fails on peerDependencies of Bootcamp
After a fresh clone of the repository, issuing
npm install
results in:Apparently, Bootcamp updated their dependencies to a newer version of grunt-contrib-sass: thejameskyle/bootcamp@21be30e9c657c6a090689cb8d5a53aedccde44e7.
After manually updating SassyLists dependency on
grunt-contrib-sass
to~0.7.2
inpackage.json
, I get the following error when runninggrunt test
:Do you have any ideas for how to fix this?
empty list
Hello,
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:
New functions
Sort values in $list
sort($list)
Returns true if every element in $list satisfies the provided testing $function
every($list, $function)
Returns true if at least one element in $list satisfies the provided testing $function
some($list, $function)
Tail should return the rest of the list
Currently,
tail
is an alias oflast
, 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
tail
orrest
to 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.
"Walk" function
The new
call()
function in Sass 3.3 could enable us to create walker functions, similar to those in PHP.http://www.php.net/manual/en/function.array-walk.php http://sass-lang.com/documentation/Sass/Script/Functions.html#call-instance_method
`compact()` breaks Compass
I've been receiving a nasty error:
Took me a while to figure this out.
Function
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.SassyLists'
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: null
remove matches.https://github.com/Team-Sass/SassyLists/blob/master/stylesheets/SassyLists/_replace.scss#L32
See: https://github.com/tctcl/ballistic/pull/47/files
Fixed remove-duplicates alias error
Recursive removal is not supported yet in
remove-duplicates
but the alias was sending two arguments causing an error. Thus, removed the second argument in and from theremove-duplicates()
aliasunique()
.fix: fix libsass 4 call deprecation warning #63
Fix the following deprecation warning:
Call
call()
with a function retrieved by the new functionget-function
.Changes:
sl-safe-call-function
polyfill forcall()
with support of both function (LibSass >= 3.5) and function name string (LibSass < 3.5)sl-safe-call-function
instead ofcall()
Closes https://github.com/at-import/SassyLists/issues/63
"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-compare
function. Something is going wrong and the test variables are exported as pure CSS.node
:v8.9.1
node-sass
:v4.9.0
libsass
:v3.5.4
Sass 4.0 `call()` deprecation warning
The following is reported by node-sass
v4.8.3
Possible Solution
Like the warning says, use the get-function function inside each
call()
Tests do not pass
Tests for
sl-flatten
,sl-loop
andsl-walk
fail. But for flatten and walk, there is no visible differences between the actual result and what is expected.See: https://gist.github.com/ncoden/0d39c464193b82090897d335e8329693
Support reduction
Hello!
A sl-reduce() function would be great! Check this:
And a callback:
Could be used like this: