UNPKG

@rickosborne/rebound

Version:

Rick Osborne's utilities for working with bounded numbers

39 lines (38 loc) 2.04 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var guard_bounded_exports = {}; __export(guard_bounded_exports, { guardForBounds: () => guardForBounds, validateBounded: () => validateBounded }); module.exports = __toCommonJS(guard_bounded_exports); var import_guard = require("@rickosborne/guard"); var import_typed_function = require("./typed-function.cjs"); 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 || (0, import_guard.isInt)(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 (0, import_typed_function.addTypedProperties)(guard, bounds, typeName, fn); } __name(guardForBounds, "guardForBounds"); //# sourceMappingURL=guard-bounded.cjs.map