////
/// Microscope(-sass) util library.
/// @group util
////

/// @name Import util library.
/// @example @import '~microscope-sass/lib/util';


/// Adds outline to all elements (* selector on root).
///
/// @param {color} $color [#000] - Color of the outline.
/// @param {number} $size [1px] - Size of the outline.
/// @param {string} $style ['solid'] - Style of the outline.
/// @see {mixin} outline.
@mixin inspect($color: #000, $size: 1px, $style: 'solid') {
  @at-root {
    * {
      outline: $size $style $color;
    }
  }
}


/// Applies `$value` to all `$properties`.
///
/// @param {list | string} $properties - One or more properties to set.
/// @param {*} $value - Value to set.
/// @param {boolean} $force [false] - Whether to use !important.
@mixin properties($properties, $value, $force: false) {
  $important: if($force, !important, null);

  @if type-of($properties) != list {
    $properties: ($properties);
  }

  @each $property in $properties {
    #{$property}: $value#{$important};
  }
}


/// Replace `$search` with `$replace` in `$string`.
/// @author Kitty Giraudel.
/// @param {string} $string - Initial string.
/// @param {string} $search - Substring to replace.
/// @param {string} $replace ('') - New value.
/// @return {string} - Updated string.
@function str-replace($string, $search, $replace: '') {
  $index: str-index($string, $search);

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

  @return $string;
}


/// Remove the unit of a length.
/// @author Kitty Giraudel.
/// @param {numer} $number - Number to remove unit from.
/// @return {number} - Unitless number.
@function strip-unit($number) {
  @if type-of($number) == 'number' and not unitless($number) {
    @return $number / ($number * 0 + 1);
  }

  @return $number;
}
