@use "sass:list";
@use "sass:map";
@use "sass:string";
@use 'sass:math';

/// Returns the named value of a map. Throws an error if it does not exist.
///
/// @param {map} $map
///   The map to access
/// @param {string} $key
///   The key to access
/// @return {any} keyed value of `$map`
@function fetch($map, $key) {
  @if map.has-key($map, string.quote($key)) {
    @return map.get($map, string.quote($key));
  } @else {
    @error "ERROR: the key: '#{$key}' is not defined";
  }
}

/// Returns the 0-indexed value of a list. Throws an error if it does not exist.
///
/// @param {list} $list
///   The list to access
/// @param {integer (unitless)} $index
///   The 0-based index to access
/// @return {any} positional value of `$list`
@function access($list, $index) {
  @return list.nth($list, $index + 1);
}

/// Merge multiple maps
///
/// @param {maps} $maps
///   The list of maps to merge
/// @return {map} merged map
@function merge($maps...) {
  $collection: ();
  @each $map in $maps {
    $collection: map.merge($collection, $map);
  }
  @return $collection;
}

@function strip-units($value) {
  @return math.div($value, ($value * 0 + 1));
}
