UNPKG

react-native-timer-picker

Version:

A simple, flexible, performant duration picker for React Native apps 🔥 Great for timers, alarms and duration inputs ⏰🕰️⏳ Includes iOS-style haptic and audio feedback 🍏

58 lines (55 loc) 1.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAdjustedLimit = void 0; /** * Adjusts and validates the min/max limits for a scrollable number picker. * Ensures limits are within valid bounds and handles edge cases. * * @param {Limit | undefined} limit - The input limit object containing optional min and max values * @param {number} numberOfItems - Total number of items in the picker * @param {number} interval - The interval between consecutive numbers * * @returns {{ max: number; min: number }} An object containing the adjusted min and max limits * * @example * // With valid limits * getAdjustedLimit({ min: 5, max: 15 }, 20, 1) * // Returns: { max: 15, min: 5 } * * @example * // With out-of-bounds limits * getAdjustedLimit({ min: -5, max: 25 }, 20, 1) * // Returns: { max: 19, min: 0 } * * @example * // With invalid limits (max < min) * getAdjustedLimit({ min: 15, max: 5 }, 20, 1) * // Returns: { max: 19, min: 0 } */ const getAdjustedLimit = (limit, numberOfItems, interval) => { const maxValue = (numberOfItems - 1) * interval; if (!limit || !limit.max && !limit.min) { return { max: maxValue, min: 0 }; } // guard against limits that are out of bounds const adjustedMaxLimit = limit.max ? Math.min(limit.max, maxValue) : maxValue; const adjustedMinLimit = limit.min ? Math.max(limit.min, 0) : 0; // guard against invalid limits if (adjustedMaxLimit < adjustedMinLimit) { return { max: maxValue, min: 0 }; } return { max: adjustedMaxLimit, min: adjustedMinLimit }; }; exports.getAdjustedLimit = getAdjustedLimit; //# sourceMappingURL=getAdjustedLimit.js.map