From: Brett Mason Date: Tue, 17 Jan 2017 10:41:49 +0000 (+0000) Subject: Add `map-safe-get` function for safely retrieving a map value. X-Git-Tag: 6.3.1~31^2^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18e102273ca28654e46eb2aab73cd83c3996dc2c;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Add `map-safe-get` function for safely retrieving a map value. --- diff --git a/scss/util/_value.scss b/scss/util/_value.scss index cec4408be..633f55498 100644 --- a/scss/util/_value.scss +++ b/scss/util/_value.scss @@ -138,3 +138,23 @@ @return if(type-of($map) != 'list', ($value,), $map); } + +/// Safely return a value from a map. +/// +/// @param {String} $name - Name of the map key. +/// @param {Map} $map - Map to retrieve a value from. +/// +/// @returns {List} Found value. +@function map-safe-get($name, $map) { + @if (type-of($map) == 'map') { + @if (map-has-key($map, $name)) { + @return map-get($map, $name); + } + @else { + @error 'Key: `#{$name}` is not available in `#{$map}`'; + } + } + @else { + @error '`#{$map}` is not a valid map'; + } +}