11 lines
451 B
JavaScript
11 lines
451 B
JavaScript
// gandalf-gate — a tiny guard utility. "You shall not pass" invalid input.
|
|
function youShallNotPass(condition, message = 'You shall not pass!') {
|
|
if (!condition) throw new Error(message);
|
|
}
|
|
// A simple gatekeeper: allow at most `max` calls, then refuse.
|
|
function gatekeeper(max) {
|
|
let count = 0;
|
|
return () => { if (count++ >= max) throw new Error('You shall not pass! (limit reached)'); };
|
|
}
|
|
module.exports = { youShallNotPass, gatekeeper };
|