cv-website

Personal website and CV
git clone https://git.in0rdr.ch/cv-website.git
Log | Files | Refs | Pull requests |Archive | README | LICENSE

_convert-units.scss (812B)


      1 //************************************************************************//
      2 // Helper function for str-to-num fn.
      3 // Source: http://sassmeister.com/gist/9647408
      4 //************************************************************************//
      5 @function _convert-units($number, $unit) {
      6   $strings: "px", "cm", "mm", "%", "ch", "pica", "in", "em", "rem", "pt", "pc", "ex", "vw", "vh", "vmin", "vmax", "deg", "rad", "grad", "turn";
      7   $units:   1px, 1cm, 1mm, 1%, 1ch, 1pica, 1in, 1em, 1rem, 1pt, 1pc, 1ex, 1vw, 1vh, 1vmin, 1vmax, 1deg, 1rad, 1grad, 1turn;
      8   $index: index($strings, $unit);
      9 
     10   @if not $index {
     11     @warn "Unknown unit `#{$unit}`.";
     12     @return false;
     13   }
     14 
     15   @if type-of($number) != "number" {
     16     @warn "`#{$number} is not a number`";
     17     @return false;
     18   }
     19 
     20   @return $number * nth($units, $index);
     21 }