UNPKG

svcorelib

Version:

Core library used in the projects of Sv443 and the Sv443 Network. Contains tons of miscellaneous QoL features.

18 lines (13 loc) 534 B
const allOfType = require("./allOfType"); function clamp(...params) { const [num, min, max] = params; if(!allOfType(params, "number")) throw new TypeError("Parameters for clamp() need to be of type number"); if(params.map(p => isNaN(p)).includes(true)) throw new TypeError("Parameters for clamp() can't be NaN"); if(min > max) throw new TypeError("Parameter min can't be higher than max in clamp()"); return Math.max(min, Math.min(num, max)); } module.exports = clamp;