Last active
December 17, 2015 17:18
-
-
Save nwwells/5644618 to your computer and use it in GitHub Desktop.
tuple lookup function for scss
This file contains hidden or 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
@function lookup ($targetKey, $map, $index:2, $default:'') { | |
@each $entry in $map { | |
@if length($entry) >= $index { | |
$key: nth($entry, 1); | |
$value: nth($entry, $index); | |
@if $key == $targetKey { | |
@return $value; | |
} | |
} | |
} | |
@return $default; | |
} | |
$example-tuple: | |
key1 white, | |
key2 black #202020 | |
; | |
.usage { | |
color: lookup(key1, $example-tuple); | |
background-color: lookup(key2, $example-tuple, 3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment