@rickosborne/rebound
Version:
Rick Osborne's utilities for working with bounded numbers
20 lines (19 loc) • 1.09 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
import { isInt as isIntValue } from "@rickosborne/guard";
import { addTypedProperties } from "./typed-function.mjs";
const validateBounded = /* @__PURE__ */ __name((isLowerInc, lower, isInt, upper, isUpperInc, ifPresent, value) => {
return ifPresent && value == null || typeof value === "number" && !isNaN(value) && (isLowerInc ? value >= lower : value > lower) && (isUpperInc ? value <= upper : value < upper) && (!isInt || isIntValue(value));
}, "validateBounded");
function guardForBounds(bounds, typeName, fnName, ifPresent) {
const { isInt, isUpperInc, isLowerInc, lower, upper } = bounds;
const fn = fnName ?? `is${typeName}${ifPresent ? "IfPresent" : ""}`;
const guard = validateBounded.bind(void 0, isLowerInc, lower, isInt, upper, isUpperInc, ifPresent);
return addTypedProperties(guard, bounds, typeName, fn);
}
__name(guardForBounds, "guardForBounds");
export {
guardForBounds,
validateBounded
};
//# sourceMappingURL=guard-bounded.mjs.map