MCPcopy Create free account
hub / github.com/chhoumann/quickadd / normalizeNumericValue

Function normalizeNumericValue

src/utils/valueSyntax.ts:540–570  ·  view source on GitHub ↗
(
	value: string | undefined,
	config?: NumericInputConfig,
)

Source from the content-addressed store, hash-verified

538}
539
540export function normalizeNumericValue(
541 value: string | undefined,
542 config?: NumericInputConfig,
543): string {
544 const trimmed = value?.trim() ?? "";
545 if (!trimmed) return "";
546
547 const parsed = Number(trimmed);
548 if (!Number.isFinite(parsed)) return "";
549
550 const min = config?.min;
551 const max = config?.max;
552 let normalized = parsed;
553 if (min !== undefined) normalized = Math.max(min, normalized);
554 if (max !== undefined) normalized = Math.min(max, normalized);
555
556 if (config?.step !== undefined && config.step > 0) {
557 const base = min ?? 0;
558 const stepsFromBase = Math.round((normalized - base) / config.step);
559 normalized = base + stepsFromBase * config.step;
560 if (min !== undefined) normalized = Math.max(min, normalized);
561 if (max !== undefined) normalized = Math.min(max, normalized);
562 const precision = Math.max(
563 decimalPlaces(base),
564 decimalPlaces(config.step),
565 );
566 return formatRoundedNumber(normalized, precision);
567 }
568
569 return String(normalized);
570}
571
572export function normalizeSliderValue(
573 value: string | undefined,

Callers 6

syncFromNumberMethod · 0.90
renderFieldMethod · 0.90
normalizeSliderValueFunction · 0.85

Calls 2

decimalPlacesFunction · 0.85
formatRoundedNumberFunction · 0.85

Tested by

no test coverage detected