Created
April 30, 2013 11:09
-
-
Save BPScott/5488065 to your computer and use it in GitHub Desktop.
Sass list utilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Search a list ($haystack) for a list of values ($needles). Returns | |
* true if any of the $needles are found in the $haystack, or false if not found. | |
* | |
* Example: | |
* list-key-exists((value1 value2 value3), 'value1') => true | |
* list-key-exists((value1 value2 value3), (thing, value1)) => true | |
* list-key-exists((value1 value2 value3), 'nothere') => false | |
*/ | |
@function list-key-exists($haystack, $needles) { | |
@each $needles-item in $needles { | |
@each $haystack-item in $haystack { | |
@if $needles-item == $haystack-item { | |
@return true; | |
} | |
} | |
} | |
@return false; | |
} | |
/** | |
* Search a list of lists ($haystack) for value ($needle) at a given position | |
* ($offset). Returns that item in the list, or false if not found. | |
* | |
* Example: | |
* list-key-search(((key1 value1), (key2 value2)), 'key1', 1) => (key1 value1) | |
*/ | |
@function list-key-search($haystack, $needle, $offset: 1) { | |
@each $haystack-item in $haystack { | |
@if $needle == nth($haystack-item, $offset) { | |
@return $haystack-item; | |
} | |
} | |
@return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment