Skip to content

Instantly share code, notes, and snippets.

@nwwells
Last active December 17, 2015 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nwwells/5644618 to your computer and use it in GitHub Desktop.
Save nwwells/5644618 to your computer and use it in GitHub Desktop.
tuple lookup function for scss
@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