|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
508 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | var $TypeError = require('es-errors/type');
|
|---|
| 4 | var max = require('math-intrinsics/max');
|
|---|
| 5 | var min = require('math-intrinsics/min');
|
|---|
| 6 |
|
|---|
| 7 | // https://262.ecma-international.org/12.0/#clamping
|
|---|
| 8 |
|
|---|
| 9 | module.exports = function clamp(x, lower, upper) {
|
|---|
| 10 | if (typeof x !== 'number' || typeof lower !== 'number' || typeof upper !== 'number' || !(lower <= upper)) {
|
|---|
| 11 | throw new $TypeError('Assertion failed: all three arguments must be MVs, and `lower` must be `<= upper`');
|
|---|
| 12 | }
|
|---|
| 13 | return min(max(lower, x), upper);
|
|---|
| 14 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.