////
/// @group helpers
////

/// Strip the unit from a number.
/// @param {Number} $num The number whose units you wish to strip.
/// @since 0.2.0
/// @link https://davidtheclark.github.io/scut/strip-unit.html
@function strip-unit ($num) {
  @return $num / ($num * 0 + 1);
}

/// Convert pixel-values to em-values.
/// @param {Number} $pixels - The px-value you wish to convert to ems. No px unit necessary (e.g. 20 is fine, so is 20px). Passing a list will result in a list of em values (see examples).
/// @param {Number} $base [$nice-base-font-size] - A base-value with which to calculate the em-value
/// @since 0.2.0
/// @link https://davidtheclark.github.io/scut/em.html
@function em ($pixels, $base: $nice-base-font-size) {
  // $base could be in em or px (no unit = px).
  // Adjust accordingly to create a $divisor that
  // serves as context for $pixels.
  $multiplier: if(unit($base) == em, 16, 1);
  $divisor: strip-unit($base) * $multiplier;

  $em-vals: ();
  @each $val in $pixels {
    $val-in-ems: (strip-unit($val) / $divisor) * 1em;
    $em-vals: append($em-vals, $val-in-ems);
  }

  @if length($em-vals) == 1 {
    // return a single value instead of a list,
    // so it can be used in calculations
    @return nth($em-vals, 1);
  } @else {
    @return $em-vals;
  }
}


/// Convert pixel-values to rem-values.
/// @param {Number} $pixels - The px-value you wish to convert to rems. No px unit necessary (e.g. 20 is fine, so is 20px). Passing a list will result in a list of rem values (see examples).
/// @param {Number} $base [$nice-base-font-size] - A base-value with which to calculate the em-value
/// @since 0.2.0
/// @link https://davidtheclark.github.io/scut/rem.html
@function rem ($pixels, $base: $nice-base-font-size) {

  $rem-vals: ();
  @each $val in $pixels {
    $val-in-rems: strip-unit($val) / $base * 1rem;
    $rem-vals: append($rem-vals, $val-in-rems);
  }

  @if length($rem-vals) == 1 {
    // return a single value instead of a list,
    // so it can be used in calculations
    @return nth($rem-vals, 1);
  } @else {
    @return $rem-vals;
  }
}
