Sha256: 5228d2606a811ae48761dca4967f1746a81418b72cc81ff2a923d2854e491520

Contents?: true

Size: 886 Bytes

Versions: 6

Compression:

Stored size: 886 Bytes

Contents

// Fetch value from key in map
// -------------------------------------------------------------------------------
// @param $map [map] : map to fetch from
// @param $keys [string | list] : string of key, or list of strings
// -------------------------------------------------------------------------------
// @return fetched literal | false

@function map-fetch($map, $keys) {
	$key: nth($keys, 1);
	$length: length($keys);
	$value: map-get($map, $key);

	// check if the key was incorrect, meaning the map doesn't exist
	@if $value == null {
		@warn "Invalid arguments passed to function: map-fetch(#{$map}, #{$keys}). One or more of the keys do not exist.";
		@return false;
	}

	@else {
		@if $length > 1 {
			$rest: ();

			@for $i from 2 through $length {
				$rest: append($rest, nth($keys, $i))
			}

			@return map-fetch($value, $rest);

		} @else {
			@return $value;
		}
	}
}

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
flint-gs-1.6.5 stylesheets/flint/functions/lib/_map-fetch.scss
flint-gs-1.6.4 stylesheets/flint/functions/lib/_map-fetch.scss
flint-gs-1.6.3 stylesheets/flint/functions/lib/_map-fetch.scss
flint-gs-1.6.2 stylesheets/flint/functions/lib/_map-fetch.scss
flint-gs-1.6.0 stylesheets/flint/functions/lib/_map-fetch.scss
flint-gs-1.5.0 stylesheets/flint/functions/lib/_map-fetch.scss