source: imaps-frontend/node_modules/es-abstract/2021/clamp.js@ d565449

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
RevLine 
[d565449]1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $TypeError = require('es-errors/type');
6var max = GetIntrinsic('%Math.max%');
7var min = GetIntrinsic('%Math.min%');
8
9// https://262.ecma-international.org/12.0/#clamping
10
11module.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.