Skip to content

Instantly share code, notes, and snippets.

@dmitry-ilyashevich
Created August 4, 2014 12:46
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 dmitry-ilyashevich/866e8b7f25506aaf8fa6 to your computer and use it in GitHub Desktop.
Save dmitry-ilyashevich/866e8b7f25506aaf8fa6 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.0.rc.1)
// Compass (v1.0.0.alpha.20)
// ----
/**
* Clamp `$value` between `$min` and `$max`.
*
* @access public
*
* @author Stan Angeloff
*
* @link https://github.com/sass/sass/pull/402 Clamp function on Sass's repo
*
* @param {Number} $value - value to clamp
* @param {Number} $min (0) - minimal value
* @param {Number} $max (1) - maximum value
*
* @throws All arguments must be numbers for `clamp`.
*
* @return {Number} - clamped number
*/
@function clamp($value, $min: 0, $max: 1) {
@if type-of($value) != "number" or type-of($min) != "number" or type-of($max) != "number" {
@error "All arguments must be numbers for `clamp`.";
}
@return if($value > $max, $max, if($value < $min, $min, $value));
}
test {
clamp: clamp(42);
clamp: clamp("string");
}
All arguments must be numbers for `clamp`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment