MCPcopy Index your code
hub / github.com/callstack/agent-device / optionalInteger

Function optionalInteger

src/commands/command-input.ts:392–410  ·  view source on GitHub ↗
(
  record: Record<string, unknown>,
  key: string,
  options: { min?: number; max?: number } = {},
)

Source from the content-addressed store, hash-verified

390}
391
392export function optionalInteger(
393 record: Record<string, unknown>,
394 key: string,
395 options: { min?: number; max?: number } = {},
396): number | undefined {
397 const value = record[key];
398 if (value === undefined) return undefined;
399 if (!Number.isInteger(value)) {
400 throw new Error(`Expected ${key} to be an integer.`);
401 }
402 const numberValue = value as number;
403 if (options.min !== undefined && numberValue < options.min) {
404 throw new Error(`Expected ${key} to be at least ${options.min}.`);
405 }
406 if (options.max !== undefined && numberValue > options.max) {
407 throw new Error(`Expected ${key} to be at most ${options.max}.`);
408 }
409 return numberValue;
410}
411
412function optionalBoolean(record: Record<string, unknown>, key: string): boolean | undefined {
413 const value = record[key];

Callers 2

readGestureInputFunction · 0.90
integerFieldFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected