main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
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.