Skip to main content
Glama
number-utils.js1.21 kB
import { isNumber } from './type-utils'; import { logger } from './logger'; /** * Clamps a value to a range. * @param value the value to clamp * @param min the minimum value * @param max the maximum value * @param label if provided then enables logging and prefixes all logs with labels * @param fallbackValue if provided then returns this value if the value is not a valid number */ export function clampToRange(value, min, max, label, fallbackValue) { if (min > max) { logger.warn('min cannot be greater than max.'); min = max; } if (!isNumber(value)) { label && logger.warn(label + ' must be a number. using max or fallback. max: ' + max + ', fallback: ' + fallbackValue); return clampToRange(fallbackValue || max, min, max, label); } else if (value > max) { label && logger.warn(label + ' cannot be greater than max: ' + max + '. Using max value instead.'); return max; } else if (value < min) { label && logger.warn(label + ' cannot be less than min: ' + min + '. Using min value instead.'); return min; } else { return value; } } //# sourceMappingURL=number-utils.js.map

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sadiuysal/mem0-mcp-server-ts'

If you have feedback or need assistance with the MCP directory API, please join our Discord server