Urara-Blog/node_modules/.pnpm-store/v3/files/02/db7e885a1bea7c368a07c9392803f56704ff0eeca78c166a3de8b2afa43f8439c951bb1c62982c435158a9e052f17cf87f0107b82d7577135b70848379f3b4
2022-08-14 01:14:53 +08:00

18 lines
576 B
Text

'use strict';
var GetIntrinsic = require('get-intrinsic');
var $TypeError = GetIntrinsic('%TypeError%');
var max = GetIntrinsic('%Math.max%');
var min = GetIntrinsic('%Math.min%');
var Type = require('./Type');
// https://262.ecma-international.org/12.0/#clamping
module.exports = function clamp(x, lower, upper) {
if (Type(x) !== 'Number' || Type(lower) !== 'Number' || Type(upper) !== 'Number' || !(lower <= upper)) {
throw new $TypeError('Assertion failed: all three arguments must be MVs, and `lower` must be `<= upper`');
}
return min(max(lower, x), upper);
};