main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
546 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var GetIntrinsic = require('get-intrinsic');
|
---|
4 |
|
---|
5 | var $TypeError = require('es-errors/type');
|
---|
6 | var max = GetIntrinsic('%Math.max%');
|
---|
7 | var min = GetIntrinsic('%Math.min%');
|
---|
8 |
|
---|
9 | // https://262.ecma-international.org/12.0/#clamping
|
---|
10 |
|
---|
11 | module.exports = function clamp(x, lower, upper) {
|
---|
12 | if (typeof x !== 'number' || typeof lower !== 'number' || typeof upper !== 'number' || !(lower <= upper)) {
|
---|
13 | throw new $TypeError('Assertion failed: all three arguments must be MVs, and `lower` must be `<= upper`');
|
---|
14 | }
|
---|
15 | return min(max(lower, x), upper);
|
---|
16 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.