Created
December 11, 2018 11:33
-
-
Save jeremyben/802a9621f5f1d31465b4cad4ee20d4ec to your computer and use it in GitHub Desktop.
Sass Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Clamp number between min and max | |
*/ | |
@function clamp($value, $min, $max) { | |
@return if($value > $max, $max, if($value < $min, $min, $value)); | |
} | |
/** | |
* Get a list from all possible abbreviations of a string | |
* Ex : abbr(yolo) => (y, yo, yol, yolo) | |
*/ | |
@function abbr($string) { | |
$list: (); | |
@for $i from 1 through str-length($string) { | |
$a: str-slice($string, 1, $i); | |
$list: append($list, $a); | |
} | |
@return $list; | |
} | |
/** | |
* Remove units from value | |
*/ | |
@function parse-int($value) { | |
@return $value / ($value * 0 + 1); | |
} | |
/** | |
* Pixel to rem | |
*/ | |
@function rem($size-px, $base-px: 16px) { | |
$size-rem: parse-int($size-px) / parse-int($base-px); | |
@return #{$size-rem}rem; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment