_convert-units.scss 696 B

123456789101112131415
  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. @if not $index {
  10. @warn "Unknown unit `#{$unit}`.";
  11. @return false;
  12. }
  13. @return $number * nth($units, $index);
  14. }