]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Add `map-safe-get` function for safely retrieving a map value.
authorBrett Mason <brettsmason@gmail.com>
Tue, 17 Jan 2017 10:41:49 +0000 (10:41 +0000)
committerBrett Mason <brettsmason@gmail.com>
Tue, 17 Jan 2017 10:41:49 +0000 (10:41 +0000)
scss/util/_value.scss

index cec4408bee512ccfec55c727f491a2bb2fc1d652..633f55498018595f2f3bbe3cfbe60ac7150a5325 100644 (file)
   @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';
+  }
+}