nex3/sass — pull request #402 by StanAngeloff (2012-05-31 18:34:34+00:00)
Title: Add `clamp` as a built-in number function

> A safeguard is very often needed when working with built-in functions, e.g, `lighten`, `saturate`, etc. where an `$amount` is expected to be between '0%' and '100%'.

Although it is trivial to implement in Sass using `@-function`s:

```scss
// Return a value between min and max.
@function clamp($value, $min, $max) {
@return if($value > $max, $max, if($value < $min, $min, $value));
}
```

not every User is a Sass expert.

This commit defines a single `clamp(..)` function whose arguments are:

* `$value` - the number being clamped
* `$min` - the minimum allowed/accepted value
* `$max` - the maximum allowed/accepted value

It works very much like `min` or `max` and behaves the same way when arguments are not numbers or cannot be compared (tests provided).

Example:

```scss
html {
background: saturate($theme, clamp($exposure, 0%, 100%));
}
```