Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
19 lines
435 B
Plaintext
19 lines
435 B
Plaintext
/**
|
|
* https://tc39.es/ecma402/#sec-defaultnumberoption
|
|
* @param val
|
|
* @param min
|
|
* @param max
|
|
* @param fallback
|
|
*/
|
|
export function DefaultNumberOption(inputVal, min, max, fallback) {
|
|
if (inputVal === undefined) {
|
|
// @ts-expect-error
|
|
return fallback;
|
|
}
|
|
const val = Number(inputVal);
|
|
if (isNaN(val) || val < min || val > max) {
|
|
throw new RangeError(`${val} is outside of range [${min}, ${max}]`);
|
|
}
|
|
return Math.floor(val);
|
|
}
|