@import 'defaults';

//
// Strips units from given $number i.e. 10px -> 10
//
@function strip-units($number) {
  @return $number / ($number * 0 + 1);
}


//
// If $value found in $string, return $string with $value replaced with
// $replacement.
//
@function str-replace($string, $value, $replacement: '') {
  $index: str-index($string, $value);

  @if $index {
    @return str-slice($string, 1, $index - 1)
      + $replacement + str-replace(
        str-slice(
          $string,
          $index + str-length($value)
        ),
        $value,
        $replacement
      );
  }

  @return $string;
}


//
// Strips units and replaces '.' with '_' for class name safety.
//
@function format-unit($unit) {
  @if type-of($unit) == number {
    @return str-replace(
      str-replace('#{strip-units($unit)}', '0.', $decimal_deliminator),
      '.',
      $decimal_deliminator
    );
  } @else {
    @return $unit;
  }
}
