SU-SWS/decanter

View on GitHub
core/src/scss/utilities/functions/string/_convert-angle.scss

Summary

Maintainability
Test Coverage

///
/// Convert an angle to the proper unit requested
///
/// @name convert-angle
///
/// @author Chris Eppstein
///
/// @param {Integer} $value - Value to convert
/// @param {String} $unit - Unit to convert to
///
/// @group mixin
@function convert-angle($value, $unit) {
  $convertable-units: deg grad turn rad;
  $conversion-factors: 1 (10grad / 9deg) (1turn / 360deg) (3.1415926rad / 180deg);
  @if index($convertable-units, unit($value)) and index($convertable-units, $unit) {
    @return $value
    / nth($conversion-factors, index($convertable-units, unit($value)))
    * nth($conversion-factors, index($convertable-units, $unit));
  }

  @warn "Cannot convert `#{unit($value)}` to `#{$unit}`.";
}