Skip to content

Instantly share code, notes, and snippets.

@jeremyben
Created December 11, 2018 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyben/802a9621f5f1d31465b4cad4ee20d4ec to your computer and use it in GitHub Desktop.
Save jeremyben/802a9621f5f1d31465b4cad4ee20d4ec to your computer and use it in GitHub Desktop.
Sass Functions
/**
* 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